Skip to content

Commit d33d068

Browse files
committed
Upgrade to Tomcat 8.0.28 and test support for SSL config from classpath
Prior to 8.0.28 Tomcat required the key store and trust store (if any) to be available directly on the filesystem, i.e. classpath: resources would not work. Tomcat 8.0.28 removed this limitation. This commit updates to Tomcat 8.0.28, updates the tests to verify the new Tomcat capability and removes the obsolete documentation of the restriction. Closes gh-4048
1 parent ee3d4b3 commit d33d068

File tree

6 files changed

+20
-23
lines changed

6 files changed

+20
-23
lines changed

spring-boot-dependencies/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
<thymeleaf-extras-conditionalcomments.version>2.1.1.RELEASE</thymeleaf-extras-conditionalcomments.version>
135135
<thymeleaf-layout-dialect.version>1.2.9</thymeleaf-layout-dialect.version>
136136
<thymeleaf-extras-data-attribute.version>1.3</thymeleaf-extras-data-attribute.version>
137-
<tomcat.version>8.0.26</tomcat.version>
137+
<tomcat.version>8.0.28</tomcat.version>
138138
<undertow.version>1.1.8.Final</undertow.version>
139139
<velocity.version>1.7</velocity.version>
140140
<velocity-tools.version>2.0</velocity-tools.version>

spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,6 @@ typically in `application.properties` or `application.yml`. For example:
423423
See {sc-spring-boot}/context/embedded/Ssl.{sc-ext}[`Ssl`] for details of all of the
424424
supported properties.
425425

426-
NOTE: Tomcat requires the key store (and trust store if you're using one) to be directly
427-
accessible on the filesystem, i.e. it cannot be read from within a jar file. This
428-
limitation doesn't apply to Jetty and Undertow.
429-
430426
Using configuration like the example above means the application will no longer support
431427
plain HTTP connector at port 8080. Spring Boot doesn't support the configuration of both
432428
an HTTP connector and an HTTPS connector via `application.properties`. If you want to
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
server.port = 8443
2-
server.ssl.key-store = sample.jks
2+
server.ssl.key-store = classpath:sample.jks
33
server.ssl.key-store-password = secret
4-
server.ssl.key-password = password
4+
server.ssl.key-password = password

spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ else if (ssl.getClientAuth() == ClientAuth.WANT) {
285285

286286
private void configureSslKeyStore(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) {
287287
try {
288-
File file = ResourceUtils.getFile(ssl.getKeyStore());
289-
protocol.setKeystoreFile(file.getAbsolutePath());
288+
protocol.setKeystoreFile(ResourceUtils.getURL(ssl.getKeyStore()).toString());
290289
}
291290
catch (FileNotFoundException ex) {
292291
throw new EmbeddedServletContainerException(
@@ -303,8 +302,8 @@ private void configureSslKeyStore(AbstractHttp11JsseProtocol<?> protocol, Ssl ss
303302
private void configureSslTrustStore(AbstractHttp11JsseProtocol<?> protocol, Ssl ssl) {
304303
if (ssl.getTrustStore() != null) {
305304
try {
306-
File file = ResourceUtils.getFile(ssl.getTrustStore());
307-
protocol.setTruststoreFile(file.getAbsolutePath());
305+
protocol.setTruststoreFile(
306+
ResourceUtils.getURL(ssl.getTrustStore()).toString());
308307
}
309308
catch (FileNotFoundException ex) {
310309
throw new EmbeddedServletContainerException(

spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,19 @@ public void errorPage() throws Exception {
311311
}
312312

313313
@Test
314-
public void basicSsl() throws Exception {
314+
public void basicSslFromClassPath() throws Exception {
315+
testBasicSslWithKeyStore("classpath:test.jks");
316+
}
317+
318+
@Test
319+
public void basicSslFromFileSystem() throws Exception {
315320
testBasicSslWithKeyStore("src/test/resources/test.jks");
316321
}
317322

318323
@Test
319324
public void sslDisabled() throws Exception {
320325
AbstractEmbeddedServletContainerFactory factory = getFactory();
321-
Ssl ssl = getSsl(null, "password", "src/test/resources/test.jks");
326+
Ssl ssl = getSsl(null, "password", "classpath:test.jks");
322327
ssl.setEnabled(false);
323328
factory.setSsl(ssl);
324329
this.container = factory.getEmbeddedServletContainer(
@@ -374,8 +379,8 @@ protected final void testBasicSslWithKeyStore(String keyStore) throws Exception
374379
public void pkcs12KeyStoreAndTrustStore() throws Exception {
375380
AbstractEmbeddedServletContainerFactory factory = getFactory();
376381
addTestTxtFile(factory);
377-
factory.setSsl(getSsl(ClientAuth.NEED, null, "src/test/resources/test.p12",
378-
"src/test/resources/test.p12"));
382+
factory.setSsl(getSsl(ClientAuth.NEED, null, "classpath:test.p12",
383+
"classpath:test.p12"));
379384
this.container = factory.getEmbeddedServletContainer();
380385
this.container.start();
381386
KeyStore keyStore = KeyStore.getInstance("pkcs12");
@@ -398,8 +403,8 @@ public void sslNeedsClientAuthenticationSucceedsWithClientCertificate()
398403
throws Exception {
399404
AbstractEmbeddedServletContainerFactory factory = getFactory();
400405
addTestTxtFile(factory);
401-
factory.setSsl(getSsl(ClientAuth.NEED, "password", "src/test/resources/test.jks",
402-
"src/test/resources/test.jks"));
406+
factory.setSsl(getSsl(ClientAuth.NEED, "password", "classpath:test.jks",
407+
"classpath:test.jks"));
403408
this.container = factory.getEmbeddedServletContainer();
404409
this.container.start();
405410
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
@@ -422,8 +427,7 @@ public void sslNeedsClientAuthenticationFailsWithoutClientCertificate()
422427
throws Exception {
423428
AbstractEmbeddedServletContainerFactory factory = getFactory();
424429
addTestTxtFile(factory);
425-
factory.setSsl(
426-
getSsl(ClientAuth.NEED, "password", "src/test/resources/test.jks"));
430+
factory.setSsl(getSsl(ClientAuth.NEED, "password", "classpath:test.jks"));
427431
this.container = factory.getEmbeddedServletContainer();
428432
this.container.start();
429433
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
@@ -441,8 +445,7 @@ public void sslWantsClientAuthenticationSucceedsWithClientCertificate()
441445
throws Exception {
442446
AbstractEmbeddedServletContainerFactory factory = getFactory();
443447
addTestTxtFile(factory);
444-
factory.setSsl(
445-
getSsl(ClientAuth.WANT, "password", "src/test/resources/test.jks"));
448+
factory.setSsl(getSsl(ClientAuth.WANT, "password", "classpath:test.jks"));
446449
this.container = factory.getEmbeddedServletContainer();
447450
this.container.start();
448451
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
@@ -465,8 +468,7 @@ public void sslWantsClientAuthenticationSucceedsWithoutClientCertificate()
465468
throws Exception {
466469
AbstractEmbeddedServletContainerFactory factory = getFactory();
467470
addTestTxtFile(factory);
468-
factory.setSsl(
469-
getSsl(ClientAuth.WANT, "password", "src/test/resources/test.jks"));
471+
factory.setSsl(getSsl(ClientAuth.WANT, "password", "classpath:test.jks"));
470472
this.container = factory.getEmbeddedServletContainer();
471473
this.container.start();
472474
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(

0 commit comments

Comments
 (0)