具有Spring安全性的LDAP身份验证

问题描述 投票:0回答:1

我在使用凭据登录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 security进行ldap身份验证。我收到以下错误:

原因:

[LDAP:错误代码16 - 00002080:AtrErr:DSID-03080155,#1:0:00002080:DSID-03080155,问题1001(NO_ATTRIBUTE_OR_VAL),数据0,Att 23(userPassword)];嵌套异常是javax.naming.directory.NoSuchAttributeException:[LDAP:错误代码16 - 00002080:AtrErr:DSID-03080155,#1:0:00002080:DSID-03080155,问题1001(NO_ATTRIBUTE_OR_VAL),数据0,Att 23(userPassword) )];

java spring-security ldap
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.