Grails弹簧开关用户

时间:2015-10-03 11:18:57

标签: grails spring-security grails-2.4

我对j_spring_security_switch_user有疑问,因为我只能在角色为ROLE_SWITCH_USER的用户之间切换。

我可以更改它,以便它可以切换到来自角色为ROLE_USER的用户ROLE_SWITCH_USER的用户吗?

1 个答案:

答案 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
    }
    ...
}