@Configuration @EnableWebSecurity(debug = true) 公共类 WebSecurityConfig 扩展 WebSecurityConfigurerAdapter {
//Getting values from properties file
@Value("${ldap.urls}")
private String ldapUrls;
@Value("${ldap.base.dn}")
private String ldapBaseDn;
@Value("${ldap.username}")
private String ldapSecurityPrincipal;
@Value("${ldap.password}")
private String ldapPrincipalPassword;
@Value("${ldap.user.dn.pattern}")
private String ldapUserDnPattern;
@Value("${ldap.enabled}")
private String ldapEnabled;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().disable().authorizeRequests().anyRequest().authenticated().and().csrf().disable()
.formLogin();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.ldapAuthentication()
.contextSource()
.url(ldapUrls + ldapBaseDn)
.managerDn(ldapSecurityPrincipal)
.managerPassword(ldapPrincipalPassword)
.and()
.userSearchBase("ou=People")
.userSearchFilter("sAMAccountName={0}").
//userDnPatterns("member={0}").
groupSearchBase("ou=Groups");
//.userDnPatterns(ldapUserDnPattern);
}
}
使用上面的代码得到错误 [LDAP:错误代码 49 - 80090308:LdapErr:DSID-0C090453,注释:AcceptSecurityContext 错误,数据 52e,v3839];嵌套异常是 javax.naming.AuthenticationException:[LDAP:错误代码 49 - 80090308:LdapErr:DSID-0C090453,注释:AcceptSecurityContext 错误,数据 52e,v3839]