Search in sources :

Example 1 with WebServerFactory

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);
            }
        }
    };
}
Also used : Connector(org.apache.catalina.connector.Connector) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) WebServerFactory(org.springframework.boot.web.server.WebServerFactory) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) WebServerFactoryCustomizer(org.springframework.boot.web.server.WebServerFactoryCustomizer) Ssl(org.springframework.boot.web.server.Ssl) ConditionalOnExpression(org.springframework.boot.autoconfigure.condition.ConditionalOnExpression) Bean(org.springframework.context.annotation.Bean)

Aggregations

Connector (org.apache.catalina.connector.Connector)1 ConditionalOnExpression (org.springframework.boot.autoconfigure.condition.ConditionalOnExpression)1 TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)1 Ssl (org.springframework.boot.web.server.Ssl)1 WebServerFactory (org.springframework.boot.web.server.WebServerFactory)1 WebServerFactoryCustomizer (org.springframework.boot.web.server.WebServerFactoryCustomizer)1 Bean (org.springframework.context.annotation.Bean)1