Skip to content

Commit 0ba192d

Browse files
committed
Merge branch '1.5.x'
2 parents 25c293b + 83fc4b3 commit 0ba192d

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected Server createJettyServer(JettyHttpHandlerAdapter servlet) {
147147
JettyReactiveWebServerFactory.logger
148148
.info("Server initialized with port: " + port);
149149
if (getSsl() != null && getSsl().isEnabled()) {
150-
customizeSsl(server, port);
150+
customizeSsl(server, address);
151151
}
152152
for (JettyServerCustomizer customizer : getServerCustomizers()) {
153153
customizer.customize(server);
@@ -189,8 +189,8 @@ private Handler applyWrapper(Handler handler, HandlerWrapper wrapper) {
189189
return wrapper;
190190
}
191191

192-
private void customizeSsl(Server server, int port) {
193-
new SslServerCustomizer(port, getSsl(), getSslStoreProvider(), getHttp2())
192+
private void customizeSsl(Server server, InetSocketAddress address) {
193+
new SslServerCustomizer(address, getSsl(), getSslStoreProvider(), getHttp2())
194194
.customize(server);
195195
}
196196

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public WebServer getWebServer(ServletContextInitializer... initializers) {
145145
server.setHandler(addHandlerWrappers(context));
146146
this.logger.info("Server initialized with port: " + port);
147147
if (getSsl() != null && getSsl().isEnabled()) {
148-
customizeSsl(server, port);
148+
customizeSsl(server, address);
149149
}
150150
for (JettyServerCustomizer customizer : getServerCustomizers()) {
151151
customizer.customize(server);
@@ -193,8 +193,8 @@ private Handler applyWrapper(Handler handler, HandlerWrapper wrapper) {
193193
return wrapper;
194194
}
195195

196-
private void customizeSsl(Server server, int port) {
197-
new SslServerCustomizer(port, getSsl(), getSslStoreProvider(), getHttp2())
196+
private void customizeSsl(Server server, InetSocketAddress address) {
197+
new SslServerCustomizer(address, getSsl(), getSslStoreProvider(), getHttp2())
198198
.customize(server);
199199
}
200200

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.boot.web.embedded.jetty;
1818

1919
import java.io.IOException;
20+
import java.net.InetSocketAddress;
2021
import java.net.URL;
2122

2223
import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory;
@@ -50,17 +51,17 @@
5051
*/
5152
class SslServerCustomizer implements JettyServerCustomizer {
5253

53-
private final int port;
54+
private final InetSocketAddress address;
5455

5556
private final Ssl ssl;
5657

5758
private final SslStoreProvider sslStoreProvider;
5859

5960
private final Http2 http2;
6061

61-
SslServerCustomizer(int port, Ssl ssl, SslStoreProvider sslStoreProvider,
62-
Http2 http2) {
63-
this.port = port;
62+
SslServerCustomizer(InetSocketAddress address, Ssl ssl,
63+
SslStoreProvider sslStoreProvider, Http2 http2) {
64+
this.address = address;
6465
this.ssl = ssl;
6566
this.sslStoreProvider = sslStoreProvider;
6667
this.http2 = http2;
@@ -70,20 +71,22 @@ class SslServerCustomizer implements JettyServerCustomizer {
7071
public void customize(Server server) {
7172
SslContextFactory sslContextFactory = new SslContextFactory();
7273
configureSsl(sslContextFactory, this.ssl, this.sslStoreProvider);
73-
ServerConnector connector = createConnector(server, sslContextFactory, this.port);
74+
ServerConnector connector = createConnector(server, sslContextFactory,
75+
this.address);
7476
server.setConnectors(new Connector[] { connector });
7577
}
7678

7779
private ServerConnector createConnector(Server server,
78-
SslContextFactory sslContextFactory, int port) {
80+
SslContextFactory sslContextFactory, InetSocketAddress address) {
7981
HttpConfiguration config = new HttpConfiguration();
8082
config.setSendServerVersion(false);
8183
config.setSecureScheme("https");
82-
config.setSecurePort(port);
84+
config.setSecurePort(address.getPort());
8385
config.addCustomizer(new SecureRequestCustomizer());
8486
ServerConnector connector = createServerConnector(server, sslContextFactory,
8587
config);
86-
connector.setPort(port);
88+
connector.setPort(address.getPort());
89+
connector.setHost(address.getHostString());
8790
return connector;
8891
}
8992

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,24 @@ public void specificIPAddressNotReverseResolved() throws Exception {
288288
.isEqualTo(localhost.getHostAddress());
289289
}
290290

291+
@Test
292+
public void specificIPAddressWithSslIsNotReverseResolved() throws Exception {
293+
JettyServletWebServerFactory factory = getFactory();
294+
InetAddress localhost = InetAddress.getLocalHost();
295+
factory.setAddress(InetAddress.getByAddress(localhost.getAddress()));
296+
Ssl ssl = new Ssl();
297+
ssl.setKeyStore("src/test/resources/test.jks");
298+
ssl.setKeyStorePassword("secret");
299+
ssl.setKeyPassword("password");
300+
factory.setSsl(ssl);
301+
this.webServer = factory.getWebServer();
302+
this.webServer.start();
303+
Connector connector = ((JettyWebServer) this.webServer).getServer()
304+
.getConnectors()[0];
305+
assertThat(((ServerConnector) connector).getHost())
306+
.isEqualTo(localhost.getHostAddress());
307+
}
308+
291309
@Override
292310
protected JspServlet getJspServlet() throws Exception {
293311
WebAppContext context = (WebAppContext) ((JettyWebServer) this.webServer)

0 commit comments

Comments
 (0)