1

我可以使用以下 bean 绑定到本地机器上的嵌入式 ldap 服务器:

<b:bean id="secondLdapProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <b:constructor-arg>
        <b:bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
            <b:constructor-arg ref="contextSource" />
            <b:property name="userSearch">
                <b:bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
                  <b:constructor-arg index="0" value="ou=people"/>
                  <b:constructor-arg index="1" value="(uid={0})"/>
                  <b:constructor-arg index="2" ref="contextSource" />
                </b:bean>
            </b:property>
        </b:bean>
    </b:constructor-arg>
    <b:constructor-arg>
        <b:bean class="com.company.security.ldap.BookinLdapAuthoritiesPopulator">
        </b:bean>
    </b:constructor-arg>
</b:bean>

但是,当我尝试使用 PasswordComparisonAuthenticator 进行身份验证时,它会在凭据错误事件中反复失败:

 <b:bean id="ldapAuthProvider"
    class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <b:constructor-arg>
        <b:bean
            class="org.springframework.security.ldap.authentication.PasswordComparisonAuthenticator">
            <b:constructor-arg ref="contextSource" />
            <b:property name="userDnPatterns">
                <b:list>
                    <b:value>uid={0},ou=people</b:value>
                </b:list>
            </b:property>
        </b:bean>
    </b:constructor-arg>
    <b:constructor-arg>
        <b:bean class="com.company.security.ldap.BookinLdapAuthoritiesPopulator">
        </b:bean>
    </b:constructor-arg>
</b:bean>

通过调试,我可以看到 authenticate 方法从 ldif 文件中获取 DN,然后尝试比较密码,但是,它使用的是 LdapShaPasswordEncoder (默认密码),其中密码以明文形式存储在文件中,并且这是身份验证失败的地方。

这是引用首选身份验证 bean 的身份验证管理器 bean:

<authentication-manager>

    <authentication-provider ref="ldapAuthProvider"/>

    <authentication-provider user-service-ref="userDetailsService">
        <password-encoder hash="md5" base64="true">
            <salt-source system-wide="secret"/>
        </password-encoder>
    </authentication-provider>
</authentication-manager>

附带说明一下,无论我将 ldapAuthProvider 上的密码编码器设置为纯文本还是将其留空,似乎都没有区别。任何帮助将不胜感激。

谢谢

4

1 回答 1

1

通过将 PlainTextPasswordEncoder 注入 passwordEncoder 属性,我能够覆盖 PasswordComparisonAuthenticator 中的默认 LdapShaPasswordEncoder:

 <b:bean id="ldapAuthProvider"
    class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <b:constructor-arg>
        <b:bean
            class="org.springframework.security.ldap.authentication.PasswordComparisonAuthenticator">
            <b:constructor-arg ref="contextSource" />
            <b:property name="passwordEncoder">
                <b:bean class="org.springframework.security.authentication.encoding.PlaintextPasswordEncoder"></b:bean>
            </b:property>
            <b:property name="userDnPatterns">
                <b:list>
                    <b:value>uid={0},ou=people</b:value>
                </b:list>
            </b:property>
        </b:bean>
    </b:constructor-arg><b:constructor-arg>
        <b:bean class="com.company.security.ldap.BookinLdapAuthoritiesPopulator">
        </b:bean>
    </b:constructor-arg>
</b:bean>

现在它不会在比较之前将提供的输入转换为 SHA...

于 2010-04-21T20:51:29.337 回答