spring-boot - 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 一切都很好!
我可能错过了一些东西......类似的东西的另一个参数,但我目前停留在这一点......任何想法?
解决方案
尝试以下属性:
server.tomcat.redirect-context-root = false
来源:https ://github.com/spring-projects/spring-boot/issues/22908
推荐阅读
- reactjs - 一个
使用 react-router-dome 可能只有一个子元素。一世 - javascript - 如何将两个数组与对象进行比较以过滤相似的数组(vanilla JS)
- java - 如何计算 JTextArea 的行和列?
- python - 使用 PyCharm 读取 pyspark 中的 avro 文件
- c# - .NET Core 打开 Linux FIFO(命名)管道块执行
- python - Snakemake“X 秒后丢失文件”错误
- adobe - Adobe ExtendScript Javascript:用包含 UI 元素的函数替换字符串
- python - 即使 Python 脚本没有焦点,也可以侦听快捷方式(如 WIN+A)
- laravel - 以 laravel 为后端概念的离子
- python - 从 Mask-RCNN 中的掩码矩阵(布尔矩阵)中查找掩码角的坐标(矩形)?