Grails Spring Security - Always redirect to a specific page after login?

I have a grails application that uses spring security plugin for authentication. If my session expires and I click the link in the application, it displays me on the login screen and then tries to redirect to the page that I was on before.

I would like to configure spring security to always redirect to the home page, not the last page the user clicked on. Is there a setting that controls this behavior?

+7
spring-security grails
source share
3 answers

In addition to setting defaultTargetUrl you also need to tell Spring Security to enforce this default destination URL. Your Config.groovy should look something like this:

 grails.plugins.springsecurity.successHandler.alwaysUseDefault = true grails.plugins.springsecurity.successHandler.defaultTargetUrl = '/home' 

You can explore additional options using the Spring Security API documentation for SavedRequestAwareAuthenticationSuccessHandler if you need them.

UPDATE: In later versions of the plugin, use grails.plugin , not grails.plugins

+12
source share

I am using grails 2.4.4 and this should be:

 grails.plugin.springsecurity.successHandler.alwaysUseDefault = true grails.plugin.springsecurity.successHandler.defaultTargetUrl = '/your-url' 

Instead:

 grails.plugins.springsecurity.successHandler.alwaysUseDefault = true grails.plugins.springsecurity.successHandler.defaultTargetUrl = '/your-url' 
+6
source share

Yes, there is a successHandler.defaultTargetUrl parameter (the root context is used by default)

 grails.plugin.springsecurity.successHandler.defaultTargetUrl = '/home' 

where /home represents the route to the home page.

+1
source share

All Articles