0
Grails的1.3.7 彈簧安全核心1.1.2擴展AjaxAwareAuthenticationSuccessHandler,記住目標URL
,我實現了擴展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呼叫(請求,響應),但它總是返回「/」即使我所請求的資源像/管理/ foo哪些是受保護的。
謝謝。
然而,它並沒有。 SavedRequestAwareAuthenticationSuccessHandler是AjaxAware的超類......這種方法實際上被埋在了抽象超類中,無論如何這個抽象超類大約有4級。所以,只要它是其中之一,我就延伸到哪一類就不重要了。 – Gregg