Merge branch '1.5.x' into 2.0.x
This commit is contained in:
commit
d6d59edb35
|
@ -144,8 +144,8 @@ class SslBuilderCustomizer implements UndertowBuilderCustomizer {
|
|||
if (sslStoreProvider != null) {
|
||||
return sslStoreProvider.getKeyStore();
|
||||
}
|
||||
return loadKeyStore(ssl.getKeyStoreType(), ssl.getKeyStore(),
|
||||
ssl.getKeyStorePassword());
|
||||
return loadKeyStore(ssl.getKeyStoreType(), ssl.getKeyStoreProvider(),
|
||||
ssl.getKeyStore(), ssl.getKeyStorePassword());
|
||||
}
|
||||
|
||||
private TrustManager[] getTrustManagers(Ssl ssl, SslStoreProvider sslStoreProvider) {
|
||||
|
@ -166,17 +166,18 @@ class SslBuilderCustomizer implements UndertowBuilderCustomizer {
|
|||
if (sslStoreProvider != null) {
|
||||
return sslStoreProvider.getTrustStore();
|
||||
}
|
||||
return loadKeyStore(ssl.getTrustStoreType(), ssl.getTrustStore(),
|
||||
ssl.getTrustStorePassword());
|
||||
return loadKeyStore(ssl.getTrustStoreType(), ssl.getTrustStoreProvider(),
|
||||
ssl.getTrustStore(), ssl.getTrustStorePassword());
|
||||
}
|
||||
|
||||
private KeyStore loadKeyStore(String type, String resource, String password)
|
||||
throws Exception {
|
||||
private KeyStore loadKeyStore(String type, String provider, String resource,
|
||||
String password) throws Exception {
|
||||
type = (type != null) ? type : "JKS";
|
||||
if (resource == null) {
|
||||
return null;
|
||||
}
|
||||
KeyStore store = KeyStore.getInstance(type);
|
||||
KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider)
|
||||
: KeyStore.getInstance(type);
|
||||
URL url = ResourceUtils.getURL(resource);
|
||||
store.load(url.openStream(), (password != null) ? password.toCharArray() : null);
|
||||
return store;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.boot.web.embedded.undertow;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.security.NoSuchProviderException;
|
||||
|
||||
import javax.net.ssl.KeyManager;
|
||||
|
||||
|
@ -26,6 +27,7 @@ import org.springframework.boot.web.server.Ssl;
|
|||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link SslBuilderCustomizer}
|
||||
|
@ -48,4 +50,42 @@ public class SslBuilderCustomizerTests {
|
|||
assertThat(keyManagers[0]).isNotInstanceOf(name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void keyStoreProviderIsUsedWhenCreatingKeyStore() throws Exception {
|
||||
Ssl ssl = new Ssl();
|
||||
ssl.setKeyPassword("password");
|
||||
ssl.setKeyStore("src/test/resources/test.jks");
|
||||
ssl.setKeyStoreProvider("com.example.KeyStoreProvider");
|
||||
SslBuilderCustomizer customizer = new SslBuilderCustomizer(8080,
|
||||
InetAddress.getLocalHost(), ssl, null);
|
||||
try {
|
||||
ReflectionTestUtils.invokeMethod(customizer, "getKeyManagers", ssl, null);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
Throwable cause = ex.getCause();
|
||||
assertThat(cause).isInstanceOf(NoSuchProviderException.class);
|
||||
assertThat(cause).hasMessageContaining("com.example.KeyStoreProvider");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void trustStoreProviderIsUsedWhenCreatingTrustStore() throws Exception {
|
||||
Ssl ssl = new Ssl();
|
||||
ssl.setTrustStorePassword("password");
|
||||
ssl.setTrustStore("src/test/resources/test.jks");
|
||||
ssl.setTrustStoreProvider("com.example.TrustStoreProvider");
|
||||
SslBuilderCustomizer customizer = new SslBuilderCustomizer(8080,
|
||||
InetAddress.getLocalHost(), ssl, null);
|
||||
try {
|
||||
ReflectionTestUtils.invokeMethod(customizer, "getTrustManagers", ssl, null);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
Throwable cause = ex.getCause();
|
||||
assertThat(cause).isInstanceOf(NoSuchProviderException.class);
|
||||
assertThat(cause).hasMessageContaining("com.example.TrustStoreProvider");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue