Spring Security AD LDAP:错误代码1 - 000004DC:LdapErr:DSID-0C0906E8

Jon*_*ith 5 spring-security spring-ldap

我试图从Spring安全连接Ldap,获得连接错误.有人会建议这个配置有什么问题,

UsernamePasswordAuthenticationFilter - 尝试验证用户时发生内部错误.org.springframework.security.authentication.InternalAuthenticationServiceException:在LDAP处理期间发生了未分类的异常; 嵌套异常是javax.naming.NamingException:[LDAP:错误代码1 - 000004DC:LdapErr:DSID-0C0906E8,注释:为了执行此操作,必须在连接上完成成功绑定.,data 0,v1db1]; 其余名称'ou =用户,dc = aaa,dc = bbb,dc = ccc,dc = dddd'at org.springframework.security.ldap.authentication.LdapAuthenticationProvider.doAuthentication(LdapAuthenticationProvider.java:191)

配置文件有,

<sec:authentication-manager alias="myAuthenticationManager">
    <sec:authentication-provider ref="myAuthenticationProvider"/>
</sec:authentication-manager>

<bean id="myAuthenticationProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <constructor-arg ref="ldapBindAuthenticator"/>
    <constructor-arg ref="ldapAuthoritiesPopulator"/>
</bean>

<bean id="ldapBindAuthenticator" class="org.springframework.security.ldap.authentication.BindAuthenticator">
    <constructor-arg ref="contextSource" />
    <property name="userSearch" ref="userSearch"/>
</bean>

<bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
    <constructor-arg index="0" value="ou=Users,dc=aaa,dc=bbb,dc=ccc,dc=dddd"/>
    <constructor-arg index="1" value="(sAMAccountName={0})"/>
    <constructor-arg index="2" ref="contextSource"/>
    <property name="searchSubtree" value="true"/>
</bean>

<bean id="ldapAuthoritiesPopulator" class="com.xxxx.MyLdapAuthoritiesPopulator">
    <property name="userDao" ref="userDao"/>
</bean>

<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <constructor-arg value="ldaps://aaa.com:123/DC=aa,DC=bb,DC=cc,DC=dd"/>
    <property name="base" value="DC=aa,DC=bb,DC=cc,DC=dd" />
    <!-- <property name="anonymousReadOnly" value="true"/> -->

</bean>
Run Code Online (Sandbox Code Playgroud)

Pav*_*ral 8

让我们假设用户尝试使用用户名XXX和密码YYY登录.通常LDAP身份验证的工作方式如下

  1. 使用技术帐户绑定到LDAP
  2. 使用用户名XXX =>搜索用户获取他的DN
  3. 尝试使用找到的DN和密码YYY绑定到LDAP

您的错误表明您没有正确执行第一步(技术帐户绑定).

尝试将userDn和密码添加到您的上下文源(这来自官方JavaDoc):

<bean id="contextSource"
        class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <constructor-arg value="ldap://monkeymachine:389/dc=springframework,dc=org"/>
    <property name="userDn" value="cn=manager,dc=springframework,dc=org"/>
    <property name="password" value="password"/>
</bean>
Run Code Online (Sandbox Code Playgroud)