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) {
|
if (sslStoreProvider != null) {
|
||||||
return sslStoreProvider.getKeyStore();
|
return sslStoreProvider.getKeyStore();
|
||||||
}
|
}
|
||||||
return loadKeyStore(ssl.getKeyStoreType(), ssl.getKeyStore(),
|
return loadKeyStore(ssl.getKeyStoreType(), ssl.getKeyStoreProvider(),
|
||||||
ssl.getKeyStorePassword());
|
ssl.getKeyStore(), ssl.getKeyStorePassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
private TrustManager[] getTrustManagers(Ssl ssl, SslStoreProvider sslStoreProvider) {
|
private TrustManager[] getTrustManagers(Ssl ssl, SslStoreProvider sslStoreProvider) {
|
||||||
|
@ -166,17 +166,18 @@ class SslBuilderCustomizer implements UndertowBuilderCustomizer {
|
||||||
if (sslStoreProvider != null) {
|
if (sslStoreProvider != null) {
|
||||||
return sslStoreProvider.getTrustStore();
|
return sslStoreProvider.getTrustStore();
|
||||||
}
|
}
|
||||||
return loadKeyStore(ssl.getTrustStoreType(), ssl.getTrustStore(),
|
return loadKeyStore(ssl.getTrustStoreType(), ssl.getTrustStoreProvider(),
|
||||||
ssl.getTrustStorePassword());
|
ssl.getTrustStore(), ssl.getTrustStorePassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
private KeyStore loadKeyStore(String type, String resource, String password)
|
private KeyStore loadKeyStore(String type, String provider, String resource,
|
||||||
throws Exception {
|
String password) throws Exception {
|
||||||
type = (type != null) ? type : "JKS";
|
type = (type != null) ? type : "JKS";
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
KeyStore store = KeyStore.getInstance(type);
|
KeyStore store = (provider != null) ? KeyStore.getInstance(type, provider)
|
||||||
|
: KeyStore.getInstance(type);
|
||||||
URL url = ResourceUtils.getURL(resource);
|
URL url = ResourceUtils.getURL(resource);
|
||||||
store.load(url.openStream(), (password != null) ? password.toCharArray() : null);
|
store.load(url.openStream(), (password != null) ? password.toCharArray() : null);
|
||||||
return store;
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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;
|
package org.springframework.boot.web.embedded.undertow;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.security.NoSuchProviderException;
|
||||||
|
|
||||||
import javax.net.ssl.KeyManager;
|
import javax.net.ssl.KeyManager;
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ import org.springframework.boot.web.server.Ssl;
|
||||||
import org.springframework.test.util.ReflectionTestUtils;
|
import org.springframework.test.util.ReflectionTestUtils;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link SslBuilderCustomizer}
|
* Tests for {@link SslBuilderCustomizer}
|
||||||
|
@ -48,4 +50,42 @@ public class SslBuilderCustomizerTests {
|
||||||
assertThat(keyManagers[0]).isNotInstanceOf(name);
|
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