我正在尝试配置 Spring Security 插件的 SwitchUser 功能但没有成功。在大多数情况下,它看起来很简单而且很先进,但是在获得所有代码并单击“切换”按钮后,它只是将我重定向到默认主页 url 而无需进行切换。
有没有人拥有比官方 Spring Security Core 插件站点上已有的信息更多的信息?我一直在凝视并阅读与它远程相关的所有内容,但没有找到任何原始信息——大多数内容都是 Beckwith 和 Talbott 原始文档的副本。
以下是我的应用程序的代码:
配置文件
grails.plugins.springsecurity.useSwitchUserFilter = true
grails.plugins.springsecurity.interceptUrlMap = [
'/j_spring_security_switch_user': ['ROLE_SWITCH_USER', 'isFullyAuthenticated()'],
'/j_spring_security_exit_user': ['permitAll'],
]
我不确定是否应该使用interceptUrlMap 或controllerAnnotations(?),或者什么标准可以确定使用哪一个。
.gsp 代码:
<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>
我不知道涉及任何其他代码或设置。如果您需要更多信息,请告诉我。