Backport Jetty/Tomcat SSL support
Fixes gh-1570 Cherry-picked from0960908and258c6f1
This commit is contained in:
@@ -56,6 +56,18 @@ content into your application; rather pick only the properties that you need.
|
||||
server.session-timeout= # session timeout in seconds
|
||||
server.context-path= # the context path, defaults to '/'
|
||||
server.servlet-path= # the servlet path, defaults to '/'
|
||||
server.ssl.client-auth= # want or need
|
||||
server.ssl.key-alias=
|
||||
server.ssl.key-password=
|
||||
server.ssl.key-store=
|
||||
server.ssl.key-store-password=
|
||||
server.ssl.key-store-provider=
|
||||
server.ssl.key-store-type=
|
||||
server.ssl.protocol=TLS
|
||||
server.ssl.trust-store=
|
||||
server.ssl.trust-store-password=
|
||||
server.ssl.trust-store-provider=
|
||||
server.ssl.trust-store-type=
|
||||
server.tomcat.access-log-pattern= # log pattern of the access log
|
||||
server.tomcat.access-log-enabled=false # is access logging enabled
|
||||
server.tomcat.internal-proxies=10\.\d{1,3}\.\d{1,3}\.\d{1,3}|\
|
||||
|
||||
@@ -389,6 +389,27 @@ and then inject the actual (``local'') port as a `@Value`. For example:
|
||||
|
||||
|
||||
|
||||
[[howto-configure-ssl]]
|
||||
=== Configure SSL
|
||||
SSL can be configured declaratively by setting the various `server.ssl.*` properties,
|
||||
typically in `application.properties` or `application.yml`. For example:
|
||||
|
||||
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
server.port = 8443
|
||||
server.ssl.key-store = classpath:keystore.jks
|
||||
server.ssl.key-store-password = secret
|
||||
server.ssl.key-password = another-secret
|
||||
----
|
||||
|
||||
See {sc-spring-boot}/context/embedded/Ssl.{sc-ext}[`Ssl`] for details of all of the
|
||||
supported properties.
|
||||
|
||||
NOTE: Tomcat requires the key store (and trust store if you're using one) to be directly
|
||||
accessible on the filesystem, i.e. it cannot be read from within a jar file.
|
||||
|
||||
|
||||
|
||||
[[howto-configure-tomcat]]
|
||||
=== Configure Tomcat
|
||||
Generally you can follow the advice from
|
||||
@@ -401,56 +422,6 @@ nuclear option is to add your own `TomcatEmbeddedServletContainerFactory`.
|
||||
|
||||
|
||||
|
||||
[[howto-terminate-ssl-in-tomcat]]
|
||||
=== Terminate SSL in Tomcat
|
||||
Use an `EmbeddedServletContainerCustomizer` and in that add a `TomcatConnectorCustomizer`
|
||||
that sets up the connector to be secure:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
@Bean
|
||||
public EmbeddedServletContainerCustomizer containerCustomizer(){
|
||||
return new MyCustomizer();
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
private static class MyCustomizer implements EmbeddedServletContainerCustomizer {
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableEmbeddedServletContainer factory) {
|
||||
if(factory instanceof TomcatEmbeddedServletContainerFactory) {
|
||||
customizeTomcat((TomcatEmbeddedServletContainerFactory) factory);
|
||||
}
|
||||
}
|
||||
|
||||
public void customizeTomcat(TomcatEmbeddedServletContainerFactory factory) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
connector.setPort(serverPort);
|
||||
connector.setSecure(true);
|
||||
connector.setScheme("https");
|
||||
connector.setAttribute("keyAlias", "tomcat");
|
||||
connector.setAttribute("keystorePass", "password");
|
||||
try {
|
||||
connector.setAttribute("keystoreFile",
|
||||
ResourceUtils.getFile("src/ssl/tomcat.keystore").getAbsolutePath());
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new IllegalStateException("Cannot load keystore", e);
|
||||
}
|
||||
connector.setAttribute("clientAuth", "false");
|
||||
connector.setAttribute("sslProtocol", "TLS");
|
||||
connector.setAttribute("SSLEnabled", true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[howto-enable-multiple-connectors-in-tomcat]]
|
||||
=== Enable Multiple Connectors Tomcat
|
||||
Add a `org.apache.catalina.connector.Connector` to the
|
||||
|
||||
Reference in New Issue
Block a user