Grails spring 切换用户
Grails spring switch user
我对 j_spring_security_switch_user
有疑问,因为我只能在角色 ROLE_SWITCH_USER
的用户之间切换。
我可以更改它以便它可以从具有 ROLE_SWITCH_USER
角色的用户切换到具有 ROLE_USER
的用户吗?
我通过以下方式修复了它:
创建文件MySwichUserFilter.groovy:
class MySwichUserFilter extends SwitchUserFilter {
protected Authentication attemptSwitchUser(HttpServletRequest request) throws AuthenticationException {
Authentication switchTo = super.attemptSwitchUser(request);
SecurityContextHolder.getContext().getAuthentication();
return switchTo;
}
}
更正 resources.groovy
beans = {
...
switchUserProcessingFilter(MySwichUserFilter){
userDetailsService = ref('userDetailsService')
switchUserUrl = "/j_spring_security_switch_user"
exitUserUrl = "/j_spring_security_exit_user"
targetUrl = conf.successHandler.defaultTargetUrl
}
...
}
我对 j_spring_security_switch_user
有疑问,因为我只能在角色 ROLE_SWITCH_USER
的用户之间切换。
我可以更改它以便它可以从具有 ROLE_SWITCH_USER
角色的用户切换到具有 ROLE_USER
的用户吗?
我通过以下方式修复了它:
创建文件MySwichUserFilter.groovy:
class MySwichUserFilter extends SwitchUserFilter {
protected Authentication attemptSwitchUser(HttpServletRequest request) throws AuthenticationException {
Authentication switchTo = super.attemptSwitchUser(request);
SecurityContextHolder.getContext().getAuthentication();
return switchTo;
}
}
更正 resources.groovy
beans = {
...
switchUserProcessingFilter(MySwichUserFilter){
userDetailsService = ref('userDetailsService')
switchUserUrl = "/j_spring_security_switch_user"
exitUserUrl = "/j_spring_security_exit_user"
targetUrl = conf.successHandler.defaultTargetUrl
}
...
}