2011-11-08 6 views
1

私は、LDAPでSpringとSpringのセキュリティを使用しているプロジェクトで作業しています。私は自分のプロジェクトをLDAPでうまく動作させる前に、ユーザーのパスワードをMD5で保存しました。今私たちはMD5ユーザーのパスワードを私はスプリングXMLにMD5のパスワードをLDAPをチェックする前に指示する方法を見つけようとしています。私はLDAPでそれをしようと試みていないLDAPを呼び出す前にSpring Security MD5パスワードを作成する方法

<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> 

は、以下の私の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

これを試してみてくださいです。しかし、それは「通常の」(LDAPではなく)認証プロバイダのために頑強に機能します。

+0

何がうまくいかなかったのですか? – Ralph

1

パスワードは安全な接続でクリアに送信する必要があります。ダイジェストで事前にエンコードしたり、事前にエンコードしたりしないでください。事前にエンコードされたパスワードは、ディレクトリサーバーによるパスワード品質チェックの実行を妨げます。ディレクトリー・サーバーはクリアテキスト・パスワードを暗号化またはハッシュし、ターゲット・エントリーで暗号化/ハッシュされたものとパスワードを比較し、バインド応答で成功または失敗を戻します。

0

バインド認証を使用している場合、Spr Sec LDAPクライアントは、指定されたユーザー名とプレーンテキストのパスワードを使用してLDAPにバインドしようとしています(つまり、バインド認証を使用する場合はSLDAPが常に推奨されます)。

パスワード比較認証を使用している場合、比較に使用するパスワードは、LDAPリポジトリに保存されているパスワードと正確に一致するようにハッシュまたはエンコードする必要があります。

バインド認証を使用しているように見えるので、現状のままであれば問題ありません。

これらの概念は、LDAP section of the manualでかなりカバーされています。

関連する問題