Skip to content

Instantly share code, notes, and snippets.

@gitssk
Created September 24, 2012 09:17
Show Gist options
  • Save gitssk/3775086 to your computer and use it in GitHub Desktop.
Save gitssk/3775086 to your computer and use it in GitHub Desktop.
MSAD Authentication using Spring LDAP - email as userid
LdapContextSource cs = new LdapContextSource();
cs.setUrl("ldap://127.0.0.1:389");
cs.setBase("OU=XX,DC=YY,DC=com");
cs.setUserDn("CN=appCN,OU=XX,DC=YY,DC=com");
cs.setPassword("appPassword");
cs.afterPropertiesSet();
LdapTemplate lt = new LdapTemplate(cs);
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("mail", "userEmail@somedomain"));
System.out.println(lt.authenticate(DistinguishedName.EMPTY_PATH, filter.toString(), userPassword)); //true means valid login
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment