Skip to content

Instantly share code, notes, and snippets.

@WeaponMan
Created November 19, 2017 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WeaponMan/faa417fea329a33f144d8362c9489bc4 to your computer and use it in GitHub Desktop.
Save WeaponMan/faa417fea329a33f144d8362c9489bc4 to your computer and use it in GitHub Desktop.
Pure Java ldap
Hashtable env = new Hashtable(11);
authEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
authEnv.put(Context.PROVIDER_URL, "ldap://ldap.example.com:389";);
authEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
authEnv.put(Context.SECURITY_PRINCIPAL, userName);
authEnv.put(Context.SECURITY_CREDENTIALS, passWord);
try {
DirContext authContext = new InitialDirContext(authEnv);
} catch (AuthenticationException authEx) {
System.out.println("Authentication failed!");
} catch (NamingException namEx) {
System.out.println("Something went wrong!");
namEx.PrintStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment