【发布时间】:2021-06-07 03:42:45
【问题描述】:
我目前正在将使用 Spring Boot 2.0.x 的旧应用程序迁移到更新的 Spring Boot 2.3.x 版本。 该应用程序部署在 OpenShift 上,位于反向代理 (apache) 后面以处理 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。 如果我将值设置为“framework”,则重定向到 http://REVERSE_PROXY_HOST/ourApp/profile
嗯...我不知道为什么使用http而不是https!我想一切都在反向代理端正确设置,因为 Spring Boot 2.0.x 一切都很好!
我可能错过了一些东西......类似的东西的另一个参数,但我目前停留在这一点...... 有什么想法吗?
【问题讨论】:
-
这是在外部tomcat环境还是嵌入式tomcat?
标签: spring-boot spring-security openid-connect