Spring安全预认证/登录

Spring安全预认证/登录,spring,spring-security,pre-authentication,Spring,Spring Security,Pre Authentication,为了使用pre_AUTH_过滤器执行预身份验证,我使用Spring Security进行了概念验证。它工作正常,但是我想知道如果这个过滤器不工作,我是否可以重定向到登录页面,因为我得到了HTTP 403。 我的意思是,如果初始请求的标题中不包含SM_USER字段,我如何重定向到登录页面?我需要考虑这两种情况(当它包含字段- SmithUpple,而不是)时,我无法使它工作。有什么想法吗 Pra身份验证与Spring Security中的登录身份验证一起顺利工作。您只需设置一个有效的登录表单配置,

为了使用pre_AUTH_过滤器执行预身份验证,我使用Spring Security进行了概念验证。它工作正常,但是我想知道如果这个过滤器不工作,我是否可以重定向到登录页面,因为我得到了HTTP 403。

我的意思是,如果初始请求的标题中不包含SM_USER字段,我如何重定向到登录页面?我需要考虑这两种情况(当它包含字段- SmithUpple,而不是)时,我无法使它工作。有什么想法吗

Pra身份验证与Spring Security中的登录身份验证一起顺利工作。您只需设置一个有效的登录表单配置,并添加PRE_AUTH_过滤器

Spring只会重定向到登录页面,如果在通过身份验证过滤器后,它检测到用户在应该进行身份验证时未进行身份验证。因此,如果请求头中包含预期字段,则用户将通过PRE_AUTH_FILTER过滤器进行身份验证,而不会转到登录页面。但如果它不包含身份验证,Spring security将检测到缺少身份验证并重定向到登录页面。

以下是我的设置:

<http auto-config="true"  use-expressions="true" entry-point-ref="http403EntryPoint">
    <intercept-url pattern="/login" access="permitAll" />
    <intercept-url pattern="/logout" access="permitAll" />
    <intercept-url pattern="/accessdenied" access="permitAll" />
    <intercept-url pattern="/**" access="hasRole('ROLE_USER')" />
    <custom-filter before="PRE_AUTH_FILTER" ref="siteminderFilter" />
    <form-login login-page="/login" default-target-url="/list" authentication-failure-url="/accessdenied" /> 
    <logout logout-success-url="/logout" />
</http>

<beans:bean id="siteminderFilter" class="org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter">
    <beans:property name="principalRequestHeader" value="SM_USER"/>
    <beans:property name="authenticationManager" ref="authenticationManager" />
    <beans:property name="exceptionIfHeaderMissing" value="false" />
</beans:bean>

<beans:bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
    <beans:property name="preAuthenticatedUserDetailsService">
        <beans:bean id="userDetailsServiceWrapper"  class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
            <beans:property name="userDetailsService" ref="customUserDetailsService"/>
        </beans:bean>
    </beans:property>
</beans:bean>

<authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="employeeDAO" />
    <authentication-provider ref="preauthAuthProvider" />
</authentication-manager>

<beans:bean id="customUserDetailsService" class="com.test.security.CustomUserDetailsService"></beans:bean>
<beans:bean id="http403EntryPoint" class="org.springframework.security.web.authentication.Http403ForbiddenEntryPoint"></beans:bean> 


向我们展示您的配置,欢迎回复。我基本上是想这么做,但对我来说不起作用。