commit bbd110ae388d4ecc566978a658e59056ba2330b6 parent f23f9c04965094db2ef2e1460f3d564ca25a0e31 Author: WimDupont <WimDupont@users.noreply.gitlab.com> Date: Fri, 3 Sep 2021 22:50:48 +0200 revert http redirect removal Diffstat:
A | src/main/java/com/wimdupont/personalweb/config/ServerConfig.java | | | 41 | +++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 41 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/wimdupont/personalweb/config/ServerConfig.java b/src/main/java/com/wimdupont/personalweb/config/ServerConfig.java @@ -0,0 +1,41 @@ +package com.wimdupont.personalweb.config; + +import org.apache.catalina.Context; +import org.apache.catalina.connector.Connector; +import org.apache.tomcat.util.descriptor.web.SecurityCollection; +import org.apache.tomcat.util.descriptor.web.SecurityConstraint; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ServletWebServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@SuppressWarnings("unused") +public class ServerConfig { + + @Bean + public ServletWebServerFactory servletContainer() { + TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() { + @Override + protected void postProcessContext(Context context) { + SecurityConstraint securityConstraint = new SecurityConstraint(); + securityConstraint.setUserConstraint("CONFIDENTIAL"); + SecurityCollection collection = new SecurityCollection(); + collection.addPattern("/*"); + securityConstraint.addCollection(collection); + context.addConstraint(securityConstraint); + } + }; + tomcat.addAdditionalTomcatConnectors(getHttpConnector()); + return tomcat; + } + + private Connector getHttpConnector() { + Connector connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL); + connector.setScheme("http"); + connector.setPort(8081); + connector.setSecure(false); + connector.setRedirectPort(8443); + return connector; + } +}