简体   繁体   English

发布与 HTTPS 一起运行的 Spring(非引导)应用程序

[英]Release a Spring (not boot) application running with HTTPS

I try a SAML connection to Azure B2C with a Spring application found on GitHub.我尝试使用 GitHub 上的Spring 应用程序与 Azure B2C 建立 SAML 连接。 Every works fine until I run in local, but when I need to test this application in a production eviroment I found myself up against problems due to HTTPS connection.一切正常,直到我在本地运行,但是当我需要在生产环境中测试这个应用程序时,我发现自己遇到了由于 HTTPS 连接而出现的问题。

My production enviroment is based on AWS, I'm running a ECS Tasks configured in reverse proxy.我的生产环境基于 AWS,我正在运行在反向代理中配置的 ECS 任务。 I'm using an Load Balancer with an HTTPS listener and an HTTP rule to redirect on HTTPS.我正在使用带有 HTTPS 侦听器和 HTTP 规则的负载均衡器来重定向 HTTPS。

This application is based on Spring, (not Spring Boot) and builds a WAR file that I run on a Tomcat 7.此应用程序基于 Spring(不是 Spring 引导)并构建我在 Tomcat 7 上运行的 WAR 文件。

When I try the login, this application try an HTTP request that the ALB redirect to HTTPS, but this redirect invalidate my SAML workflow.当我尝试登录时,此应用程序会尝试 HTTP 请求,该请求将 ALB 重定向到 HTTPS,但此重定向使我的 SAML 工作流程无效。

I try to add requires-channel="https" to any <security:intercept-url /> node in my securityContext.xml but when I try to access to the application online I've got a ERR_TOO_MANY_REDIRECTS我尝试将requires-channel="https"添加到我的 securityContext.xml 中的任何<security:intercept-url />节点,但是当我尝试在线访问应用程序时,我得到了 ERR_TOO_MANY_REDIRECTS

I need to configure tomcat and this application to request only HTTPS without the needs of any redirects but I don't now how我需要配置 tomcat 和此应用程序以仅请求 HTTPS 而无需任何重定向,但我现在不知道如何

I finnaly found a solution in two steps.我最终分两步找到了解决方案。

First step: I modify my Tomcat configuration to works only in https.第一步:我将我的 Tomcat 配置修改为仅适用于 https。

In server.xml I added a connector to works with TLS在 server.xml 我添加了一个连接器来使用 TLS

<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true" 
           maxThreads="150" scheme="https" secure="true"
           clientAuth="false" sslProtocol="TLS"
           keystoreFile="conf/keystore.keystore"
           keystoreType="JKS"
           keystorePass="myStorePass"
           keyPass="myPass" />

And then I removed redirect of 8080 to 443. Find the node Connector with protocol="HTTP/1.1" and remove it.然后我删除了 8080 到 443 的重定向。找到带有protocol="HTTP/1.1"的节点连接器并将其删除。

Second step: I modify Load Balancer to works only in HTTS with 443 port.第二步:我将负载均衡器修改为仅在具有 443 端口的 HTTS 中工作。 To do this I had to create a new target group and a new service on my cluster.为此,我必须在集群上创建一个新目标组和一个新服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM