2009-05-28 115 views
3

我是Spring的新手,所以這個問題可能看起來很明顯。如何在Spring安全中進行LDAP身份驗證和數據庫授權?

我試圖實現Spring安全性,我的要求是驗證對LDAP服務器的用戶名/密碼,一旦用戶通過身份驗證,我需要從關係數據庫檢索用戶角色。

是否有可能在Spring安全中做到這一點?

回答

4

是的。

內置ldap認證管理器將用戶的認證和授權分爲兩部分 您可以像下面那樣配置基於LDAP的認證管理器。

<bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager"> 
    <property name="providers"> 
     <list> 
      <ref local="ldapAuthenticationProvider"/> 
     </list> 
    </property> 
</bean> 

身份驗證提供程序是這樣配置的。

<bean id="ldapAuthenticationProvider" class="org.acegisecurity.providers.ldap.LdapAuthenticationProvider"> 
    <constructor-arg><ref local="authenticator"/></constructor-arg> 
    <constructor-arg><ref local="populator"/></constructor-arg> 
    <property name="userCache"><ref local="userCache"/></property> 
</bean> 

我不知道是否有一個內置的populator可以做你想做的,但是如果需要你可以開發你自己的。

+1

您可以使用UserDetailsS​​erviceLdapAuthoritiesPopulator委託給標準的UserDetailsS​​ervice。這將完全符合Veera的需求。 – 2009-05-28 10:13:41

相關問題