Reputation: 133
I have a jhipster (4.14.5) Monolithic application using Spring Boot that runs with http v2 on production and uses a certificate to force ssl. The application server uses an embedded undertow container that is created using the automatic builder (which is a standard configuration in jhipster).
Unfortunately, it does not automatically forward users on the production server who use http in their browser to https. I tried many different possible solutions to this problem including
security:
require-ssl: true
in application-prod.yml
and
http.requiresChannel().anyRequest().requiresSecure()
and.portMapper().http(80).mapsTo(443)
in the SecurityConfiguration
and
underTowContainer.addBuilderCustomizers(builder -> builder.addHttpListener(80, hostAddress));
underTowContainer.addDeploymentInfoCustomizers(deploymentInfo -> {
deploymentInfo.addSecurityConstraint(new SecurityConstraint()
.addWebResourceCollection(new WebResourceCollection().addUrlPattern("/*"))
.setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL)
.setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT))
.setConfidentialPortManager(exchange -> 443);
});
in WebConfigurer
However, no approach has worked so far. Any ideas what I could try?
Upvotes: 0
Views: 1345
Reputation: 1383
The WebFlux code below worked for me.
// Spring MVC
http.requiresChannel(channel -> channel
.requestMatchers(r -> r.getHeader("X-Forwarded-Proto") != null).requiresSecure());
// WebFlux
http.redirectToHttps(redirect -> redirect
.httpsRedirectWhen(e -> e.getRequest().getHeaders().containsKey("X-Forwarded-Proto")));
Reference: https://www.jhipster.tech/security/
Upvotes: 1
Reputation: 9
do you use some proxy like nginx or something like a load balancer? i would suggest using it for https forwarding.
Upvotes: 0