views:

130

answers:

1

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?

+1  A: 
 <!-- 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

Aaron Saunders
hmm, looks like I can set a RedirectStrategy property on the SimpleUrlAuthenticationFailureHandler. RedirectStrategy looks like a simple interface to implement where I can call response.sendRedirect(request.getHeader("Referer")); Is this the proper way to handle this situation?
at