【发布时间】:2011-10-23 19:40:24
【问题描述】:
Grails 1.3.7 Spring-Security-Core 1.1.2
我已经实现了一个扩展 AjaxAwareAuthenticationSuccessHandler 的自定义类,以便在登录后可以将特定角色带到特定的 URL,效果很好。但是,如果会话过期,我需要能够在会话过期时将用户带到请求的 URL,覆盖基于角色的 URL。
这是我的代码的简化版本
class MyAuthSuccessHandler extends AjaxAwareAuthenticationSuccessHandler {
@Override
public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response,
final Authentication authentication) throws ServletException, IOException {
def goAdmin = false
authentication.authorities.each { ga ->
if (ga.authority.equals('ROLE_ADMIN')) {
goAdmin = true
}
}
if (goAdmin) {
response.sendRedirect(request.contextPath + '/admin/index')
}else{
super.onAuthenticationSuccess(request, response, authentication)
}
}
}
我尝试添加一个对 determineTargetUrl(request, response) 的调用,但它总是返回“/”,即使我请求了一个受保护的 /admin/foo 之类的资源。
谢谢。
【问题讨论】: