Spring Security - 在重定向到登录时保留 URL 参数 [英] Spring Security - Retaining URL parameters on redirect to login
问题描述
好的.
假设我有一个安全的网址模式
lets say I have a secure url pattern
/secure/link-profile
可选地,可以附加 url 参数.
optionally, there can be url paramaters appended.
/secure/link-profile?firstName=Bob&secondName=Smith&membershipNumber=1234
如何才能将这些 url 参数传递到登录页面?
how can I make it so that those url params are carried over to the login page?
/login?firstName=Bob&secondName=Smith&membershipNumber=1234
基本前提是我们提供与第三方的奖励集成,第三方会将他们的用户发送给我们.他们将被带到一个页面,将他们的第 3 方帐户/个人资料与他们/我们的网站用户相关联.但是,如果他们没有我们的现有帐户,则在登录页面上,他们将转到注册页面,然后我们希望预先填充第 3 方传递给我们的一些详细信息.
the basic premise is that we offer rewards integration with a 3rd party, who will send their users to us. They will be taken to a page to link their 3rd party account/profile with their/our website user. If however, they dont have an existing account with us, then on the login page, they will go to the signup page, and we would then like to prepopulate some of their details that the 3rd party has passed on to us.
提前致谢
spring security 2.0.7.RELEASEspring 框架 3.1.1.RELEASE
spring security 2.0.7.RELEASE spring framework 3.1.1.RELEASE
推荐答案
查看LoginUrlAuthenticationEntryPoint
中的方法buildRedirectUrlToLoginPage(HttpServletRequest request, ...)
.
如果我正确理解你想要实现的目标,我认为在子类中覆盖这个方法应该就足够了,复制原始方法,但另外调用 urlBuilder.setQuery(request.getQueryString())
构建 url 时.
If I understood correctly what you want to achieve, I think it should be enough to override this method in a sublclass, copy the original method, but additionally call
urlBuilder.setQuery(request.getQueryString())
when it builds the url.
然后你只需要用这个自定义的入口点配置ExceptionTranslationFilter
.
Then you only need to configure the ExceptionTranslationFilter
with this customized entry point.
这篇关于Spring Security - 在重定向到登录时保留 URL 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!