会话超时后,Spring安全性不会重定向到上次请求的页面登录

我在我的应用程序中使用Spring Security 4.2.2.RELEASE。一旦发生超时,然后用户点击任何URL,它就会被重定向到注销页面,一旦认证成功,它就会重定向到默认的主页,而不是请求的页面。

web xml如下:

<bean id="logoutSuccessHandler"
         class="org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler">
         <property name="useReferer" value="true"/>
     </bean>


    <security:form-login
            login-page="/login"
            authentication-failure-url="/login_error"
            username-parameter="username"
            password-parameter="password"
            default-target-url="/home"
            always-use-default-target="false"
            />

我希望它在身份验证正确后重定向到请求的页面。我已经读过Spring Security默认提供此功能。但它没有用,所以我试图使用SimpleUrlLogoutSuccessHandler来实现。但仍无法找到方法。那么这里可能出现什么问题?


BIG阳
浏览 818回答 2
2回答

湖上湖

好吧,你需要实施SimpleUrlAuthenticationSuccessHandler。这有助于您处理重定向。&nbsp;&nbsp;&nbsp;&nbsp;<http> &nbsp;&nbsp;&nbsp;&nbsp;<intercept-url&nbsp;pattern="/login"&nbsp;access="permitAll"/> &nbsp;&nbsp;&nbsp;&nbsp;<intercept-url&nbsp;pattern="/**"&nbsp;access="isAuthenticated()"/> &nbsp;&nbsp;&nbsp;&nbsp;<form-login&nbsp;authentication-success-handler-ref="refererHandler"&nbsp;/></http><beans:bean&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;class="RefererRedirectionAuthenticationSuccessHandler" &nbsp;&nbsp;name="refererHandler"/>并执行如下:&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;class&nbsp;RefererRedirectionAuthenticationSuccessHandler&nbsp; &nbsp;&nbsp;extends&nbsp;SimpleUrlAuthenticationSuccessHandler &nbsp;&nbsp;implements&nbsp;AuthenticationSuccessHandler&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;RefererRedirectionAuthenticationSuccessHandler()&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setUseReferer(true); &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java