使spring security在登录页面的查询字符串中添加return to url [英] Make spring security add the return to url in the query string for the login page

查看:21
本文介绍了使spring security在登录页面的查询字符串中添加return to url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

之前我询问可以在 Spring Security 2 的表单登录页面中获取原始请求 url.事实证明这实际上对我没有帮助,我需要的是重定向到表单登录页面以将其作为请求嵌入其中范围.所以如果我有:

Earlier I asked if it was possible to get the original request url in the form login page in Spring Security 2. Turns out that actually won't help me, what I need is for the redirect to the form-login page to have that embedded in it as a request parameter. So if I have:

<form-login login-page="/login.html" /> 

并尝试访问 /secure.html 我想在 /login.html?return_to=/secure.html 中结束.

and try to access /secure.html I want to end up in /login.html?return_to=/secure.html.

推荐答案

重定向到登录表单由 AuthenticationEntryPoint 执行.对于 Spring Security 3.0+,这通常是 LoginUrlAuthenticationEntryPoint 的一个实例.在 2.0 中对应的类是 AuthenticationProcessingFilterEntryPoint.

The redirect to the login form is performed by the AuthenticationEntryPoint. For Spring Security 3.0+ this will usually be an instance of LoginUrlAuthenticationEntryPoint. In 2.0 the corresponding class is AuthenticationProcessingFilterEntryPoint.

入口点由 ExceptionTranslationFilter 调用,它也负责缓存请求.因此,您可以编写自定义 AuthenticationEntryPoint 重定向到登录页面 URL,并附加附加参数(包含当前请求 URI).代码应该与标准实现几乎相同.

The entry point is invoked by the ExceptionTranslationFilter which is also responsible for caching the request. You can therefore write a custom AuthenticationEntryPoint which redirects to the login page URL with the additional parameter appended (containing the current request URI). The code should be almost identical to the standard implementation.

您可以使用 http 命名空间元素上的 entry-point-ref 属性将自定义 AuthenticationEntryPoint 注入命名空间配置.如果您使用普通 bean,则将其注入 ExceptionTranslationFilter.

You can inject a custom AuthenticationEntryPoint into the namespace configuration using the entry-point-ref attribute on the http namespace element. If you are using plain beans, you would inject it into the ExceptionTranslationFilter.

这篇关于使spring security在登录页面的查询字符串中添加return to url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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