Merge pull request #12120 from Marcos Trejo Munguia

* gh-12120:
  Polish "Set host when creating Jetty SSL connector"
  Set host when creating Jetty SSL connector
pull/11991/merge
Andy Wilkinson 7 years ago
commit 83fc4b3246

@ -180,7 +180,7 @@ public class JettyEmbeddedServletContainerFactory
SslContextFactory sslContextFactory = new SslContextFactory();
configureSsl(sslContextFactory, getSsl());
AbstractConnector connector = getSslServerConnectorFactory()
.getConnector(server, sslContextFactory, port);
.createConnector(server, sslContextFactory, address);
server.setConnectors(new Connector[] { connector });
}
for (JettyServerCustomizer customizer : getServerCustomizers()) {
@ -700,8 +700,8 @@ public class JettyEmbeddedServletContainerFactory
*/
private interface SslServerConnectorFactory {
AbstractConnector getConnector(Server server, SslContextFactory sslContextFactory,
int port);
AbstractConnector createConnector(Server server,
SslContextFactory sslContextFactory, InetSocketAddress address);
}
@ -712,8 +712,8 @@ public class JettyEmbeddedServletContainerFactory
implements SslServerConnectorFactory {
@Override
public ServerConnector getConnector(Server server,
SslContextFactory sslContextFactory, int port) {
public ServerConnector createConnector(Server server,
SslContextFactory sslContextFactory, InetSocketAddress address) {
HttpConfiguration config = new HttpConfiguration();
config.setSendServerVersion(false);
config.addCustomizer(new SecureRequestCustomizer());
@ -722,7 +722,8 @@ public class JettyEmbeddedServletContainerFactory
sslContextFactory, HttpVersion.HTTP_1_1.asString());
ServerConnector serverConnector = new ServerConnector(server,
sslConnectionFactory, connectionFactory);
serverConnector.setPort(port);
serverConnector.setPort(address.getPort());
serverConnector.setHost(address.getHostString());
return serverConnector;
}
@ -735,8 +736,8 @@ public class JettyEmbeddedServletContainerFactory
implements SslServerConnectorFactory {
@Override
public AbstractConnector getConnector(Server server,
SslContextFactory sslContextFactory, int port) {
public AbstractConnector createConnector(Server server,
SslContextFactory sslContextFactory, InetSocketAddress address) {
try {
Class<?> connectorClass = Class
.forName("org.eclipse.jetty.server.ssl.SslSocketConnector");
@ -744,7 +745,9 @@ public class JettyEmbeddedServletContainerFactory
.getConstructor(SslContextFactory.class)
.newInstance(sslContextFactory);
connector.getClass().getMethod("setPort", int.class).invoke(connector,
port);
address.getPort());
connector.getClass().getMethod("setHost", String.class).invoke(connector,
address.getHostString());
return connector;
}
catch (Exception ex) {

@ -244,6 +244,27 @@ public class JettyEmbeddedServletContainerFactoryTests
.isEqualTo(new String[] { "TLSv1.1" });
}
@Test
public void sslEnabledSpecificIPAddress() throws Exception {
Ssl ssl = new Ssl();
ssl.setKeyStore("src/test/resources/test.jks");
ssl.setKeyStorePassword("secret");
ssl.setKeyPassword("password");
JettyEmbeddedServletContainerFactory factory = getFactory();
factory.setSsl(ssl);
factory.setAddress(
InetAddress.getByAddress(InetAddress.getLocalHost().getAddress()));
this.container = factory.getEmbeddedServletContainer();
this.container.start();
JettyEmbeddedServletContainer jettyContainer = (JettyEmbeddedServletContainer) this.container;
ServerConnector connector = (ServerConnector) jettyContainer.getServer()
.getConnectors()[0];
assertThat(connector.getHost()).isEqualTo(factory.getAddress().getHostAddress());
}
private void assertTimeout(JettyEmbeddedServletContainerFactory factory,
int expected) {
this.container = factory.getEmbeddedServletContainer();

Loading…
Cancel
Save