1

I'm trying to configure the SwitchUser feature of the Spring Security plugin and not having success. For the most part, it seems simple and strati-forward but after getting all the code in place and clicking 'switch' button, it just redirects me to default home url without making the switch.

Does anyone have more info than what already exists on the official Spring Security Core plugin site? I've been Goggling and reading everything remotely related to it and not finding any original info -- most everything is a copy of Beckwith and Talbott's original documentation.

The following is the code for my app:

Config.groovy

grails.plugins.springsecurity.useSwitchUserFilter = true

grails.plugins.springsecurity.interceptUrlMap = [
    '/j_spring_security_switch_user': ['ROLE_SWITCH_USER', 'isFullyAuthenticated()'],
    '/j_spring_security_exit_user': ['permitAll'],
]

I'm not sure if I should use interceptUrlMap or controllerAnnotations (?), or what criteria would determine which one to use.

The .gsp code:

<sec:ifLoggedIn>
    Logged in as <sec:username/>
</sec:ifLoggedIn>

<sec:ifSwitched> 
    <a href='${request.contextPath}/j_spring_security_exit_user'> 
        Resume as <sec:switchedUserOriginalUsername/> 
    </a> 
</sec:ifSwitched>

<sec:ifNotSwitched> 
    <sec:ifAllGranted roles='ROLE_SWITCH_USER'>

        <form action='${request.contextPath}/j_spring_security_switch_user' method='POST'> 
            Switch to user: <input type='text' name='j_username'/><br/> 
            <input type='submit' value='Switch'/> 
        </form>

    </sec:ifAllGranted> 
</sec:ifNotSwitched>

I'm not aware of any other code or settings involved. Let me know if you need more info.

CheddarMonkey
  • 449
  • 5
  • 12

2 Answers2

0

It turns out, all the code for SwitchUser was implemented correctly. Although SwitchUser still doesnt behave consistently, the problem was not with the code included in the question. We had problems with the implementation of roles in Grails.

I wish I had a better answer. I would still like to know more about SwitchUser -- more than what I've found with the Googles.

CheddarMonkey
  • 449
  • 5
  • 12
0

It seems like the filter only accept switching between users with the role ROLE_SWITCH_USER

Dasma
  • 1,023
  • 13
  • 34