I'm running a Spring boot (Jhipster/Undertow) application on port 8080 on an AWS EC2 instance.
I have an AWS ELB configured to redirect
80 -> 8080
443 (SSL termination happens here) -> 8080
The application uses Spring Security and if you user arrives to http://example.com I want it to redirect to https://example.com, to use SSL.
I have found various examples of configuring this in Tomcat but none using Undertow.
I have tried this, with a second port 8089, and it does redirect as required, but this causes port 8080 to also redirects which I don't want.
80 -> 8089
443 (SSL termination happens here) -> 8080
@Bean
public EmbeddedServletContainerFactory undertow() {
UndertowEmbeddedServletContainerFactory undertow = new UndertowEmbeddedServletContainerFactory();
undertow.addBuilderCustomizers(builder -> builder.addHttpListener(8089, "0.0.0.0"));
undertow.addDeploymentInfoCustomizers(deploymentInfo -> {
deploymentInfo.addSecurityConstraint(new SecurityConstraint()
.addWebResourceCollection(new WebResourceCollection()
.addUrlPattern("/*"))
.setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL)
.setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT))
.setConfidentialPortManager(exchange -> 443);
});
return undertow;
}
How can I configure Undertow to achieve this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…