【问题标题】:Spring security 3.1 authentication LDAP with md5使用 md5 的 Spring Security 3.1 身份验证 LDAP
【发布时间】:2013-05-08 14:26:21
【问题描述】:

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

Authentication request = new UsernamePasswordAuthenticationToken("john", "johnldap");
result = authenticationManager.authenticate(request);

这里是 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"  />

但是使用“ldapsearch”我们可以成功连接:

ldapsearch -D "uid=john,ou=People,dc=example,dc=com" -w johnldap  -L "objectClass=*"

起初我们认为问题在于我们必须告诉 spring 在调用 LDAP 之前对密码进行 md5 处理。所以我们把它添加到applicationSecurtyContext.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"  />

但是当我们添加标签时,它会说:

LDAP: error code 34 - invalid DN]

这里有什么问题?

【问题讨论】:

    标签: spring spring-security spring-ldap


    【解决方案1】:

    如果我没记错的话,user-dn-pattern 不应该包含根 dn,因为它会自动附加。所以尝试使用:

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

    如果您只想进行简单的绑定身份验证,我认为您不需要password-encoder

    【讨论】:

    • 我试过了,它说:LDAP: error code 34 - invalid DN],即使我试图传递密码直接在 md5 中:new UsernamePasswordAuthenticationToken("john", "905514952b7a4248db5147f501eaa48d");。你知道有什么方法可以告诉 spring 获取一些额外的调试信息来观察它发送到 LDAP 服务器的真实查询吗?
    • 尝试为org.springframework.ldap启用跟踪/调试级别日志记录。
    【解决方案2】:

    我花了很多时间尝试连接spring security,查看stackoverflow我也认为它可能是编码问题,因为密码在md5中,虽然我不得不单独添加上面提到的root 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>
    

    【讨论】:

      猜你喜欢
      • 2016-09-09
      • 2012-02-18
      • 2016-09-01
      • 2012-10-10
      • 2018-08-09
      • 2015-10-20
      • 2012-11-18
      • 2013-01-11
      • 2016-08-05
      相关资源
      最近更新 更多