Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support declaritive SSL termination #1084

Closed
philwebb opened this issue Jun 12, 2014 · 4 comments
Closed

Support declaritive SSL termination #1084

philwebb opened this issue Jun 12, 2014 · 4 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@philwebb
Copy link
Member

We support SSL but as pointed out in #101 (comment) it's not all that convenient to configure.

@wilkinsona
Copy link
Member

While I remember, I answered a question the other day about configuring SSL on Jetty. This is the code to do it:

@Bean
public EmbeddedServletContainerCustomizer servletContainerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {

        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            if (container instanceof JettyEmbeddedServletContainerFactory) {
                customizeJetty((JettyEmbeddedServletContainerFactory) container);
            }
        }

        private void customizeJetty(JettyEmbeddedServletContainerFactory factory) {
            factory.addServerCustomizers(new JettyServerCustomizer() {

                @Override
                public void customize(Server server) {
                    SslContextFactory sslContextFactory = new SslContextFactory();
                    sslContextFactory.setKeyStorePassword("password");
                    try {
                        sslContextFactory.setKeyStorePath(ResourceUtils.getFile(
                                "classpath:jetty-ssl.keystore").getAbsolutePath());
                    }
                    catch (FileNotFoundException ex) {
                        throw new IllegalStateException("Could not load keystore", ex);
                    }
                    SslSocketConnector sslConnector = new SslSocketConnector(
                            sslContextFactory);
                    sslConnector.setPort(8443);
                    server.addConnector(sslConnector);
                }
            });
        }
    };
}

@wilkinsona wilkinsona changed the title Support delaritive SSL termination Support declaritive SSL termination Jun 12, 2014
@philwebb philwebb changed the title Support declaritive SSL termination Support delaritive SSL termination Jun 12, 2014
@btiernay
Copy link

I should also mention that the above (and the same for Tomcat) doesn't work work inside from within a jar (or nested jar). I would think that is okay because typically one doesn't package the keystore with the application, but it should probably be mentioned in the docs if this feature is implemented.

@wilkinsona wilkinsona changed the title Support delaritive SSL termination Support declaritive SSL termination Jun 25, 2014
@markfisher markfisher modified the milestones: 1.1.4, 1.2.0 Jul 3, 2014
@philwebb philwebb removed this from the 1.1.4 milestone Jul 3, 2014
@wilkinsona
Copy link
Member

Good point. Thanks, @btiernay.

I've learned today that we can do slightly better with Jetty as it allows the keystore to be configured using a Resource:

sslContextFactory.setKeyStoreResource(Resource.newResource(ResourceUtils.getURL(getSsl().getKeystore())));

This allows the keystore to be packaged in a jar if you're using Jetty. Tomcat still requires the keystore to be a file on the filesystem and we'll need to document this.

@btiernay
Copy link

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants