LDAP Programming with JNDI
by, 07-07-2012 at 05:24 PM (701 Views)
Objects present in LDAP server could be manipulated by connecting with server. Also, you may require the authentication with server. For making connections with server get a reference of DirContext interface to an object. This is done with class InitialDirContext that would be taking hashtable.
Given code could be used for authentication and connection of user with LDAP server. It shall be noted that simpler authentications are used over here. Simpler kind of authentications include full qualified DN as well as clear text password of user to be receive by the LDAP server.In order to make clear text password avoidable of getting exposed, this mechanism shall be used along with some encrypted channel if support is provided by LDAP servers.
Java Code:Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "LdapCtxFactory"); // specify where the ldap server is running env.put(Context.PROVIDER_URL, "ldap://test.org:61596"); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager"); env.put(Context.SECURITY_CREDENTIALS, "password"); // Create the initial directory context DirContext ctx = new InitialDirContext(env);