在重定向到登录页面之前,spring会在哪个过滤器中存储访问的url? [英] In which filter does spring store the accessed url, before redirecting to the login page?

查看:264
本文介绍了在重定向到登录页面之前,spring会在哪个过滤器中存储访问的url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring安全性(3.0.6)中,如果我们尝试访问一个页面,并且会话超时,我们会进入登录页面,并且在成功认证后,我们被重定向到我们尝试过的页面在我们被带到登录页面之前访问。在过滤拦截链,这是'最后访问'的网址保存?



我想修改这个最后访问的URL在特定情况下,当它重定向到'/ exitUser'。我怎么能做到这一点?

解决方案

传入的请求的副本被缓存(不仅仅是URL),重定向到登录页面。 ExceptionTranslationFilter 意识到需要登录,并将请求传递给配置的 RequestCache 实例。在参考手册



您可以通过从<$ c>请求来访问 SavedRequest $ C> RequestCache 。默认情况下它存储在会话中,所以创建一个 HttpSessionRequestCache 将会给你所需的功能。你也可以通过使用 RequestCache 。 x / reference / springsecurity-single.html#nsa-request-cacherel =nofollow> namespace

实际的重定向,保存的请求由 AuthenticationSuccessHandler 实例执行。如果您想更改成功登录的重定向,可以自定义。您可以在手册中找到更多信息,也可以在之前的问题中找到。


In Spring security (3.0.6), if we try to access a page, and the session times out, we are taken to the login page, and upon successful authentication, we are redirected to the very page that we had tried to access before we were taken to the login page. Where, in the filter interceptor chain, is this 'last-accessed' url saved ?

I wish to modify this 'last accessed' url in the particular case when it redirects to '/exitUser'. How can I do that ?

解决方案

A copy of the incoming request is cached (not just the URL), before redirecting to the login page. The ExceptionTranslationFilter realises that a login is required and passes the request to the configured instance of RequestCache. There is a basic description in the reference manual.

You can access the SavedRequest by requesting it from the RequestCache. By default it is stored in the session, so creating an HttpSessionRequestCache will give you the required functionality. You can also customize the RequestCache if you wish by using the namespace.

The actual redirect, which uses the saved request, is performed by the AuthenticationSuccessHandler instance. You can customize that if you want to change the redirect for a successful login. You'll find more on that in the manual and also in previous SO questions.

这篇关于在重定向到登录页面之前,spring会在哪个过滤器中存储访问的url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆