Skip to content

Instantly share code, notes, and snippets.

@lihonosov
Forked from mpilone/SpringAdLdapTest.java
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save lihonosov/da9f0b700beee9f8aa80 to your computer and use it in GitHub Desktop.

Select an option

Save lihonosov/da9f0b700beee9f8aa80 to your computer and use it in GitHub Desktop.
// Setup the LDAP client (normally done via Spring context file).
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://adserver.mycompany.com:3268");
contextSource.setBase("DC=AD,DC=MYCOMPANY,DC=COM");
contextSource.setUserDn("[email protected]");
contextSource.setPassword("password1");
contextSource.afterPropertiesSet();
LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
ldapTemplate.afterPropertiesSet();
// Perform the authentication.
Filter filter = new EqualsFilter("sAMAccountName", "mpilone");
boolean authed = ldapTemplate.authenticate("OU=CorpUsers",
filter.encode(),
"user-entered-password");
// Display the results.
System.out.println("Authenticated: " + authed);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment