2010-09-09 80 views
8

我正在使用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"/> 

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

那么我该如何做到这一点?

回答

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

+2

嗯页面自定义的处理程序,长相就像我可以在SimpleUrlAuthenticationFailureHandler上设置RedirectStrategy属性一样。 RedirectStrategy看起来像一个简单的接口来实现我可以调用response.sendRedirect(request.getHeader(“Referer”));这是处理这种情况的正确方法吗? – 2010-09-10 12:14:08

+0

@它怎么样?您是否编写了自己的SimpleUrlAuthenticationFailureHandler?你有没有找到关于这方面的任何好的信息,或者你介意提供一些你的代码?我一直在寻找一段时间,但很难找到任何东西。 – nilsi 2013-09-24 15:54:37

相关问题