2

在我的应用程序中,我正在向用户发送一封电子邮件,其中包含指向 jsp 的链接。如果用户单击该链接但未登录,则将重定向到登录页面,成功登录后将重定向到默认登录页面。

我希望当用户成功登录时,它应该被重定向到用户提交请求的同一页面(链接页面),而不是默认页面。

我正在使用 Spring Security 2.0.2。

任何帮助,将不胜感激。

4

2 回答 2

1

使用 SavedRequestAwareAuthenticationSuccessHandler 定义 yourAuthenticationFilter

    <bean id="yourAuthenticationFilter" class="yourAuthenticationFilterClass">  
        <property name="authenticationSuccessHandler">
            <bean class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler" />
        </property>
    </bean>
于 2013-03-13T13:40:03.067 回答
0

我找到了答案。我在扩展的自定义身份验证过滤器中添加了以下几行AuthenticationProcessingFilter

HttpSession session = request.getSession(false);
        SavedRequest savedRequest = null; 
        if (session != null) {
            savedRequest = (SavedRequest) session.getAttribute(SPRING_SECURITY_SAVED_REQUEST_KEY);
        }

savedRequest 对象存储最后一次请求的 url,认证成功后可以设置为目标 url。

PS 这项工作在 Spring security 2.0 中。

于 2013-03-16T05:17:34.980 回答