-
-
Save jpukg/b738bd13a80f6e8c271d7b624544601a to your computer and use it in GitHub Desktop.
A simple example of using Spring LDAP to authenticate a user against Active Directory.
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://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