How to prevent spring from being redirected to the previous page after a successful login?

We are using Spring Security 2.0.7: = (in our application.

Spring Security implements the following function: when there is no access to the user's X access page, the following occurs:

  • User redirected to login page
  • After a successful login, the user is redirected to page X instead of the purpose of the login form.

In my application, for reasons beyond my control, this is not the desired behavior. We want to land on the landing page of the login form, regardless of which page the user tried to get.

Q: Can I disable this Spring Security feature and how?

I suppose that one of the filters in the standard filter chain does this, but I could not determine which one.

+3
source share
2 answers

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

The default value falsealso leads to the description that 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" />
+6
source

For annotation-based settings, use the following: .defaultSuccessUrl ("/ panel", true )

The second logical parameter sets the value to always-use-default-target.

0
source

All Articles