gpt4 book ai didi

java - 使用 spring security 验证失败后重定向回原始页面

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:56:22 25 4
gpt4 key购买 nike

我正在使用 Spring 3.0 和 Spring Security。我一直使用以下配置:

    <form-login login-page="/login" authentication-failure-url="/login?error=credentials" default-target-url="/account" login-processing-url="/security_check"/>

所以当用户没有正确登录时,他们会转到/login。现在我在网站的每个页面上都有一个登录对话框。如果他们没有正确登录,我不希望他们重定向到/login.. 相反,我希望他们返回到他们所在的页面。当我看到 error=credentials 作为参数时,他们会弹出相同的对话框。

那我该怎么做呢?

最佳答案

 <!-- redirect url for failure of authentication -->
<bean id="simpleUrlAuthenticationFailureHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
<constructor-arg value="/login.jsp?error=1"></constructor-arg>
</bean>

我建议从上下文中访问对象并重置 url 或编写您自己的自定义处理程序,它可能会执行特定于您所在页面的操作

http://static.springsource.org/spring-security/site/apidocs/org/springframework/security/web/authentication/SimpleUrlAuthenticationFailureHandler.html

关于java - 使用 spring security 验证失败后重定向回原始页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3679442/

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