首页 > 解决方案 > Spring Boot 2.3.2 server.forward-headers-strategy=framework 重定向到方案 http 而不是 https

问题描述

我目前正在将使用 Spring Boot 2.0.x 的旧应用程序迁移到更新的 Spring Boot 2.3.x 版本。该应用程序部署在反向代理 (apache) 后面的 OpenShift 上,以处理 SSL 证书。

该应用程序使用 openid-connect 系统对用户进行身份验证。基本上,openid-connect 服务器将用户重定向到 /login(通过 redirect-uri),然后,通过 Spring 类 SavedRequestAwareAuthenticationSuccessHandler 的自定义实现及其方法“onAuthenticationSuccess”,我们通过默认重定向策略将用户重定向到 /profile。

@Slf4j
@RequiredArgsConstructor
@Component
public class AuthenticationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

    private final RedirectStrategy redirectStrategy;


    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {
        // We do some stuff here...
        log.debug("Redirecting to /profile");
        log.debug("request.getScheme() = " + request.getScheme());
        log.debug("request.getContextPath() = " + request.getContextPath());
        log.debug("request.getRequestURI() = " + request.getRequestURI());
        log.debug("request.getRequestURL() = " + request.getRequestURL().toString());
        log.debug("request.getServletPath() = " + request.getServletPath());
        redirectStrategy.sendRedirect(request, response, "/profile");
    }

}

使用 Spring Boot 2.0.x 版,没问题,一切正常。迁移到 Spring Boot 2.3.x 版本后,用户被重定向到 http:// INTERNAL_OPENSHIFT_HOST /ourApp/profile

我发现自 Spring Boot 2.2 以来引入的“新”参数称为server.forward-headers-strategy。如果我将值设置为“框架”,则重定向到http ://REVERSE_PROXY_HOST/ourApp/profile

好吧......我不知道为什么使用 http 而不是 https!我想一切都在反向代理端正确设置,因为 Spring Boot 2.0.x 一切都很好!

我可能错过了一些东西......类似的东西的另一个参数,但我目前停留在这一点......任何想法?

标签: spring-bootspring-securityopenid-connect

解决方案


尝试以下属性:

server.tomcat.redirect-context-root = false

来源:https ://github.com/spring-projects/spring-boot/issues/22908


推荐阅读