2

I am trying to implement a login system such that the user is redirected back to the original request url. For example, if a user tries to access url '/books/list' (which requires login to access) then the user should be redirect to login page and after login, the user should be redirected to '/books/list', the original requested url. How do I do this ? My login controller looks like :

def index = { if (springSecurityService.isLoggedIn()) { redirect action: 'dashboard' //redirect uri: SpringSecurityUtils.securityConfig.login.filterProcessesUrl } else { redirect action: auth, params: params } } def auth = { def config = SpringSecurityUtils.securityConfig if (springSecurityService.isLoggedIn()) { redirect uri: config.successHandler.defaultTargetUrl return } String view = 'auth' String postUrl = "${request.contextPath}${config.apf.filterProcessesUrl}" render view: view, model: [postUrl: postUrl, rememberMeParameter: config.rememberMe.parameter] } 

2 Answers 2

1

The Spring Security Core plugin does this by default.

Sign up to request clarification or add additional context in comments.

1 Comment

Right, this is core Spring Security functionality.
1

Redirecting to the requested url after sign in , you just need to add the following in your config.groovy file.

grails.plugins.springsecurity.successHandler.alwaysUseDefaultTargetUrl = false grails.plugins.springsecurity.securityConfigType = "InterceptUrlMap" grails.plugins.springsecurity.interceptUrlMap = [ '/**': ["IS_AUTHENTICATED_FULLY"] ] 

1 Comment

I think we need to add one line grails.plugins.springsecurity.successHandler.alwaysUseDefaultTargetUrl = false into Config.groovy

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.