Created
April 17, 2012 20:54
-
-
Save z720/2408991 to your computer and use it in GitHub Desktop.
Ldap authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set up the environment for creating the initial context | |
Hashtable env = new Hashtable(); | |
env.put(Context.INITIAL_CONTEXT_FACTORY, | |
"com.sun.jndi.ldap.LdapCtxFactory"); | |
env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=JNDITutorial"); | |
// Authenticate as S. User and password "mysecret" | |
env.put(Context.SECURITY_AUTHENTICATION, "simple"); | |
env.put(Context.SECURITY_PRINCIPAL, "cn=S. User, ou=NewHires, o=JNDITutorial"); | |
env.put(Context.SECURITY_CREDENTIALS, "mysecret"); | |
// Create the initial context | |
DirContext ctx = new InitialDirContext(env); | |
// ... do something useful with ctx | |
javax.naming.AuthenticationException: [LDAP: Invalid Credentials] | |
at java.lang.Throwable.<init>(Compiled Code) | |
at java.lang.Exception.<init>(Compiled Code) | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment