2011-11-08 50 views
1

我正在使用Spring和Spring Security與LDAP一起開發項目。在我們使用MD5密碼之前,我讓我的項目在LDAP上工作得很好。現在我們使用MD5用戶密碼,我試圖在Spring XML中找到一種方法,在檢查LDAP之前告訴Springs到MD5密碼。如何在調用LDAP之前創建Spring Security 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> 

回答

0

試試這個:

<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 tryed它。但它有效地適用於「正常」(而不是LDAP)身份驗證提供程序。

+0

什麼都不起作用? – Ralph

1

密碼應該通過安全連接以明文方式發送,不應使用摘要預編碼或以任何方式預編碼 - 預編碼的密碼會阻止目錄服務器執行密碼質量檢查。目錄服務器加密或散列明文密碼並將密碼與目標條目中加密/散列的密碼進行比較,並返回綁定響應中的成功或失敗。

0

如果您使用的是綁定驗證,那麼Terry的回答是正確的,Spr Sec LDAP客戶端正嘗試使用提供的用戶名和明文密碼綁定到LDAP(順便說一句,這就是爲什麼SLDAP總是建議您使用綁定驗證)。

如果使用密碼比較認證,則用於比較的密碼必須進行散列或編碼以與存儲在LDAP存儲庫中的密碼完全匹配。

由於它看起來像你正在使用綁定認證,你應該沒有問題,因爲目前的情況。

這些概念在LDAP section of the manual中涵蓋得很好。

相關問題