0

我有问题j_spring_security_switch_user,因为我只能在具有该角色的用户之间切换ROLE_SWITCH_USER

我可以更改它,以便它可以ROLE_USER从具有角色的用户切换到用户ROLE_SWITCH_USER吗?

4

1 回答 1

1

我通过以下方式修复了它:

创建文件 MySwichUserFilter.groovy:

class MySwichUserFilter extends SwitchUserFilter {

    protected Authentication attemptSwitchUser(HttpServletRequest request) throws AuthenticationException {

        Authentication switchTo = super.attemptSwitchUser(request);
        SecurityContextHolder.getContext().getAuthentication();

        return switchTo;
    }
}

更正资源.groovy

beans = {
    ...
    switchUserProcessingFilter(MySwichUserFilter){
        userDetailsService  = ref('userDetailsService')
        switchUserUrl       = "/j_spring_security_switch_user"
        exitUserUrl         = "/j_spring_security_exit_user"
        targetUrl           = conf.successHandler.defaultTargetUrl
    }
    ...
}
于 2015-10-05T06:33:42.037 回答