【问题标题】:LDAP authentication with Spring Security使用 Spring Security 进行 LDAP 身份验证
【发布时间】: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


【解决方案1】:

从异常看来,您的 ldap 数据库似乎没有名为 userPassword 的属性。您是否验证了您在配置中放置的属性的名称与您的 ldap 中的名称完全相同? 您的问题将通过提供确切的属性名称来解决。

【讨论】:

    猜你喜欢
    • 2012-11-18
    • 2013-03-06
    • 2011-02-01
    • 2015-11-22
    • 2011-04-16
    • 2016-09-09
    • 2012-02-18
    • 2016-09-01
    • 2020-02-16
    相关资源
    最近更新 更多