Skip to content

Commit 96b1a85

Browse files
committed
Decorate KeyManager for Undertow only when an alias is configured
Fixes gh-9351
1 parent a064a52 commit 96b1a85

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,12 @@ private KeyManager[] getKeyManagers() {
316316
keyPassword = ssl.getKeyStorePassword().toCharArray();
317317
}
318318
keyManagerFactory.init(keyStore, keyPassword);
319-
return getConfigurableAliasKeyManagers(ssl,
320-
keyManagerFactory.getKeyManagers());
319+
if (ssl.getKeyAlias() != null) {
320+
return getConfigurableAliasKeyManagers(ssl,
321+
keyManagerFactory.getKeyManagers());
322+
}
323+
return keyManagerFactory.getKeyManagers();
324+
321325
}
322326
catch (Exception ex) {
323327
throw new IllegalStateException(ex);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Set;
2929
import java.util.concurrent.atomic.AtomicReference;
3030

31+
import javax.net.ssl.KeyManager;
3132
import javax.net.ssl.SSLHandshakeException;
3233

3334
import io.undertow.Undertow.Builder;
@@ -43,6 +44,7 @@
4344
import org.springframework.boot.context.embedded.ExampleServlet;
4445
import org.springframework.boot.context.embedded.MimeMappings.Mapping;
4546
import org.springframework.boot.context.embedded.PortInUseException;
47+
import org.springframework.boot.context.embedded.Ssl;
4648
import org.springframework.boot.web.servlet.ErrorPage;
4749
import org.springframework.boot.web.servlet.ServletRegistrationBean;
4850
import org.springframework.http.HttpStatus;
@@ -250,6 +252,16 @@ public void sslRestrictedProtocolsRSATLS11Failure() throws Exception {
250252
new String[] { "TLS_RSA_WITH_AES_128_CBC_SHA256" });
251253
}
252254

255+
@Test
256+
public void getKeyManagersWhenAliasIsNullShouldNotDecorate() throws Exception {
257+
UndertowEmbeddedServletContainerFactory factory = getFactory();
258+
Ssl ssl = getSsl(null, "password", "src/test/resources/test.jks");
259+
factory.setSsl(ssl);
260+
KeyManager[] keyManagers = ReflectionTestUtils.invokeMethod(factory, "getKeyManagers");
261+
Class<?> name = Class.forName("org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory$ConfigurableAliasKeyManager");
262+
assertThat(keyManagers[0]).isNotInstanceOf(name);
263+
}
264+
253265
@Override
254266
protected JspServlet getJspServlet() {
255267
return null; // Undertow does not support JSPs

0 commit comments

Comments
 (0)