Authenticating to the Directory This example uses the JNDI/LDAP service provider to create an authenticated session to an LDAP server on the local machine, by using "simple" authentication. String url = "ldap://localhost/o=JNDITutorial"; Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, url); env.put(Context.SECURITY_AUTHENTICATION, "simple"); env.put(Context.SECURITY_PRINCIPAL, "userDN"); env.put(Context.SECURITY_CREDENTIALS, "secret"); try { DirContext ctx = new InitialDirContext(env); } catch (NamingException e) { }