我对j_spring_security_switch_user
有疑问,因为我只能在角色为ROLE_SWITCH_USER
的用户之间切换。
我可以更改它,以便它可以切换到来自角色为ROLE_USER
的用户ROLE_SWITCH_USER
的用户吗?
答案 0 :(得分:1)
我通过以下方式解决了这个问题:
创建文件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
}
...
}