配置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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user