Reputation: 1647
I'm using grails spring-security-core and spring-security-ui plugins, but no matter what I do, I can't get switch user to work, I always get:
Error: Page Not Found (404) Path: /login/impersonate
I've got this in my application.groovy:
grails.plugin.springsecurity.controllerAnnotations.staticRules = [
......
[pattern: '/login/**', access: ['permitAll']],
[pattern: '/logout/**', access: ['permitAll']],
[pattern: '/login/impersonate', access: ['permitAll']],
[pattern: '/logout/impersonate', access: ['permitAll']]
}
(Very open permissions I know, but just trying to get it working.) I've tried to add this also:
grails.plugin.springsecurity.interceptUrlMap = [
[pattern: '/login/impersonate', access: ['permitAll']]
]
I've got this set in application.groovy:
grails.plugin.springsecurity.switchUser.useSwitchUserFilter = true
grails.plugin.springsecurity.ui.switchUserRoleName = 'ROLE_SWITCH_USER'
and to be doubly sure I put this in my application.yml:
grails:
plugin:
springsecurity:
switchUser:
useSwitchUserFilter: true
ui:
switchUserRoleName: 'ROLE_SWITCH_USER'
I've tried logging in with a user with roles ROLE_ADMIN as well as ROLE_SWITCH_USER and clicking the standard "Login as user" found in the spring-security-ui gui plugin. I've tried just going to http://localhost:8080/login/impersonate in the browser. I've tried adding this to a page:
<sec:ifAllGranted roles='ROLE_SWITCH_USER'>
<form action='/login/impersonate' method='POST'>
Switch to user: <input type='text' name='username'/> <br/>
<input type='submit' value='Switch'/>
</form>
</sec:ifAllGranted>
and trying to switch users that way. But no matter what I do, I get page not found 404.
I tried looking at the source code to spring-security-core plugin, but the LoginController.groovy doesn't have an impersonate() method. I'm guessing it uses some magic to arrive at Spring's SwitchUserFilter. I've tried putting break points in there, but it didn't seem to stop.
In all other respects, grails spring security plugin seems to be working fine and as expected. But I'm stumped.
Using grails 4.0.9, org.grails.plugins:spring-security-core:4.0.3, org.grails.plugins:spring-security-ui:4.0.0.M1
Upvotes: 3
Views: 423
Reputation: 2219
I upgraded from Grails 3 to 5 and leaving an impersonate session was causing a 404. I found this https://github.com/404labfr/laravel-impersonate/issues/134 changng my link to
<sec:ifSwitched>
<form method="post" action="${request.contextPath}/logout/impersonate">
<button class="btn btn-link" type="submit">
Resume as <sec:switchedUserOriginalUsername/>
</button>
</form>
</sec:ifSwitched>
Upvotes: 0
Reputation: 21
Try to use:
grails.plugin.springsecurity.useSwitchUserFilter = true
not:
grails.plugin.springsecurity.switchUser.useSwitchUserFilter = true
Upvotes: 2