Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent spring security from redirecting to the previous page after successful login?

We use Spring Security 2.0.7 :=( in our application.

Spring Security implements the following feature: when an unauthenticated user access page X, the following happens:

  • User is redirected to login page
  • Upon successful login, the user is redirected to page X instead of the target of the login form.

In my application, for reasons beyond my control, this is not the desired behavior. We want to land on the target page of the login form no matter what the page that the user tried to access.

Q: Is it possible to disable this feature of Spring Security and how ?

I suppose one of the filters of the standard filter chain is doing this, but I could not identify which.

like image 556
Samuel Rossille Avatar asked Feb 25 '14 10:02

Samuel Rossille


People also ask

How do I restrict URL in Spring Security?

Securing the URLs The most common methods are: authenticated(): This is the URL you want to protect, and requires the user to login. permitAll(): This is used for URL's with no security applied for example css, javascript. hasRole(String role): Restrict to single role.

How do I redirect back to original URL after successful login in laravel?

You can apply this filter to the routes that need authentication. Route::filter('auth', function() { if (Auth::guest()) { return Redirect::guest('login'); } }); What this method basically does it's to store the page you were trying to visit and it is redirects you to the login page. return Redirect::intended();


1 Answers

Try modifying always-use-default-target="true" in the of your Spring Security Configuration xml file.

The default value is false, and leads to the behavior you describe.

Example:

<form-login 
    login-page="/login.html"
    authentication-failure-url="/login.html?status=LOGIN_FAILURE"
    default-target-url="/index.html"
    always-use-default-target="true" />
like image 52
Sandhu Santhakumar Avatar answered Sep 28 '22 00:09

Sandhu Santhakumar