websusk
websusk

Reputation: 81

Spring boot with jetty 9 and ssl

I have followed Spring Boot setup and can easily get Tomcat to run with SSL, however I'd like to use Jetty and there is little documentation out there for this. I can get access to the JettyEmbeddedServletContainerFactory, but it doesn't use the same interface methods to gain access to the configuation.

Has anyone had any luck configuring jetty 9 inside spring boot to use SSL? I found a similar question here and wondered if there was anyone that solved this.

Any help would be great.

Upvotes: 3

Views: 3930

Answers (2)

websusk
websusk

Reputation: 81

So there was a recent question posted to Spring Boot (day of or before I asked here, nice timing) via GitHub that asked for support for the same. They have an example of this working, and an example of how this will work after the new commit they will/have made. I'm using the former, and it's working fine. Looks like you can either get the latest source or wait for another release/milestone.

Here is a link to the discussion.

Here is my solution, but it works just as they say in their answer. I have not pulled their commit, so I'm using the first solution with the base Jetty API. Using Jetty 8 with Spring Boot for this sample, but Jetty 9 worked also.

@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() throws Exception {
    return new JettyEmbeddedServletContainerFactory() {
        @Override
        protected JettyEmbeddedServletContainer getJettyEmbeddedServletContainer(
                Server server) {

            SslContextFactory sslContextFactory = new SslContextFactory();
            sslContextFactory.setKeyStorePath("/usr/local/keystore");
            sslContextFactory.setKeyStorePassword("password");
            sslContextFactory.setCertAlias("alias");

            SslSocketConnector sslConnector = new SslSocketConnector(sslContextFactory);
            sslConnector.setPort(8443);
            server.setConnectors(new Connector[] { sslConnector });
            return super.getJettyEmbeddedServletContainer(server);
        }
    };
}

Upvotes: 4

JRr
JRr

Reputation: 1621

Are you using maven as build system? If so, you could check this pom.xml artifact - http://bghints.blogspot.com/2012/03/client-authentication-with-ssl_28.html

The blog post is for jetty 6. For jetty 9, there is a difference. Group ID must change from:

org.mortbay.jetty

to

org.eclipse.jetty

I hope this helps you.

Upvotes: 0

Related Questions