【问题标题】:How to do LDAP authentication and DataBase authorization in Spring Security如何在 Spring Security 中进行 LDAP 身份验证和数据库授权
【发布时间】:2012-08-31 13:21:41
【问题描述】:
我是否可以有一个 Spring Security 项目,在该项目中我针对 LDAP 进行身份验证并针对数据库为经过身份验证的用户设置权限?
谢谢!
【问题讨论】:
标签:
database
spring
security
ldap
authorization
【解决方案1】:
我已经解决了这个问题,答案在上面:
<authentication-manager >
<authentication-provider ref="ldapAuthProvider" />
</authentication-manager>
<beans:bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<beans:constructor-arg value="ldap://IP:port/...."/>
</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="userSearch" ref="ldapUserSearch" />
</beans:bean>
</beans:constructor-arg>
<beans:constructor-arg>
<beans:bean
class="prpa.athos.security.listener.MyLDAPAuthorities">
</beans:bean>
</beans:constructor-arg>
</beans:bean>
<beans:bean id="authenticationSuccessListener"
class="prpa.athos.security.listener.AuthenticationSuccessListener">
</beans:bean>
<beans:bean id="ldapUserSearch"
class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<beans:constructor-arg index="0" value=""/>
<beans:constructor-arg index="1" value="(uid={0})"/>
<beans:constructor-arg index="2" ref="contextSource" />
</beans:bean>
在 MyLDAPAuthorities 类上,我实现了 LdapAuthoritiesPopulator 类从数据库中获取权限。
【解决方案2】:
是的,您需要一个 LdapBindAuthenticator 和一个基于 DAO 的 AuthoritiesPopulator。