Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用md5的Spring security 3.1身份验证LDAP_Spring_Spring Security_Spring Ldap - Fatal编程技术网

使用md5的Spring security 3.1身份验证LDAP

使用md5的Spring security 3.1身份验证LDAP,spring,spring-security,spring-ldap,Spring,Spring Security,Spring Ldap,当我们尝试使用spring身份验证管理器进行身份验证时,它会显示“错误凭据”: 下面是SecurityApplicationContext.xml文件: <authentication-manager alias="authenticationManager"> <ldap-authentication-provider server-ref="ldapLocal" user-dn-pattern="uid={0},ou=People

当我们尝试使用spring身份验证管理器进行身份验证时,它会显示“错误凭据”:

下面是SecurityApplicationContext.xml文件:

  <authentication-manager alias="authenticationManager">
        <ldap-authentication-provider server-ref="ldapLocal"
            user-dn-pattern="uid={0},ou=People,dc=example,dc=com">         
        </ldap-authentication-provider> 
    </authentication-manager>
    <ldap-server url="ldap://127.0.0.1:389/dc=example,dc=com" manager-dn="admin" manager-password="xxxxxxxx" id="ldapLocal"  />
起初,我们认为问题在于我们必须告诉spring在调用LDAP之前对密码进行md5。因此,我们将其添加到ApplicationSecurityContext.xml中:

    <beans:bean id="passwordEncoder"  class="org.springframework.security.authentication.encoding.Md5PasswordEncoder">
    </beans:bean>
    <authentication-manager alias="authenticationManager">
        <ldap-authentication-provider server-ref="ldapLocal"
            user-dn-pattern="uid={0},ou=People,dc=example,dc=com">  
         <password-compare>
            <password-encoder ref="passwordEncoder"> </password-encoder>
        </password-compare>
        </ldap-authentication-provider> 
    </authentication-manager>
    <ldap-server url="ldap://127.0.0.1:389/dc=example,dc=com" manager-dn="admin" manager-password="xxxxxxxx" id="ldapLocal"  />

这里怎么了?

如果我没记错的话,
用户dn模式
不应该包含根dn,因为它将被自动追加。因此,请尝试使用:

user-dn-pattern="uid={0},ou=People">

如果你只想做一个简单的绑定身份验证,我认为你不需要密码编码器。

我花了很多时间尝试与spring security连接,查看stackoverflow,我还认为这可能是编码问题,因为密码在md5中,尽管我不得不单独添加上面提到的根dn,密码由ldap服务器编码。以下是我的工作版本:

<ldap-server url="ldap://dsa.company.com:389/" manager-dn="cn=manager,dc=company,dc=com"
    manager-password="pass"></ldap-server>
<authentication-manager>
    <ldap-authentication-provider
        user-dn-pattern="cn={0},ou=people,dc=company,dc=com"
        group-search-base="ou=groups,dc=company,dc=com" />
</authentication-manager>

我尝试过,它说:LDAP:错误代码34-无效DN],甚至我也尝试直接在md5中传递密码:new UsernamePasswordAuthenticationToken(“john”,“905514952b7a4248db5147f501eaa48d”);。您知道如何告诉spring获取一些额外的调试信息以查看它发送到LDAP服务器的实际查询吗?请尝试为
org.springframework.LDAP
启用跟踪/调试级别日志记录。
LDAP: error code 34 - invalid DN]
user-dn-pattern="uid={0},ou=People">
<ldap-server url="ldap://dsa.company.com:389/" manager-dn="cn=manager,dc=company,dc=com"
    manager-password="pass"></ldap-server>
<authentication-manager>
    <ldap-authentication-provider
        user-dn-pattern="cn={0},ou=people,dc=company,dc=com"
        group-search-base="ou=groups,dc=company,dc=com" />
</authentication-manager>