【问题标题】:How to make Spring Security MD5 password before calling LDAP如何在调用 LDAP 之前设置 Spring Security MD5 密码
【发布时间】:2011-12-24 15:28:11
【问题描述】:

我正在开发一个使用 Spring 和 Spring Security 和 LDAP 的项目。在我们对用户密码进行 MD5 之前,我的项目使用 LDAP 运行良好。现在我们对用户密码进行 MD5 处理,我正试图在 Spring XML 中找到一种方法,在检查 LDAP 之前告诉 Springs 对密码进行 MD5 处理。

下面是我的 XML

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/jdbc
           http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.0.xsd">

    <http auto-config="true" use-expressions='true'>
        <intercept-url pattern="/friends/**" access="isAuthenticated()" />
        <intercept-url pattern="/articles/**" access="isAuthenticated()" />
    </http>

    <authentication-manager>
        <ldap-authentication-provider
            user-search-filter="(uid={0})" user-search-base="ou=sampleusers" />
    </authentication-manager>


    <beans:bean id="contextSource"
        class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
        <beans:constructor-arg value="ldap://localhost:389/dc=xxxwf,dc=org" />
        <beans:property name="userDn" value="cn=admin,dc=xxxwf,dc=org" />
        <beans:property name="password" value="sabrina123" />
    </beans:bean>
    <beans:bean id="ldapAuthProvider"
        class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
        <beans:constructor-arg>
            <beans:bean
                class="org.springframework.security.ldap.authentication.BindAuthenticator">
                <beans:constructor-arg ref="contextSource" />
                <beans:property name="userDnPatterns">
                    <beans:list>
                        <beans:value>uid={0},ou=sampleusers</beans:value>
                    </beans:list>
                </beans:property>
        </beans:constructor-arg>

    </beans:bean>
    <ldap-server url="ldap://127.0.0.1:389/dc=xxxwf,dc=org" />

    <beans:bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <beans:property name="location" value="classpath:jdbc.properties" />


    </beans:bean>
    <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <beans:property name="driverClassName" value="${database.driver}" />
        <beans:property name="url" value="${database.url}" />
        <beans:property name="username" value="${database.user}" />
        <beans:property name="password" value="${database.password}" />
        <beans:property name="initialSize" value="5" />
        <beans:property name="maxActive" value="10" />
    </beans:bean>
</beans:beans>

【问题讨论】:

    标签: java spring ldap spring-security md5


    【解决方案1】:

    Terry 的回答是正确的,如果您使用绑定身份验证,Spr Sec LDAP 客户端会尝试使用提供的用户名和明文密码绑定到 LDAP(顺便说一句,这就是为什么如果您使用绑定身份验证始终建议使用 SLDAP) .

    如果您使用密码比较身份验证,则您用于比较的密码必须经过散列或编码,以与存储在 LDAP 存储库中的密码完全匹配。

    由于您似乎正在使用绑定身份验证,因此按照目前的情况应该没问题。

    LDAP section of the manual 很好地涵盖了这些概念。

    【讨论】:

      【解决方案2】:

      密码应通过安全连接以明文形式发送,不应使用摘要进行预编码或以任何方式进行预编码 - 预编码密码会阻止目录服务器执行密码质量检查。目录服务器对明文密码进行加密或散列,并将密码与目标条目中加密/散列的密码进行比较,并在绑定响应中返回成功或失败。

      【讨论】:

        【解决方案3】:

        试试这个:

        <security:authentication-manager>
                <security:ldap-authentication-provider>
                <security:password-compare>
                    <security:password-encoder ref="passwordEncoder">
                    </security:password-encoder>
                </security:password-compare>
            </security:ldap-authentication-provider>
        </security:authentication-manager>
        
        <bean id="passwordEncoder" 
              class="org.springframework.security.authentication.encoding.Md5PasswordEncoder">
        </bean>
        

        我没有用 LDAP 尝试过。但它显然适用于“正常”(不是 LDAP)身份验证提供程序。

        【讨论】:

          猜你喜欢
          • 2012-03-28
          • 2023-03-30
          • 2014-09-13
          • 2012-10-15
          • 2018-10-08
          • 2010-12-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多