Grails Spring Security Plugin: User Switcher

14 / Nov / 2011 by Himanshu Seth 2 comments

If you are using Grails Spring Security in your application, one killer functionality that we can easily provide is a simple user switcher
Add this to your admin layout:

[html]
<sec:ifAllGranted roles=’ROLE_ADMIN’>
<form action=’/j_spring_security_switch_user’ method=’POST’>
Switch: <g:select from="${users}" optionKey="username" optionValue="displayInfo"
name=’j_username’/> <input type=’submit’ value=’Switch’/>
</form>
</sec:ifAllGranted>
<sec:ifSwitched>
<a href=’${request.contextPath}/j_spring_security_exit_user’>
Resume as <sec:switchedUserOriginalUsername/>
</a>
</sec:ifSwitched>
[/html]

In Config.groovy, add the following:

[groovy]grails.plugins.springsecurity.useSwitchUserFilter = true[/groovy]

So, in two easy steps we can provide the application admin to impersonate other users. This also checks if the current user is actually an impersonation and if it is, it provides a link to go back to the original user.

Very neat indeed 🙂

More detailed info available here

Regards
~~Himanshu Seth~~

http://www.tothenew.com

FOUND THIS USEFUL? SHARE IT

comments (2)

  1. Vivek yadav

    Hi,
    Is it possible to return same controller and action from where admin switched as user,-when admin resume as admin.

    Reply

Leave a Reply to Vivek yadav Cancel reply

Your email address will not be published. Required fields are marked *