In my application i am sending an email to a user with a link to a jsp. if user clicks on the link and is not logged-in then it is redirecting to the login page and after successfully login it is redirecting to the default landing page.
I want when user logged in successfully then it should be redirect to same page (link page) for which user submitted the request and not to the default page.
I am using Spring Security 2.0.2.
any help would be appreciated.
define yourAuthenticationFilter with SavedRequestAwareAuthenticationSuccessHandler
<bean id="yourAuthenticationFilter" class="yourAuthenticationFilterClass">
<property name="authenticationSuccessHandler">
<bean class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler" />
</property>
</bean>
I found the answer. i have added the following lines in custom authentication filter which extends AuthenticationProcessingFilter
HttpSession session = request.getSession(false);
SavedRequest savedRequest = null;
if (session != null) {
savedRequest = (SavedRequest) session.getAttribute(SPRING_SECURITY_SAVED_REQUEST_KEY);
}
and savedRequest object stores the last requested url and which can be set as a target url after successful authentication.
PS This work in Spring security 2.0.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.