Spring Security - 在重定向到登录时保留URL参数 [英] Spring Security - Retaining URL parameters on redirect to login

查看:306
本文介绍了Spring Security - 在重定向到登录时保留URL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好。

假设我有一个安全的网址格式

lets say I have a secure url pattern

/secure/link-profile

可选择附加网址参数。

/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



<基本前提是我们提供与第三方的奖励整合,第三方会将用户发送给我们。他们将被带到一个页面,将他们的第三方帐户/个人资料与他们/我们的网站用户联系起来。但是,如果他们没有我们的现有帐户,那么在登录页面上,他们将进入注册页面,然后我们希望预先填充第三方传递给我们的一些细节。

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.RELEASE
spring framework 3.1.1.RELEASE

spring security 2.0.7.RELEASE spring framework 3.1.1.RELEASE

推荐答案

请参阅 buildRedirectUrlToLoginPage(HttpServletRequest request,...)中的方法 LoginUrlAuthenticationEntryPoint

如果我理解你想要实现的目标,我认为应该足以覆盖这个方法子类,复制原始方法,但在构建URL时另外调用
urlBuilder.setQuery(request.getQueryString())

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屋!

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