{"id":4487,"date":"2011-11-14T12:07:47","date_gmt":"2011-11-14T06:37:47","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=4487"},"modified":"2016-12-19T15:19:23","modified_gmt":"2016-12-19T09:49:23","slug":"grails-spring-security-plugin-user-swticher","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/grails-spring-security-plugin-user-swticher\/","title":{"rendered":"Grails Spring Security Plugin: User Switcher"},"content":{"rendered":"<p>If you are using Grails Spring Security in your application, one killer functionality that we can easily provide is a simple user switcher<br \/>\nAdd this to your admin layout:<\/p>\n<p>[html]<br \/>\n&amp;lt;sec:ifAllGranted roles=&#8217;ROLE_ADMIN&#8217;&amp;gt;<br \/>\n    &amp;lt;form action=&#8217;\/j_spring_security_switch_user&#8217; method=&#8217;POST&#8217;&amp;gt;<br \/>\n        Switch: &amp;lt;g:select from=&amp;quot;${users}&amp;quot; optionKey=&amp;quot;username&amp;quot; optionValue=&amp;quot;displayInfo&amp;quot;<br \/>\n                          name=&#8217;j_username&#8217;\/&amp;gt;&amp;amp;nbsp;&amp;lt;input type=&#8217;submit&#8217; value=&#8217;Switch&#8217;\/&amp;gt;<br \/>\n    &amp;lt;\/form&amp;gt;<br \/>\n&amp;lt;\/sec:ifAllGranted&amp;gt;<br \/>\n&amp;lt;sec:ifSwitched&amp;gt;<br \/>\n    &amp;lt;a href=&#8217;${request.contextPath}\/j_spring_security_exit_user&#8217;&amp;gt;<br \/>\n        Resume as &amp;lt;sec:switchedUserOriginalUsername\/&amp;gt;<br \/>\n    &amp;lt;\/a&amp;gt;<br \/>\n&amp;lt;\/sec:ifSwitched&amp;gt;<br \/>\n[\/html]<\/p>\n<p>In Config.groovy, add the following:<\/p>\n<p>[groovy]grails.plugins.springsecurity.useSwitchUserFilter = true[\/groovy]<\/p>\n<p>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.<\/p>\n<p>Very neat indeed \ud83d\ude42<\/p>\n<p>More detailed info available here<\/p>\n<p>Regards<br \/>\n~~Himanshu Seth~~<\/p>\n<p>http:\/\/www.tothenew.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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] &amp;lt;sec:ifAllGranted roles=&#8217;ROLE_ADMIN&#8217;&amp;gt; &amp;lt;form action=&#8217;\/j_spring_security_switch_user&#8217; method=&#8217;POST&#8217;&amp;gt; Switch: &amp;lt;g:select from=&amp;quot;${users}&amp;quot; optionKey=&amp;quot;username&amp;quot; optionValue=&amp;quot;displayInfo&amp;quot; name=&#8217;j_username&#8217;\/&amp;gt;&amp;amp;nbsp;&amp;lt;input type=&#8217;submit&#8217; value=&#8217;Switch&#8217;\/&amp;gt; &amp;lt;\/form&amp;gt; &amp;lt;\/sec:ifAllGranted&amp;gt; &amp;lt;sec:ifSwitched&amp;gt; &amp;lt;a href=&#8217;${request.contextPath}\/j_spring_security_exit_user&#8217;&amp;gt; Resume as &amp;lt;sec:switchedUserOriginalUsername\/&amp;gt; &amp;lt;\/a&amp;gt; &amp;lt;\/sec:ifSwitched&amp;gt; [\/html] In [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[7],"tags":[4840,672,673],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4487"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=4487"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/4487\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=4487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=4487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=4487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}