Spring Boot LDAP身份验证失败,LDAP错误代码49-80090308数据52e。

3

我正在尝试在我的 Web 应用程序中使用 Spring Security 进行 LDAP 用户身份验证,但是遇到了 error 52e,以下是我的 Spring Security LDAP 身份验证代码:

protected void configure(AuthenticationManagerBuilder auth) throws Exception {
  auth.ldapAuthentication()
   .contextSource().url("ldap://192.168.1.5:389/DC=zonetest,DC=lk")
   .managerDn("CN=administrator@zonetest.lk,DC=zonetest,DC=lk").managerPassword("P@ssw0rd")
   .and()
   .userSearchBase("OU=SL Users")
   .userSearchFilter("(CN={0})");
}

我的LDAP结构如下截图所示: 我在Postman客户端中遇到了以下错误:
{
    "timestamp": 1505368170503,
    "status": 401,
    "error": "Unauthorized",
    "message": "[LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903C5, comment: AcceptSecurityContext error, data 52e, v2580\u0000]; nested exception is javax.naming.AuthenticationException: [LDAP: error code 49 - 80090308: LdapErr: DSID-0C0903C5, comment: AcceptSecurityContext error, data 52e, v2580\u0000]",
    "path": "/"
}

请帮助我。


你确定你的名字中可以使用空格吗?“SL Users”。 - Aruna Karunarathna
我尝试过将ou名称中的空格删除,并将ou设置为“SLUsers”,但仍然出现相同的LDAP 52e错误。 - Sai Nikhil
52e 表示凭证无效,因此用户是可用的,你确定你使用了正确的凭证吗?你是否对密码进行了哈希/加密处理? - Aruna Karunarathna
不,我没有加密密码。 - Sai Nikhil
1个回答

1

还有一种简单的方法进行LDAP身份验证。我使用下面的代码来进行LDAP身份验证。这对我非常有效:

            package app.config;    
            import org.springframework.beans.factory.annotation.Value;
            import org.springframework.context.annotation.Bean;
            import org.springframework.context.annotation.Configuration;
            import org.springframework.security.authentication.AuthenticationManager;
            import org.springframework.security.authentication.AuthenticationProvider;
            import org.springframework.security.authentication.ProviderManager;
            import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
            import org.springframework.security.config.annotation.web.builders.HttpSecurity;
            import org.springframework.security.config.annotation.web.builders.WebSecurity;
            import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
            import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
            import org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider;
            import java.util.Arrays;

            @Configuration
            @EnableWebSecurity
            public class WebSecurityConfigAD extends WebSecurityConfigurerAdapter {

             @Value("${ad.domain}")
             private String AD_DOMAIN;

             @Value("${ad.url}")
             private String AD_URL;

             @Override
             protected void configure(HttpSecurity http) throws Exception {
              http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
             }

             @Override
             protected void configure(AuthenticationManagerBuilder authManagerBuilder) throws Exception {
              authManagerBuilder.authenticationProvider(activeDirectoryLdapAuthenticationProvider()).userDetailsService(userDetailsService());
             }

             @Bean
             public AuthenticationManager authenticationManager() {
              return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider()));
             }
             @Bean
             public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() {
              ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(AD_DOMAIN, AD_URL);
              provider.setConvertSubErrorCodesToExceptions(true);
              provider.setUseAuthenticationRequestCredentials(true);

              return provider;
             }
            }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接