gpt4 book ai didi

java - Spring Security targetUrlParameter 不重定向

转载 作者:行者123 更新时间:2023-12-04 17:36:21 24 4
gpt4 key购买 nike

我正在尝试将用户重定向回他们单击登录链接的页面。 (页面对于未经身份验证的用户是只读的,但对于登录用户是可写的。)我如何将用户重定向回他们登录后的位置?

我通过以下链接将用户发送到登录页面:/spring_security_login?redirect=/item5 .登录后,我希望用户被重定向到 /item5页。但是,它们总是被重定向到 /页。

这是我正在使用的配置:

<http use-expressions="true">
<intercept-url pattern="/**" access="permitAll" />
<form-login authentication-success-handler-ref="simpleUrlAuthenticationSuccessHandler"/>
</http>
<beans:bean id="simpleUrlAuthenticationSuccessHandler"
class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler">
<beans:property name="defaultTargetUrl" value="/"/>
<beans:property name="targetUrlParameter" value="redirect"/>
</beans:bean>

看来 targetUrlParameter没有像预期的那样被接走。我正在使用 Spring Security 3.1.4

最佳答案

使用 SimpleUrlAuthenticationSuccessHandler 时应用以下规则:

  • If the alwaysUseDefaultTargetUrl property is set to true, the defaultTargetUrl property will be used for the destination.
  • If a parameter matching the value of targetUrlParameter has been set on the request, the value will be used as the destination. By default this has the value "spring-security-redirect".
  • If the useReferer property is set, the "Referer" HTTP header value will be used, if present.
  • As a fallback option, the defaultTargetUrl value will be used.


根据您的配置,这应该可以工作。我的猜测是你没有传播 referer发送 POST 时在表单登录中请求。通常,您应该编写 referer登录页面中隐藏字段中的值,以便 referer参数传送到 spring_security_login .

关于java - Spring Security targetUrlParameter 不重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17779366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com