【发布时间】:2026-01-31 23:15:01
【问题描述】:
我是 Spring 新手,所以这个问题可能看起来很明显。
我正在尝试实现 Spring 安全性,我的要求是针对 LDAP 服务器对用户名/密码进行身份验证,一旦用户通过身份验证,我需要从关系数据库中检索用户角色。
是否可以在 Spring 安全性中做到这一点?
【问题讨论】:
我是 Spring 新手,所以这个问题可能看起来很明显。
我正在尝试实现 Spring 安全性,我的要求是针对 LDAP 服务器对用户名/密码进行身份验证,一旦用户通过身份验证,我需要从关系数据库中检索用户角色。
是否可以在 Spring 安全性中做到这一点?
【问题讨论】:
是的。
内置的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>
我不知道是否有内置的填充器可以满足您的需求,但如果需要,您可以开发自己的。
【讨论】: