5

CRLFログアウトエクスプロイト( https://jira.springsource.org/browse/SEC-1790 )を修正したSpring Securityバージョン3.0.6では、「spring-security-redirect」パラメーターの使用が無効になりました。

ログアウトURLのリダイレクトパラメータのデフォルトサポートも3.0.6で削除されました。3.1では、すでに明示的に有効にする必要があります。

Grails Spring Security Logout Controllerで動的にリダイレクトできるように、リダイレクトパラメーターをオンに戻す方法はありますか?

LogoutContoller.groovy

def user = springSecurityService.currentUser

if (params.redirect) {
    // this needs to log the user out and then redirect, so don't redirect until we log the user out here
    log.info "Redirecting " + springSecurityService.currentUser.username + " to " + params.redirect
    // the successHandler.targetUrlParameter is spring-security-redirect, which should redirect after successfully logging the user out
    redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl + "?spring-security-redirect="+params.redirect
    return;
}


redirect uri: SpringSecurityUtils.securityConfig.logout.filterProcessesUrl // '/j_spring_security_logout'

以下は、SpringSecurity3.0.6以降のバージョンでは機能しなくなりました

4

2 に答える 2

16

プログラムでログアウトし、コントローラーのアクションで手動リダイレクトを実行できます。

// Bean where Spring Security store logout handlers
def logoutHandlers
// logout action
def logout = {
    // Logout programmatically
        Authentication auth = SecurityContextHolder.context.authentication
    if (auth) {
        logoutHandlers.each  { handler->
            handler.logout(request,response,auth)
        }
    }
    redirect uri:params.redirect
}
于 2012-03-22T00:40:31.540 に答える
1

これはかなり専門的なトピックです。調査したソリューションは次のとおりです。

リダイレクトを削除した3.0.xコミットは次のとおりです:http://git.springsource.org/spring-security/spring-security/commit/a087e828a63edf0932e4eecf174cf816cbe6a58a

基本的な考え方は、targetUrlParameterを削除することにより、デフォルトのLogoutSuccessHandler Beanがリダイレクトを処理する機能を削除したことです(nullに設定すると、リダイレクトは発生しません)。

したがって、この問題の解決策は次のとおりです。1)targetUrlParameterをnullに設定しない単純なLogoutSuccessHandlerBeanを作成します。

/**
 * Handles the navigation on logout by delegating to the {@link AbstractAuthenticationTargetUrlRequestHandler}
 * base class logic.
 */
public class RedirectLogoutSuccessHandler extends AbstractAuthenticationTargetUrlRequestHandler
        implements LogoutSuccessHandler {

    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
            throws IOException, ServletException {
        super.handle(request, response, authentication);
    }

}

そして2)このBeanを登録しますresources.groovy

 logoutSuccessHandler(com.example.package.RedirectLogoutSuccessHandler)

また、デフォルトの動作では、ログアウトリダイレクトが発生します。

于 2011-10-26T21:43:40.503 に答える