配置https .JKS的SSL证书。
This commit is contained in:
+43
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Binary file not shown.
@@ -358,6 +358,7 @@
|
||||
<nonFilteredFileExtension>svg</nonFilteredFileExtension>
|
||||
<nonFilteredFileExtension>doc</nonFilteredFileExtension>
|
||||
<nonFilteredFileExtension>docx</nonFilteredFileExtension>
|
||||
<nonFilteredFileExtension>jks</nonFilteredFileExtension>
|
||||
</nonFilteredFileExtensions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
Reference in New Issue
Block a user