繁体   English   中英

使用 Spring Security 进行 LDAP 身份验证

[英]LDAP authentication with Spring Security

使用凭据登录 ldap 服务器时出现错误。

我的 securityconfig 类

@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 安全性进行 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 中的命名完全相同? 您的问题将通过提供确切的属性名称来解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM