Search in sources :

Example 1 with TomcatEmbeddedServletContainerFactory

use of org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory in project cas by apereo.

the class CasEmbeddedContainerTomcatConfiguration method servletContainer.

@ConditionalOnClass(value = { Tomcat.class, Http2Protocol.class })
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    final TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    configureAjp(tomcat);
    configureHttp(tomcat);
    configureExtendedAccessLog(tomcat);
    configureRewriteValve(tomcat);
    return tomcat;
}
Also used : TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) Bean(org.springframework.context.annotation.Bean)

Example 2 with TomcatEmbeddedServletContainerFactory

use of org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory in project fru-paqx-parent by dellemc-symphony.

the class ContextConfig method servletContainer.

@Bean
public /**
     * This container is required in order to implement the redirect from http 8080 to https 18443 in spring boot.
     * This means that http can continue to be used but will automatically redirect to https
     * The responses from FRU will be https regardless of the protocol/port used by the cli.
     */
EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }

        @Override
        protected /**
             * This is the method where ssl is configured in the tomcat container.
             * We want to override this in order to be able to take an encrypted-base64-encoded password from
             * application.properties and to decode+decrypt it and provide it to the Ssl object before ssl configuration begins.
             */
        void configureSsl(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("ContextConfig: servletContainer: encoded password = " + ssl.getKeyStorePassword());
            }
            byte[] decodedBytes = Base64.getDecoder().decode(ssl.getKeyStorePassword());
            ssl.setKeyStorePassword(new String(decodedBytes));
            super.configureSsl(protocol, ssl);
        }
    };
    //Setup the redirection
    tomcat.addAdditionalTomcatConnectors(initiateHttpConnector());
    //Setup the custom realm, which sets the custom redirect code.
    //By default the redirect is 302.  But if the request to be redirected is a post,
    //then the post is converted to a get and therefore the post's body is removed in the redirect. (e.g. using CURL)
    //We need to set the redirection with code 307 so that the origin method is used in the redirect
    //e.g. get uses get on redirect and post uses post on redirect.
    //This conforms to standard RFC 2616
    tomcat.addContextCustomizers((TomcatContextCustomizer) context -> {
        RealmBase base = new CombinedRealm();
        base.setTransportGuaranteeRedirectStatus(307);
        context.setRealm(base);
    });
    return tomcat;
}
Also used : Context(org.apache.catalina.Context) CombinedRealm(org.apache.catalina.realm.CombinedRealm) Logger(org.slf4j.Logger) TomcatContextCustomizer(org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection) LoggerFactory(org.slf4j.LoggerFactory) Connector(org.apache.catalina.connector.Connector) Context(org.apache.catalina.Context) EmbeddedServletContainerFactory(org.springframework.boot.context.embedded.EmbeddedServletContainerFactory) RealmBase(org.apache.catalina.realm.RealmBase) Configuration(org.springframework.context.annotation.Configuration) Ssl(org.springframework.boot.context.embedded.Ssl) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) Base64(java.util.Base64) ConsumerContextConfig(com.dell.cpsd.service.common.client.context.ConsumerContextConfig) AbstractHttp11JsseProtocol(org.apache.coyote.http11.AbstractHttp11JsseProtocol) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) Bean(org.springframework.context.annotation.Bean) AbstractHttp11JsseProtocol(org.apache.coyote.http11.AbstractHttp11JsseProtocol) CombinedRealm(org.apache.catalina.realm.CombinedRealm) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) RealmBase(org.apache.catalina.realm.RealmBase) Ssl(org.springframework.boot.context.embedded.Ssl) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection) Bean(org.springframework.context.annotation.Bean)

Example 3 with TomcatEmbeddedServletContainerFactory

use of org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory in project survey by markoniemi.

the class TomcatConfig method servletContainer.

@Bean
@DependsOn("contextPath")
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
    factory.setPort(port);
    factory.setContextPath(contextPath());
    // https://stackoverflow.com/questions/43264890/after-upgrade-from-spring-boot-1-2-to-1-5-2-filenotfoundexception-during-tomcat
    String[] tldSkipPatterns = { "jaxb-core.jar", "jaxb-api.jar", "xml-apis.jar", "xercesImpl.jar", "xml-apis.jar", "serializer.jar" };
    factory.setTldSkipPatterns(Arrays.asList(tldSkipPatterns));
    return factory;
}
Also used : TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) DependsOn(org.springframework.context.annotation.DependsOn) Bean(org.springframework.context.annotation.Bean)

Example 4 with TomcatEmbeddedServletContainerFactory

use of org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory in project PublicCMS-preview by sanluan.

the class SprintBootApplication method servletContainer.

/**
 * @return servlet container
 */
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    String server = System.getProperty("cms.server");
    AbstractEmbeddedServletContainerFactory factory = null;
    if ("jetty".equalsIgnoreCase(server)) {
        factory = new JettyEmbeddedServletContainerFactory();
    } else if ("undertow".equalsIgnoreCase(server)) {
        factory = new UndertowEmbeddedServletContainerFactory();
    } else {
        factory = new TomcatEmbeddedServletContainerFactory();
    }
    factory.setPort(Integer.valueOf(System.getProperty("cms.port", "8080")));
    factory.setContextPath(System.getProperty("cms.contextPath", ""));
    factory.setDisplayName("PublicCMS");
    factory.setSessionTimeout(20, TimeUnit.MINUTES);
    return factory;
}
Also used : AbstractEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory) UndertowEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory) JettyEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) Bean(org.springframework.context.annotation.Bean)

Example 5 with TomcatEmbeddedServletContainerFactory

use of org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory in project danyuan-application by 514840279.

the class App method servletContainer.

// @Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint constraint = new SecurityConstraint();
            constraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            constraint.addCollection(collection);
            context.addConstraint(constraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(httpConnector());
    return tomcat;
}
Also used : Context(org.apache.catalina.Context) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection)

Aggregations

TomcatEmbeddedServletContainerFactory (org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory)14 Bean (org.springframework.context.annotation.Bean)11 Connector (org.apache.catalina.connector.Connector)6 TomcatConnectorCustomizer (org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer)4 Context (org.apache.catalina.Context)3 AbstractHttp11Protocol (org.apache.coyote.http11.AbstractHttp11Protocol)3 SecurityCollection (org.apache.tomcat.util.descriptor.web.SecurityCollection)3 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)3 SpringApplication (org.springframework.boot.SpringApplication)2 SpringBootApplication (org.springframework.boot.autoconfigure.SpringBootApplication)2 ConsumerContextConfig (com.dell.cpsd.service.common.client.context.ConsumerContextConfig)1 IOException (java.io.IOException)1 Base64 (java.util.Base64)1 ServletException (javax.servlet.ServletException)1 Request (org.apache.catalina.connector.Request)1 Response (org.apache.catalina.connector.Response)1 CombinedRealm (org.apache.catalina.realm.CombinedRealm)1 RealmBase (org.apache.catalina.realm.RealmBase)1 ValveBase (org.apache.catalina.valves.ValveBase)1 ProtocolHandler (org.apache.coyote.ProtocolHandler)1