2013-05-07 94 views
1

我們使用彈簧安全&使用LDAP來驗證我們的Web應用程序。在我們的LDAP配置中,有多個可用的userndn模式。我想知道如何在applicationContext-security.xml文件中配置多個userdn模式。我有以下配置中指定Spring Security LDAP身份驗證多個DN模式

<b:bean id="ldapProvider" 
    class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"> 
    <b:constructor-arg> 
     <b:bean 
      class="com.intl.set.him.mait.security.CustomLdapAuthenticator"> 
      <b:constructor-arg ref="ldapContextSource" /> 
      <b:property name="userDnPatterns" value="cn={0},OU=GEN,OU=Users"/> 
      <b:property name= "commonNameQuery" value = "select USER_CN from emt.sec_users1 where user_id=?"/> 
      <b:property name="datasource" ref="dataSourceMSSQL"/> 

</b:bean> 

當我提供在XML文件中的上述結構中,對應於一個特定的位置DN模式用戶將只能夠登錄。我想知道我們如何在xml文件中配置多個userdn模式。

任何幫助,這是非常感謝。謝謝

+0

不要在Web上發佈內部信息! – Michael 2013-05-07 08:02:20

回答

0

該bean充當指定類的構造函數(通常帶有參數和/或屬性)。如果你簡單地擴展在自己的子類,類,可以從子類參數傳遞給supoerclass的構造函數和設置屬性:

CustomLdapAuthenticationProvider.java

public class CustomLdapAuthenticationProvider extends LdapAuthenticationProvider { 
    //your constructor 
    public CustomLdapAuthenticationProvider(unParsedArguments) { 
     //some logic to parse the arguments as desired 
     super(parsedArguments); 
     //set super's properties as desired 

    } 

    //other methods as needed/required 
} 

這種方法爲您提供了很大的靈活性你的應用程序設計,這是什麼激發開源 - 很容易擴展,覆蓋等等。你也已經在做大部分。

然後,改變你的applicationContext-security.xml

<bean id="ldapProvider" 
     class="your.project.package.CustomLdapAuthenticationProvider"> 
    <constructor-arg value="firstArgument"/> 
    <constructor-arg value="secondArgument"/> 
    <!-- etc. //--> 
    <property name="fieldName" value="valueToBeSet"/> 
</bean> 

顯然,這是人爲的,但你應該看看你需要做什麼:延伸,覆蓋/過載,並根據您的邏輯調用超類的方法/構造與靜態模板相反。

我希望這會有所幫助。

相關問題