Spring Security Login Redirection

The redirection after logged in can be controlled in application.groovy by adding the URL-related properties there. For more details, go see the chapter URL Properties in the Grails Spring Security Core Plugin Documentation.

The following example redirect to / after logged in.

grails.plugin.springsecurity.syccessHandler.defaultTargetUrl = "/"
grails.plugin.springsecurity.syccessHandler.alwaysUseDefault= true

For some page that required user to be logged in before it is able to access, it will redirect user to the login page. After user logged in, we might want the user to redirect that originally-requested page. (This is actually the default behavior of Grails Spring Security Plugin 3.2.3)

grails.plugin.springsecurity.syccessHandler.alwaysUseDefault= false

The following example redirect to /home/fail after login failed.

grails.plugin.springsecurity.failureHandler.defaultFailureUrl = "/home/fail"

The following example redirect to /home/logout after logged in.

grails.plugin.springsecurity.logout.afterLogoutUrl = "/home/logout"
  • grails/spring_security_login_redirection.txt
  • Last modified: 2019/09/10 09:56
  • by chongtin