早些时候我asked如果有可能在 Spring Security 2 的表单登录页面中获取原始请求 url。事实证明这实际上对我没有帮助,我需要的是重定向到表单登录页面以将其嵌入其中一个请求参数。所以如果我有:
<form-login login-page="/login.html" />
并尝试访问
/secure.html
我想在 /login.html?return_to=/secure.html
结束.
最佳答案
我猜你需要使用 spring-security-redirect .基本上,如果您的 url 是形式 /login.html?spring-security-redirect=/secure.html
, spring security 将在成功登录后自动重定向到 secure.html。
从 spring 3.1.x 开始,这不再是开箱即用的。您需要添加:
authentication-success-handler-ref="simpleUrlAuthenticationSuccessHandler"
...到您的
<!-- Emulates the functionality of spring security 3.0.x by specifying the targetUrlParameter to be the value it
defaulted to in 3.0.x. As of 3.1.x this is null by default with no option to specify in <form-login> -->
<beans:bean id="simpleUrlAuthenticationSuccessHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler">
<beans:property name="useReferer" value="true"/>
<beans:property name="defaultTargetUrl" value="/account"/>
<beans:property name="targetUrlParameter" value="spring-security-redirect"/>
</beans:bean>
关于spring-security - 使spring security在登录页面的查询字符串中添加return to url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4696905/