Using External LDAP Naming service in JBoss-5.1.0.GA

Often you’re using ldap for authentication. But what if you’d like to store more information to your ldap and access it from your enterprise application? You can add an external context to your JNDI tree.

Insert the following xml snippet into your ${jboss_home}/server/${server_config}/conf/jboss-service.xml:

<!-- Bind a remote LDAP server -->
<mbean code="org.jboss.naming.ExternalContext"
    <attribute name="JndiName">external/ldap/myldap</attribute>
    <attribute name="Properties">
    <attribute name="InitialContext"> javax.naming.ldap.InitialLdapContext </attribute>
    <attribute name="RemoteAccess">true</attribute>

You can access the naming service within your enterprise application like this:

public static LdapContext newMyLdapContext() throws NamingException {
	try {
		InitialContext iniCtx = new InitialContext();
		return (LdapContext) iniCtx.lookup("external/ldap/myldap");
	} catch (NoInitialContextException e) {
		// TODO handle the exception

Leave a Reply

Your email address will not be published. Required fields are marked *