2011-10-21 26 views
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哪些是受保護的。

謝謝。

回答

0

請求

super.determineTargetUrl(request, response); 

應該工作,如果你使用SavedRequestAwareAuthenticationSuccessHandler作爲超類。我不確定是否可以在您的場景中切換到此課程。也許這可以幫助,但我想你完全知道它:http://omarello.com/2011/09/grails-custom-target-urls-after-login/

+0

然而,它並沒有。 SavedRequestAwareAuthenticationSuccessHandler是AjaxAware的超類......這種方法實際上被埋在了抽象超類中,無論如何這個抽象超類大約有4級。所以,只要它是其中之一,我就延伸到哪一類就不重要了。 – Gregg