Spring Security针对同一URL的多个身份验证提供程序

时间:2019-09-11 02:58:00

标签: spring spring-security

我有一个入口点应用程序。我正在使用两个身份验证提供程序-DB和LDAP。当单独使用它们时,它们可以很好地工作,但是我无法使其一起使用。

此外,我有两个登录页面,一个用于DB,另一个用于LDAP。

如何为集成身份验证配置spring security XML。

我尝试在单个身份验证管理器中使用多个提供程序,并将其配置为单个http标签。

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
             xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security.xsd">



    <http  auto-config="true" use-expressions="true" pattern="/" authentication-manager-ref="authenticationManager" >
    <intercept-url pattern="/welcome" access="hasAnyRole('ROLE_ADMIN','ROLE_USER')"/>

        <form-login login-page="/login_normal" default-target-url="/" authentication-failure-url="/login_normal?error" username-parameter="username" password-parameter="password"/>
        <csrf disabled="true"/>
        <session-management invalid-session-url="/login">
            <concurrency-control expired-url="/login" />
        </session-management>
        <access-denied-handler error-page="/accessDenied"/>
    </http>

    <http  auto-config="true" use-expressions="true" pattern="/"  authentication-manager-ref="customAuthenticationManager" >
    <intercept-url pattern="/welcome" access="permitAll"/>

        <form-login login-page="/login_normal2" default-target-url="/welcome" authentication-failure-url="/login_normal2?error" username-parameter="username" password-parameter="password"/>
        <csrf disabled="true"/>


        <session-management invalid-session-url="/login">
            <concurrency-control expired-url="/login" />
        </session-management>
        <access-denied-handler error-page="/accessDenied"/>
    </http>


    <authentication-manager id="authenticationManager">
        <authentication-provider user-service-ref="loginUserDetailsServiceImpl">
            <password-encoder ref="encoder"></password-encoder>
        </authentication-provider>

    </authentication-manager>


    <authentication-manager id="customAuthenticationManager">

        <ldap-authentication-provider user-dn-pattern="<pattern>" server-ref="ldapServer">

        </ldap-authentication-provider>
    </authentication-manager>


    <ldap-server id="ldapServer" url="<server url>"
        manager-dn="<admin name>" manager-password="<password>"/>




    <beans:bean id="loginUserDetailsServiceImpl" class="com.ipt.web.service.LoginUserDetailsServiceImpl"></beans:bean>


    <beans:bean id="encoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder">
        <beans:constructor-arg name="strength" value="11"/>
    </beans:bean>
</beans:beans>

0 个答案:

没有答案