0

I have problem with j_spring_security_switch_user, as I only can switch between users with the role ROLE_SWITCH_USER.

Can I change it so it can switch to users with the ROLE_USER from a user with the role ROLE_SWITCH_USER?

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
Dasma
  • 1,023
  • 13
  • 34
  • If I'm understanding your question correct then you want to switch to only those users who have `ROLE_USER` role? – Shashank Agrawal Oct 03 '15 at 14:02
  • Yes, but I want to keep the permission rule for switching user, so it's only can be done from ROLE_SWITCH_USER – Dasma Oct 03 '15 at 15:15

1 Answers1

1

I got it fixed by:

Create file MySwichUserFilter.groovy:

class MySwichUserFilter extends SwitchUserFilter {

    protected Authentication attemptSwitchUser(HttpServletRequest request) throws AuthenticationException {

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

        return switchTo;
    }
}

Correct the resources.groovy

beans = {
    ...
    switchUserProcessingFilter(MySwichUserFilter){
        userDetailsService  = ref('userDetailsService')
        switchUserUrl       = "/j_spring_security_switch_user"
        exitUserUrl         = "/j_spring_security_exit_user"
        targetUrl           = conf.successHandler.defaultTargetUrl
    }
    ...
}
Dasma
  • 1,023
  • 13
  • 34