无法连接外部LDAP服务器

时间:2017-11-01 05:09:18

标签: java spring spring-security active-directory

我正在使用spring boot开发一个API,它会根据我们公司的AD验证用户和密码。我厌倦了嵌入LDAP测试服务器的示例,它运行得很好。但是,每当我尝试连接到LDAP服务器时,都会看到以下错误消息。

这就是我在做的事。

protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth
            .ldapAuthentication()
            .userDnPatterns("uid={0},ou=people")
            .groupSearchBase("ou=groups")
            .contextSource()
                .url("ldap://<company AD server>/dc=springframework,dc=org")
                .and()
            .passwordCompare()
                .passwordEncoder(new LdapShaPasswordEncoder())
                .passwordAttribute("userPassword");

错误讯息: -

  

尝试验证用户时发生内部错误。   org.springframework.security.authentication.InternalAuthenticationServiceException:   在LDAP处理期间发生了未分类的异常;嵌套   异常是javax.naming.NamingException:[LDAP:错误代码1 -   000004DC:LdapErr:DSID-0C0906E8,注释:为了执行此操作   操作成功绑定必须在连接。,数据上完成   0,v1db1]

我不确定我哪里出错了。我试着用谷歌搜索但没有运气。我正在使用带有弹簧安全性的eclipse。

1 个答案:

答案 0 :(得分:0)

  

您需要配置允许读取LDAP服务器的用户。

在您的AuthenticationConfiguration中,您只是定义了LDAP服务器的URL,但没有允许执行搜索并从那里读取的用户。

.contextSource()
        .url("ldaps://<ap-ldap-server>")
        .port(639)
        .managerDn("cn=binduser,ou=users,dc=ap,dc=domain,dc=com")
        .managerPassword("some pass")

阅读此答案What login name to use for Spring LDAP authentication了解如何定义经理连接