简体   繁体   English

如何在Spring安全性中进行LDAP身份验证和数据库授权?

[英]How to do LDAP authentication and database Authorization in Spring security?

I'm new to Spring, so this question may look like so obvious. 我是Spring的新手,所以这个问题可能看起来很明显。

I'm trying to implement Spring security and my requirement is to authenticate the user name/password against a LDAP server and once the user is authenticated, I need to retrieve the user roles from a relational database. 我正在尝试实现Spring安全性,我的要求是针对LDAP服务器验证用户名/密码,一旦用户通过身份验证,我需要从关系数据库中检索用户角色。

is it possible to do this in Spring security? 是否可以在Spring安全性中执行此操作?

Yes. 是。

The build-in ldap authentication manager splits the authentication and authorisation of a user into 2 parts You can configure a LDAP based authentiication manager like below. 内置ldap身份验证管理器将用户的身份验证和授权分为两部分您可以配置基于LDAP的身份验证管理器,如下所示。

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

The authentication provider is configured like this. 身份验证提供程序配置如下。

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

I don't know if there's a built-in populator that will do what you want, but you can develop your own one if required. 我不知道是否有内置的populator可以做你想要的,但你可以根据需要开发自己的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM