2010-04-20 195 views
1

我可以綁定到嵌入式LDAP服務器我的本地機器上,使用下列豆:如何配置Spring Security PasswordComparisonAuthenticator

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

通過調試,我可以看到,在認證方法從ldif文件拿起DN,但隨後嘗試比較密碼,但是,它的使用LdapShaPasswordEncoder(默認的),其中通單詞在文件中以明文存儲,並且這是認證失敗的地方。

這裏的認證管理器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口令編碼器,以明文或者只是留空,似乎它不使一個區別。任何幫助將不勝感激。

感謝

回答

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

相關問題