Grails Spring Security Plugin: User Switcher
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’/>&nbsp;<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
Hi,
Is it possible to return same controller and action from where admin switched as user,-when admin resume as admin.
Great article. cheers