【发布时间】:2018-08-09 17:22:05
【问题描述】:
使用凭据登录 ldap 服务器时出现错误。
我的安全配置类
@Configuration
@EnableWebSecurity
public class SecurityConfig 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()
.userSearchFilter("(employeeID={0})")
.userSearchBase("DC=xxx,DC=xxx")
.contextSource()
.url("ldap://localhost:389")
.managerDn("sxxx")
.managerPassword("xxx")
.and()
.passwordCompare()
.passwordEncoder(new LdapShaPasswordEncoder())
.passwordAttribute("userPassword");
}
@Bean
public DefaultSpringSecurityContextSource contextSource() {
return new DefaultSpringSecurityContextSource(Arrays.asList("ldap://localhost:389"), "DC=xxx,DC=xxx");
}
我正在使用 Spring Security 进行 ldap 身份验证。我收到以下错误:
原因:
[LDAP: error code 16 - 00002080: AtrErr: DSID-03080155, #1: 0:
00002080: DSID-03080155, problem 1001 (NO_ATTRIBUTE_OR_VAL), data 0,
Att 23 (userPassword) ]; nested exception is
javax.naming.directory.NoSuchAttributeException: [LDAP: error code 16
- 00002080: AtrErr: DSID-03080155, #1: 0: 00002080: DSID-03080155, problem 1001 (NO_ATTRIBUTE_OR_VAL), data 0, Att 23 (userPassword) ];
【问题讨论】:
-
从异常看来你的ldap数据库没有
userPassword这个属性。您是否验证了您在配置中放入的属性的名称与您的 ldap 中的名称完全相同? -
@theLearner 谢谢。我能够通过将其绑定到“sAMAccountName”来进行身份验证
-
我已经发布了上述建议作为我的答案。如果它解决了您的问题,您可以接受答案。
标签: java spring-security ldap