[英]In Spring security 2.0.2 How to redirect to a requested url after login
在我的應用程序中,我正在向用戶發送一封電子郵件,其中包含指向jsp的鏈接。 如果用戶單擊該鏈接但未登錄,則它將重定向到登錄頁面,並且在成功登錄后,它將重定向到默認登錄頁面。
我想要當用戶成功登錄后將其重定向到用戶提交請求的同一頁面(鏈接頁面),而不是默認頁面。
我正在使用Spring Security 2.0.2。
任何幫助,將不勝感激。
使用SavedRequestAwareAuthenticationSuccessHandler定義yourAuthenticationFilter
<bean id="yourAuthenticationFilter" class="yourAuthenticationFilterClass">
<property name="authenticationSuccessHandler">
<bean class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler" />
</property>
</bean>
我找到了答案。 我在自定義身份驗證過濾器中添加了以下幾行,這些行擴展了AuthenticationProcessingFilter
HttpSession session = request.getSession(false);
SavedRequest savedRequest = null;
if (session != null) {
savedRequest = (SavedRequest) session.getAttribute(SPRING_SECURITY_SAVED_REQUEST_KEY);
}
保存的對象存儲最后請求的URL,可以在成功認證后將其設置為目標URL。
PS這項工作在Spring Security 2.0中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.