diff --git a/jero-boot/jero-boot-module-system/src/main/java/com/jero/config/init/TomcatFactoryConfig.java b/jero-boot/jero-boot-module-system/src/main/java/com/jero/config/init/TomcatFactoryConfig.java index 8ca4f6635..5256b528b 100644 --- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/config/init/TomcatFactoryConfig.java +++ b/jero-boot/jero-boot-module-system/src/main/java/com/jero/config/init/TomcatFactoryConfig.java @@ -1,7 +1,12 @@ package com.jero.config.init; import org.apache.catalina.Context; +import org.apache.catalina.connector.Connector; +import org.apache.coyote.http11.Http11NioProtocol; +import org.apache.tomcat.util.descriptor.web.SecurityCollection; +import org.apache.tomcat.util.descriptor.web.SecurityConstraint; import org.apache.tomcat.util.scan.StandardJarScanner; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -13,10 +18,15 @@ import org.springframework.context.annotation.Configuration; */ @Configuration public class TomcatFactoryConfig { + @Value("${server.port-https}") + private String serverPortHttp; + @Value("${server.port}") + private String serverPortHttps; + /** * tomcat-embed-jasper引用后提示jar找不到的问题 */ - @Bean + /*@Bean public TomcatServletWebServerFactory tomcatFactory() { TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() { @Override @@ -29,5 +39,37 @@ public class TomcatFactoryConfig { connector.setProperty("relaxedQueryChars", "[]{}"); }); return factory; + }*/ + + @Bean + public TomcatServletWebServerFactory tomcatFactory() { + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() { + @Override + protected void postProcessContext(Context context) { + ((StandardJarScanner) context.getJarScanner()).setScanManifest(false); + + SecurityConstraint securityConstraint = new SecurityConstraint(); + securityConstraint.setUserConstraint("CONFIDENTIAL"); + SecurityCollection securityCollection = new SecurityCollection(); + securityCollection.addPattern("/*"); + securityConstraint.addCollection(securityCollection); + context.addConstraint(securityConstraint); + } + }; + factory.addConnectorCustomizers(connector -> { + connector.setProperty("relaxedPathChars", "[]{}"); + connector.setProperty("relaxedQueryChars", "[]{}"); + }); + factory.addAdditionalTomcatConnectors(redirectConnector()); + return factory; + } + + private Connector redirectConnector() { + Connector connector = new Connector(Http11NioProtocol.class.getName()); + connector.setScheme("http"); + connector.setPort(Integer.parseInt(serverPortHttp)); + connector.setSecure(false); + connector.setRedirectPort(Integer.parseInt(serverPortHttps)); + return connector; } } diff --git a/jero-boot/jero-boot-single-startup/src/main/resources/application-dev.yml b/jero-boot/jero-boot-single-startup/src/main/resources/application-dev.yml index cf284ac6f..391799eff 100644 --- a/jero-boot/jero-boot-single-startup/src/main/resources/application-dev.yml +++ b/jero-boot/jero-boot-single-startup/src/main/resources/application-dev.yml @@ -1,5 +1,6 @@ server: port: 8080 + port-https: 8089 #自定义https端口 tomcat: max-swallow-size: -1 error: @@ -12,7 +13,10 @@ server: enabled: true min-response-size: 1024 mime-types: application/javascript,application/json,application/xml,text/html,text/xml,text/plain,text/css,image/* - + ssl: #配置https证书 + key-store: classpath:bxxt.hzwlsoft.com.jks + key-store-password: w933m5y1kz0xj8w + key-store-type: JKS management: endpoints: web: diff --git a/jero-boot/jero-boot-single-startup/src/main/resources/bxxt.hzwlsoft.com.jks b/jero-boot/jero-boot-single-startup/src/main/resources/bxxt.hzwlsoft.com.jks new file mode 100644 index 000000000..38bbfad14 Binary files /dev/null and b/jero-boot/jero-boot-single-startup/src/main/resources/bxxt.hzwlsoft.com.jks differ diff --git a/jero-boot/pom.xml b/jero-boot/pom.xml index c3f234115..6bee178cc 100644 --- a/jero-boot/pom.xml +++ b/jero-boot/pom.xml @@ -358,6 +358,7 @@ svg doc docx + jks