spring-security - 使spring security在登录页面的查询字符串中添加return to url

标签 spring-security

早些时候我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"

...到您的 元素并添加一个如下所示的 bean:
<!-- 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/

相关文章:

spring-security - 使用 Spring Security Saml 和 SP 应用程序的无状态 session

java - Spring Security 默认使用的 AuthenticationProvider 和 UserDetailsS​​ervice

java - 为什么在 https 中要加上 Spring Security 的 80 端口?

java - 'UserDetailsService' 类型的 bean 不止一个。 bean 类 : inMemoryUserDetailsManager

grails - 执行脚本CreateAuthDomains时出错:null\scripts\Init.groovy(系统找不到指定的路径)

Grails Acegi : Redirection on a ajax method and not on the webpage. 为什么?

java - SessionInformation 过期不会导致用户从系统注销

spring-security - 在 Spring Security 过滤器链之前执行 servlet 过滤器

java - 在微服务之间共享用户 ID 的最佳实践是什么?

java - 添加 Spring Security 后,我的 spring 应用程序停止运行