use of org.springframework.boot.web.server.WebServerFactory in project kork by spinnaker.
the class TomcatConfiguration method containerCustomizer.
/**
* Setup multiple connectors: - an https connector requiring client auth that will service API
* requests - an http connector that will service legacy non-https requests
*/
@Bean
@ConditionalOnExpression("${server.ssl.enabled:false}")
WebServerFactoryCustomizer containerCustomizer(DefaultTomcatConnectorCustomizer defaultTomcatConnectorCustomizer, TomcatConfigurationProperties tomcatConfigurationProperties) {
System.setProperty("jdk.tls.rejectClientInitiatedRenegotiation", "true");
System.setProperty("jdk.tls.ephemeralDHKeySize", "2048");
return new WebServerFactoryCustomizer() {
@Override
public void customize(WebServerFactory factory) {
TomcatServletWebServerFactory tomcat = (TomcatServletWebServerFactory) factory;
// This will only handle the case where SSL is enabled on the main Tomcat connector
tomcat.addConnectorCustomizers(defaultTomcatConnectorCustomizer);
if (tomcatConfigurationProperties.getLegacyServerPort() > 0) {
log.info("Creating legacy connector on port {}", tomcatConfigurationProperties.getLegacyServerPort());
Connector httpConnector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
httpConnector.setScheme("http");
httpConnector.setPort(tomcatConfigurationProperties.getLegacyServerPort());
applyCompressionSettings(httpConnector, tomcat);
tomcat.addAdditionalTomcatConnectors(httpConnector);
}
if (tomcatConfigurationProperties.getApiPort() > 0) {
log.info("Creating api connector on port {}", tomcatConfigurationProperties.getApiPort());
Connector apiConnector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
apiConnector.setScheme("https");
apiConnector.setSecure(true);
apiConnector.setPort(tomcatConfigurationProperties.getApiPort());
applyCompressionSettings(apiConnector, tomcat);
Ssl ssl = defaultTomcatConnectorCustomizer.copySslConfigurationWithClientAuth(tomcat);
CustomizableTomcatServletWebServerFactory newFactory = new CustomizableTomcatServletWebServerFactory();
BeanUtils.copyProperties(tomcat, newFactory);
newFactory.setPort(tomcatConfigurationProperties.getApiPort());
newFactory.setSsl(ssl);
newFactory.customizeSslConnector(apiConnector);
defaultTomcatConnectorCustomizer.customize(apiConnector);
tomcat.addAdditionalTomcatConnectors(apiConnector);
}
}
};
}
Aggregations