Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redirecting back to original page after authentication failure with spring security

I'm using Spring 3.0 along with Spring Security. I've always used the following configuration:

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

So when the user doesn't login correctly, they go to /login. Now I have a login dialog on every page of the site. If they don't login correctly, I don't want them redirecting to /login.. instead I want them returning to the page they are at. I'll them popup that same dialog when I see the error=credentials as a parameter.

So how do I do this?

like image 493
at. Avatar asked Sep 09 '10 18:09

at.


1 Answers

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

I would suggest getting access to the object from the context and resetting the url OR writing your own custom handler which might perform actions specific to the page you are on

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

like image 119
Aaron Saunders Avatar answered Sep 23 '22 13:09

Aaron Saunders