5

在修复了 CRLF 注销漏洞 ( https://jira.springsource.org/browse/SEC-1790 )的 spring security 版本 3.0.6 中,他们禁用了“spring-security-redirect”参数的使用。

3.0.6 中也删除了对注销 URL 中重定向参数的默认支持。在 3.1 中,它已经需要显式启用。

有没有办法重新打开重定向参数,以便我可以在我的 Grails Spring Security Logout Controller 中动态重定向?

注销控制器.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'

以下不再适用于 spring security 3.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 的简单 LogoutSuccessHandler bean:

/**
 * 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 回答