Spring Boot / Embedded Tomcat - SSL

 @Bean

    public ServletWebServerFactory servletContainer() {

        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {

            @Override

            protected void postProcessContext(Context context) {

                var securityConstraint = new SecurityConstraint();

                securityConstraint.setUserConstraint("CONFIDENTIAL");

                var collection = new SecurityCollection();

                collection.addPattern("/*");

                securityConstraint.addCollection(collection);

                context.addConstraint(securityConstraint);

            }

        };

        tomcat.addAdditionalTomcatConnectors(getHttpConnector());

        return tomcat;

    }


    private Connector getHttpConnector() {

        var connector = new Connector(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);

        connector.setScheme("http");

        connector.setPort(8001);

        connector.setSecure(false);

        connector.setRedirectPort(2083);

        return connector;

    }


server.ssl.key-store=classpath:certif.p12
server.ssl.key-store-password=pass
server.ssl.key-store-type=pkcs12
#server.ssl.key-alias=certif
server.ssl.key-password=pass

Comments

Popular posts from this blog

Validation for AZ phone numbers with RegEx in Java

Java necə işləyir, kod nədir ?