Switch User in Spring Security Grails

Posted By : Shashikant Sharma | 02-Dec-2013

In this Blog I am going to share how to use switch user feature of spring security in Grails.I am assuming that spring security core plugin is installed in your application.If not installed please follow this link  

 

when I am writing this blog the current version of Spring security is spring-security-core:2.0-RC2

1.Changes in Config.groovy

a.)To enable a user to switch from the current Authentication to another user's, set the useSwitchUserFilter attribute to true.          

grails.plugin.springsecurity.useSwitchUserFilter = true

 

For using Switch user feature you should have a role ‘ROLE_SWITCH_USER’

b.)If you use annotations, add a rule to the controllerAnnotations.staticRules attribute:

 
grails.plugin.springsecurity.controllerAnnotations.staticRules=[
    '/j_spring_security_switch_user':['ROLE_SWITCH_USER', 'IS_AUTHENTICATED_FULLY' ],
    '/j_spring_security_exit_user': ['permitAll'],
]

2.To switch to another user, create a form that submits to /j_spring_security_switch_user:

 
Switch to user:  

This code will enable a Switch button on gsp.

3.To resume as the original user, create a form that submits to /j_spring_security_exit_user.


 

4.You can also customized your URL in Config.groovy that are used for this feature, although it is rarely used:

grails.plugin.springsecurity.switchUser.switchUserUrl = …
grails.plugin.springsecurity.switchUser.exitUserUrl = …
grails.plugin.springsecurity.switchUser.targetUrl = …
grails.plugin.springsecurity.switchUser.switchFailureUrl = …

This is all about spring security switch user feature.for more information stay tuned on www.oodlestechnologies.com .

Thaks

Shashikant Sharma

 

 

About Author

Author Image
Shashikant Sharma

Shashikant is a bright java developer and have worked on development of various SaaS applications using Grails technologies. ShashiKant like watching movies and playing cricket in his free time

Request for Proposal

Name is required

Comment is required

Sending message..