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:

<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’/>
<a href=’${request.contextPath}/j_spring_security_exit_user’>
Resume as <sec:switchedUserOriginalUsername/>

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

~~Himanshu Seth~~


comments (2)

  1. Vivek yadav

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


Leave a Reply to Roxana Kolat Cancel reply

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