Reputation: 833
I'm trying to integrate spring authentication with embedded ldap.
I have user info in local ldif file.
User1
dn: uid=joe,ou=otherpeople,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Joe Smeth
sn: Smeth
uid: joe
userPassword: joespassword
User 2
dn: uid=bob,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Bob Hamilton
sn: Hamilton
uid: bob
userPassword: bobspassword
Spring WebsecurityConfigFile
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().fullyAuthenticated()
.and()
.formLogin();
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userDnPatterns("uid={0},ou=people")
.contextSource()
.url("ldap://localhost:8389/dc=springframework,dc=org")
.and()
.passwordCompare()
.passwordAttribute("userPassword");
}
}
userDnPattern in config file I have taken ou=people (uid={0},ou=people) so I'm able to authenticate bob. When it comes to joe his directory path is different. So I'm not able to login using joe's username and password.
What should be my SpringConfiguration for authenticating all the users irrespective of the directory structure?
Upvotes: 0
Views: 525
Reputation: 833
Authentication for any user in the DIT (Directory information tree) using userSearchFilter.
Spring configuration is,
auth.ldapAuthentication()
.userSearchFilter("(uid={0})")
.contextSource()
.url("ldap://localhost:8389/dc=springframework,dc=org")
.and()
.passwordCompare()
.passwordAttribute("userPassword");
Thanks @EricLavault
Upvotes: 1