Created
April 5, 2016 16:48
-
-
Save akkidas/d1d10b65e97b77a8ec1340c39c5418c9 to your computer and use it in GitHub Desktop.
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
// Setup the LDAP client (normally done via Spring context file). | |
LdapContextSource contextSource = new LdapContextSource(); | |
contextSource.setUrl("ldap://localhost:389"); | |
contextSource.setBase("DC=COMPANY,DC=COM"); | |
contextSource.setUserDn("[email protected]"); | |
contextSource.setPassword("password"); | |
contextSource.afterPropertiesSet(); | |
LdapTemplate ldapTemplate = new LdapTemplate(contextSource); | |
ldapTemplate.afterPropertiesSet(); | |
// Perform the authentication. | |
Filter filter = new EqualsFilter("sAccountName", "testuser"); | |
boolean authed = ldapTemplate.authenticate("ou=people,ou=myrealm", | |
filter.encode(), | |
"user-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