Skip to content

Commit 9f2995a

Browse files
committed
Migrate from deprecated Jetty's SslContextFactory
Closes gh-16827
1 parent 2e504b4 commit 9f2995a

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/SslServerCustomizer.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ class SslServerCustomizer implements JettyServerCustomizer {
6969

7070
@Override
7171
public void customize(Server server) {
72-
SslContextFactory sslContextFactory = new SslContextFactory();
72+
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
7373
configureSsl(sslContextFactory, this.ssl, this.sslStoreProvider);
7474
ServerConnector connector = createConnector(server, sslContextFactory,
7575
this.address);
7676
server.setConnectors(new Connector[] { connector });
7777
}
7878

7979
private ServerConnector createConnector(Server server,
80-
SslContextFactory sslContextFactory, InetSocketAddress address) {
80+
SslContextFactory.Server sslContextFactory, InetSocketAddress address) {
8181
HttpConfiguration config = new HttpConfiguration();
8282
config.setSendServerVersion(false);
8383
config.setSecureScheme("https");
@@ -91,7 +91,7 @@ private ServerConnector createConnector(Server server,
9191
}
9292

9393
private ServerConnector createServerConnector(Server server,
94-
SslContextFactory sslContextFactory, HttpConfiguration config) {
94+
SslContextFactory.Server sslContextFactory, HttpConfiguration config) {
9595
if (this.http2 == null || !this.http2.isEnabled()) {
9696
return createHttp11ServerConnector(server, config, sslContextFactory);
9797
}
@@ -104,7 +104,7 @@ private ServerConnector createServerConnector(Server server,
104104
}
105105

106106
private ServerConnector createHttp11ServerConnector(Server server,
107-
HttpConfiguration config, SslContextFactory sslContextFactory) {
107+
HttpConfiguration config, SslContextFactory.Server sslContextFactory) {
108108
HttpConnectionFactory connectionFactory = new HttpConnectionFactory(config);
109109
SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(
110110
sslContextFactory, HttpVersion.HTTP_1_1.asString());
@@ -121,7 +121,7 @@ private boolean isConscryptPresent() {
121121
}
122122

123123
private ServerConnector createHttp2ServerConnector(Server server,
124-
HttpConfiguration config, SslContextFactory sslContextFactory) {
124+
HttpConfiguration config, SslContextFactory.Server sslContextFactory) {
125125
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(config);
126126
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
127127
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
@@ -134,11 +134,11 @@ private ServerConnector createHttp2ServerConnector(Server server,
134134

135135
/**
136136
* Configure the SSL connection.
137-
* @param factory the Jetty {@link SslContextFactory}.
137+
* @param factory the Jetty {@link SslContextFactory.Server}.
138138
* @param ssl the ssl details.
139139
* @param sslStoreProvider the ssl store provider
140140
*/
141-
protected void configureSsl(SslContextFactory factory, Ssl ssl,
141+
protected void configureSsl(SslContextFactory.Server factory, Ssl ssl,
142142
SslStoreProvider sslStoreProvider) {
143143
factory.setProtocol(ssl.getProtocol());
144144
configureSslClientAuth(factory, ssl);
@@ -166,7 +166,7 @@ protected void configureSsl(SslContextFactory factory, Ssl ssl,
166166
}
167167
}
168168

169-
private void configureSslClientAuth(SslContextFactory factory, Ssl ssl) {
169+
private void configureSslClientAuth(SslContextFactory.Server factory, Ssl ssl) {
170170
if (ssl.getClientAuth() == Ssl.ClientAuth.NEED) {
171171
factory.setNeedClientAuth(true);
172172
factory.setWantClientAuth(true);
@@ -176,7 +176,7 @@ else if (ssl.getClientAuth() == Ssl.ClientAuth.WANT) {
176176
}
177177
}
178178

179-
private void configureSslPasswords(SslContextFactory factory, Ssl ssl) {
179+
private void configureSslPasswords(SslContextFactory.Server factory, Ssl ssl) {
180180
if (ssl.getKeyStorePassword() != null) {
181181
factory.setKeyStorePassword(ssl.getKeyStorePassword());
182182
}
@@ -185,7 +185,7 @@ private void configureSslPasswords(SslContextFactory factory, Ssl ssl) {
185185
}
186186
}
187187

188-
private void configureSslKeyStore(SslContextFactory factory, Ssl ssl) {
188+
private void configureSslKeyStore(SslContextFactory.Server factory, Ssl ssl) {
189189
try {
190190
URL url = ResourceUtils.getURL(ssl.getKeyStore());
191191
factory.setKeyStoreResource(Resource.newResource(url));
@@ -202,7 +202,7 @@ private void configureSslKeyStore(SslContextFactory factory, Ssl ssl) {
202202
}
203203
}
204204

205-
private void configureSslTrustStore(SslContextFactory factory, Ssl ssl) {
205+
private void configureSslTrustStore(SslContextFactory.Server factory, Ssl ssl) {
206206
if (ssl.getTrustStorePassword() != null) {
207207
factory.setTrustStorePassword(ssl.getTrustStorePassword());
208208
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/SslServerCustomizerTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,8 @@ public void alpnConnectionFactoryHasNullDefaultProtocolToAllowNegotiationToHttp1
8585
public void configureSslWhenSslIsEnabledWithNoKeyStoreThrowsWebServerException() {
8686
Ssl ssl = new Ssl();
8787
SslServerCustomizer customizer = new SslServerCustomizer(null, ssl, null, null);
88-
assertThatExceptionOfType(Exception.class)
89-
.isThrownBy(
90-
() -> customizer.configureSsl(new SslContextFactory(), ssl, null))
88+
assertThatExceptionOfType(Exception.class).isThrownBy(
89+
() -> customizer.configureSsl(new SslContextFactory.Server(), ssl, null))
9190
.satisfies((ex) -> {
9291
assertThat(ex).isInstanceOf(WebServerException.class);
9392
assertThat(ex)

0 commit comments

Comments
 (0)