Merge branch '1.5.x'

pull/12272/head
Andy Wilkinson 7 years ago
commit 0ba192dead

@ -147,7 +147,7 @@ public class JettyReactiveWebServerFactory extends AbstractReactiveWebServerFact
JettyReactiveWebServerFactory.logger
.info("Server initialized with port: " + port);
if (getSsl() != null && getSsl().isEnabled()) {
customizeSsl(server, port);
customizeSsl(server, address);
}
for (JettyServerCustomizer customizer : getServerCustomizers()) {
customizer.customize(server);
@ -189,8 +189,8 @@ public class JettyReactiveWebServerFactory extends AbstractReactiveWebServerFact
return wrapper;
}
private void customizeSsl(Server server, int port) {
new SslServerCustomizer(port, getSsl(), getSslStoreProvider(), getHttp2())
private void customizeSsl(Server server, InetSocketAddress address) {
new SslServerCustomizer(address, getSsl(), getSslStoreProvider(), getHttp2())
.customize(server);
}

@ -145,7 +145,7 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
server.setHandler(addHandlerWrappers(context));
this.logger.info("Server initialized with port: " + port);
if (getSsl() != null && getSsl().isEnabled()) {
customizeSsl(server, port);
customizeSsl(server, address);
}
for (JettyServerCustomizer customizer : getServerCustomizers()) {
customizer.customize(server);
@ -193,8 +193,8 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
return wrapper;
}
private void customizeSsl(Server server, int port) {
new SslServerCustomizer(port, getSsl(), getSslStoreProvider(), getHttp2())
private void customizeSsl(Server server, InetSocketAddress address) {
new SslServerCustomizer(address, getSsl(), getSslStoreProvider(), getHttp2())
.customize(server);
}

@ -17,6 +17,7 @@
package org.springframework.boot.web.embedded.jetty;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URL;
import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory;
@ -50,7 +51,7 @@ import org.springframework.util.ResourceUtils;
*/
class SslServerCustomizer implements JettyServerCustomizer {
private final int port;
private final InetSocketAddress address;
private final Ssl ssl;
@ -58,9 +59,9 @@ class SslServerCustomizer implements JettyServerCustomizer {
private final Http2 http2;
SslServerCustomizer(int port, Ssl ssl, SslStoreProvider sslStoreProvider,
Http2 http2) {
this.port = port;
SslServerCustomizer(InetSocketAddress address, Ssl ssl,
SslStoreProvider sslStoreProvider, Http2 http2) {
this.address = address;
this.ssl = ssl;
this.sslStoreProvider = sslStoreProvider;
this.http2 = http2;
@ -70,20 +71,22 @@ class SslServerCustomizer implements JettyServerCustomizer {
public void customize(Server server) {
SslContextFactory sslContextFactory = new SslContextFactory();
configureSsl(sslContextFactory, this.ssl, this.sslStoreProvider);
ServerConnector connector = createConnector(server, sslContextFactory, this.port);
ServerConnector connector = createConnector(server, sslContextFactory,
this.address);
server.setConnectors(new Connector[] { connector });
}
private ServerConnector createConnector(Server server,
SslContextFactory sslContextFactory, int port) {
SslContextFactory sslContextFactory, InetSocketAddress address) {
HttpConfiguration config = new HttpConfiguration();
config.setSendServerVersion(false);
config.setSecureScheme("https");
config.setSecurePort(port);
config.setSecurePort(address.getPort());
config.addCustomizer(new SecureRequestCustomizer());
ServerConnector connector = createServerConnector(server, sslContextFactory,
config);
connector.setPort(port);
connector.setPort(address.getPort());
connector.setHost(address.getHostString());
return connector;
}

@ -288,6 +288,24 @@ public class JettyServletWebServerFactoryTests
.isEqualTo(localhost.getHostAddress());
}
@Test
public void specificIPAddressWithSslIsNotReverseResolved() throws Exception {
JettyServletWebServerFactory factory = getFactory();
InetAddress localhost = InetAddress.getLocalHost();
factory.setAddress(InetAddress.getByAddress(localhost.getAddress()));
Ssl ssl = new Ssl();
ssl.setKeyStore("src/test/resources/test.jks");
ssl.setKeyStorePassword("secret");
ssl.setKeyPassword("password");
factory.setSsl(ssl);
this.webServer = factory.getWebServer();
this.webServer.start();
Connector connector = ((JettyWebServer) this.webServer).getServer()
.getConnectors()[0];
assertThat(((ServerConnector) connector).getHost())
.isEqualTo(localhost.getHostAddress());
}
@Override
protected JspServlet getJspServlet() throws Exception {
WebAppContext context = (WebAppContext) ((JettyWebServer) this.webServer)

Loading…
Cancel
Save