java - 无法通过 Spring Security 的 LDAP 身份验证登录

标签 java authentication spring-boot active-directory

您好,我正在研究 Spring Boot,我正在尝试使用 Spring Security 从 Activity 目录进行用户身份验证。但我无法将用户登录到应用程序中,我尝试了几种方法,这是我尝试过的代码:

@Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth
            .ldapAuthentication()
                .userDnPatterns("uid={0},ou=Users")
                .groupSearchBase("ou=groups")
                .contextSource(contextSource())
                .passwordCompare()
                    .passwordEncoder(new LdapShaPasswordEncoder())
                    .passwordAttribute("userPassword");
    }

    @Bean
    public DefaultSpringSecurityContextSource contextSource() {
        return  new DefaultSpringSecurityContextSource(Arrays.asList("ldap://WIN-BSCF2478SL5.Adexample.com"), "CN=Administrator,DC=ADExample,DC=com");
    }

我尝试实现 here 中的示例

当我尝试从管理员登录时收到的错误如下:

原因:LDAP处理过程中发生未分类异常;嵌套异常是 javax.naming.NamingException: [LDAP: 错误代码 1 - 000004DC: LdapErr: DSID-0C0906E8,注释:为了执行此操作,必须在连接上完成成功的绑定(bind)。,数据 0,v1db1];剩余名称 'uid=administrator,ou=Users'

我还尝试使用 userSearchFilter 而不是 userDnPatterns 但仍然遇到异常,这里是代码

auth.ldapAuthentication().userSearchFilter("uid={0}").contextSource()
                .url("ldap://WIN-BSCF2478SL5.Adexample.com/DC=ADExample,DC=com").managerDn("Administrator")
                .managerPassword("Passw0rd");

我得到的这段代码的异常如下: 我得到异常:原因:[LDAP:错误代码 49 - 80090308:LdapErr:DSID-0C0903A9,注释:AcceptSecurityContext 错误,数据 52e,v1db1];嵌套异常是 javax.naming.AuthenticationException: [LDAP: 错误代码 49 - 80090308: LdapErr: DSID-0C0903A9,注释:AcceptSecurityContext 错误,数据 52e,v1db1]

最后我也尝试了不提供用户名及其密码

auth.ldapAuthentication().userSearchFilter("uid={0}").contextSource()
            .url("ldap://WIN-BSCF2478SL5.Adexample.com/DC=ADExample,DC=com");

它对我也不起作用,我得到的异常(exception)是

原因:LDAP处理过程中发生未分类异常;嵌套异常是 javax.naming.NamingException: [LDAP: 错误代码 1 - 000004DC: LdapErr: DSID-0C0906E8,注释:为了执行此操作,必须在连接上完成成功的绑定(bind)。,数据 0,v1db1];剩余名称 '/'

最佳答案

类似问题可以查here .

您收到的错误可能是由多种其他原因引起的,因为我们看不到您的配置。您似乎无法绑定(bind)到 LDAP。您的 LDAP 配置正确吗?您是否尝试像教程指出的那样配置 test-server.ldif ?

关于java - 无法通过 Spring Security 的 LDAP 身份验证登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43497482/

相关文章:

java - Java HTTP 服务器

java - bean类无效属性 'dao'的原因

Java apache Httpclient 基于表单登录myspace

java - 为什么liquibase无法解析db.changelog类路径?

mysql - 文件上传 Angular - spring boot - mysql

java - Spring boot - 返回 403 Forbidden 而不是重定向到登录页面

java - 使用赋值运算符设置 cplex java 约束 "+="

java - IntelliJ IDEA 13 和 Android Studio 的区别

authentication - 如何在 AspNetCore SignalR Alpha 中启用 Windows 身份验证

http - 这里应该使用 401 Unauthorized 还是 403 Forbidden?