I've been trying to connect to LDAP for quite a while, but with no success.
The error I'm getting is
ERROR o.s.s.w.a.UsernamePasswordAuthenticationFilter - An internal error occurred while trying to authenticate the user.
org.springframework.security.authentication.InternalAuthenticationServiceException: Uncategorized exception occured during LDAP processing;
nested exception is javax.naming.NamingException: [LDAP: error code 1 - 000004DC: LdapErr: DSID-0C0906E8, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v1db1 ];
remaining name 'dc=2008r2ad,dc=test'
I'm also using the same AD with other program and there is no problem there.
The result I get there is:
I'm trying to use the AD for authentication into my app. The details of the users are then downloaded from DB. I got everything working with an LDIF file. But not with a real AD.
You can see the working ldif configuration commented out:
@Configuration
@ComponentScan
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
BaseLdapPathContextSource contextSource;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.userSearchFilter("uid={0}, ou=anyoffice")
.ldapAuthoritiesPopulator(new UserDetailsServiceLdapAuthoritiesPopulator(personDetailsService()))
.userSearchBase("dc=2008r2ad,dc=test")
.contextSource(contextSource);
// .userDnPatterns("uid={0},ou=people")
// .groupSearchBase("ou=groups")
// .contextSource().ldif("classpath:test-server.ldif");
}
....
Then there is the contexSource bean definition. In the LdapTemplate bean you can see an attempt to do the bind operation, but I get a different error there and I'm not sure if that is the way to go.
@Configuration
@EnableLdapRepositories
public class LdapConfig {
@Bean
BaseLdapPathContextSource contextSource() throws Exception {
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl("ldap://10.0.10.170:389");
contextSource.setBase("dc=2008r2ad,dc=test");
contextSource.setUserDn("administrator@2008r2ad.test");
contextSource.setPassword("password");
contextSource.setAnonymousReadOnly(true);
contextSource.afterPropertiesSet();
return contextSource;
}
@Bean
LdapTemplate ldapTemplate() throws Exception {
log.debug("LdapTemplate initialized");
LdapTemplate template = new LdapTemplate(contextSource());
// template.afterPropertiesSet();
// Attributes attrs = new BasicAttributes();
// attrs.put("uid", "testUID");
// attrs.put("cn", "testCN");
// template.bind("ou=anyoffice", null, attrs);
return template;
}
@Bean
public String userSearchBase() {
return "ou=anyoffice";
}
}
Any help would be appreciated. I'm here to provide you with any info needed. I guess the problem is with the configuration.
Aucun commentaire:
Enregistrer un commentaire