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 deleted file mode 100644 index f6e81ff7c..000000000 --- a/jero-boot/jero-boot-module-system/src/main/java/com/jero/config/init/TomcatFactoryConfig.java +++ /dev/null @@ -1,76 +0,0 @@ -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; - -/** - * @Description: TomcatFactoryConfig - * @author: scott - * @date: 2021年01月25日 11:40 - */ -@Configuration -public class TomcatFactoryConfig { - - /** - * tomcat-embed-jasper引用后提示jar找不到的问题 - */ - @Bean - public TomcatServletWebServerFactory tomcatFactory() { - TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() { - @Override - protected void postProcessContext(Context context) { - ((StandardJarScanner) context.getJarScanner()).setScanManifest(false); - } - }; - factory.addConnectorCustomizers(connector -> { - connector.setProperty("relaxedPathChars", "[]{}"); - connector.setProperty("relaxedQueryChars", "[]{}"); - }); - return factory; - } - - //TODO 配置https证书 部署服务器的时候解开。 - /* @Value("${server.port}") - private String serverPortHttp; - @Value("${server.port-https}") - private String serverPortHttps; - @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/java/com/jero/config/TomcatSslConnectorProperties.java b/jero-boot/jero-boot-single-startup/src/main/java/com/jero/config/TomcatSslConnectorProperties.java new file mode 100644 index 000000000..204e17a35 --- /dev/null +++ b/jero-boot/jero-boot-single-startup/src/main/java/com/jero/config/TomcatSslConnectorProperties.java @@ -0,0 +1,46 @@ +package com.jero.config; + +import lombok.Data; +import org.apache.catalina.connector.Connector; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.PropertySource; + +import java.io.File; + +//@PropertySource("classpath:config/tomcat.https.properties") +@ConfigurationProperties(prefix = "jero.tomcat.https") +@Data +public class TomcatSslConnectorProperties { + + private Integer port; + private Boolean ssl = true; + private Boolean secure = true; + private String scheme = "https"; + private File keystore; + private String keystorePassword; + private String keystoreType; + //这里为了节省空间,省略了getters和setters,读者在实践的时候要加上 + + public void configureConnector(Connector connector) { + if (port != null) { + connector.setPort(port); + } + if (secure != null) { + connector.setSecure(secure); + } + if (scheme != null) { + connector.setScheme(scheme); + } + if (ssl != null) { + connector.setProperty("SSLEnabled", ssl.toString()); + } + + if (keystore != null && keystore.exists()) { + connector.setProperty("keystoreFile", keystore.getAbsolutePath()); + connector.setProperty("keystorePass", keystorePassword); + connector.setProperty("keystoreType", keystoreType); + } + } + +} diff --git a/jero-boot/jero-boot-single-startup/src/main/java/com/jero/config/TomcatWebConfiguration.java b/jero-boot/jero-boot-single-startup/src/main/java/com/jero/config/TomcatWebConfiguration.java new file mode 100644 index 000000000..2a6e8f839 --- /dev/null +++ b/jero-boot/jero-boot-single-startup/src/main/java/com/jero/config/TomcatWebConfiguration.java @@ -0,0 +1,28 @@ +package com.jero.config; + +import org.apache.catalina.connector.Connector; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +@EnableConfigurationProperties(TomcatSslConnectorProperties.class) +public class TomcatWebConfiguration extends WebMvcConfigurerAdapter { + + @Bean + public TomcatServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) { + TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(); + factory.addAdditionalTomcatConnectors(createSslConnector(properties)); + return factory; + } + + private Connector createSslConnector(TomcatSslConnectorProperties properties) { + Connector connector = new Connector(); + properties.configureConnector(connector); + 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 61a634c68..73617b813 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 @@ -12,12 +12,6 @@ server: enabled: true min-response-size: 1024 mime-types: application/javascript,application/json,application/xml,text/html,text/xml,text/plain,text/css,image/* -##配置https证书 部署服务器的时候解开。 -# port-https: 8089 #自定义https端口 -# ssl: -# key-store: classpath:bxxt.hzwlsoft.com.jks -# key-store-password: w933m5y1kz0xj8w -# key-store-type: JKS management: endpoints: web: @@ -209,6 +203,15 @@ jero : exportPdfTempPath: D://opt//exportPdfTemp/ #仿宋体字体文件路径 设置 simfangFontFilePath: D://opt//simfangFontFilePath//simfang.ttf + tomcat: + https: + port: 8089 + secure: true + scheme: https + ssl: true + keystore: classpath:grp.jks + keystorePassword: 501937 + keystoreType: JKS shiro: excludeUrls: /test/jeroDemo/demo3,/test/jeroDemo/redisDemo/**,/category/**,/visual/**,/map/**,/jmreport/bigscreen2/** #阿里云oss存储配置 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 deleted file mode 100644 index 38bbfad14..000000000 Binary files a/jero-boot/jero-boot-single-startup/src/main/resources/bxxt.hzwlsoft.com.jks and /dev/null differ diff --git a/jero-boot/jero-boot-single-startup/src/main/resources/filename.jks b/jero-boot/jero-boot-single-startup/src/main/resources/filename.jks deleted file mode 100644 index 2f9db442b..000000000 Binary files a/jero-boot/jero-boot-single-startup/src/main/resources/filename.jks and /dev/null differ diff --git a/jero-boot/jero-boot-single-startup/src/main/resources/grp.jks b/jero-boot/jero-boot-single-startup/src/main/resources/grp.jks new file mode 100644 index 000000000..20d3c0d33 Binary files /dev/null and b/jero-boot/jero-boot-single-startup/src/main/resources/grp.jks differ