Skip to content

Commit

Permalink
Move setup of hosted specific 4443 connector to new class
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorncs committed Aug 21, 2019
1 parent f5c9952 commit 2ea2314
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import com.yahoo.osgi.provider.model.ComponentModel;
import com.yahoo.prelude.fastsearch.FS4ResourcePool;
import com.yahoo.vespa.model.container.component.Component;
import com.yahoo.vespa.model.container.http.ConnectorFactory;
import com.yahoo.vespa.model.container.http.Http;
import com.yahoo.vespa.model.container.http.JettyHttpServer;
import com.yahoo.vespa.model.container.http.ssl.ConfiguredDirectSslProvider;
import com.yahoo.vespa.model.container.http.ssl.HostedSslConnectorFactory;

import java.util.Optional;

Expand All @@ -35,22 +34,15 @@ public ApplicationContainer(AbstractConfigProducer parent, String name, boolean
this.isHostedVespa = isHostedVespa;

if (isHostedVespa && tlsSecrets.isPresent()) {
String connectorName = "tls4443";

JettyHttpServer server = Optional.ofNullable(getHttp())
.map(Http::getHttpServer)
.orElse(getDefaultHttpServer());

var sslProvider = new ConfiguredDirectSslProvider(
server.getComponentId().getName(),
tlsSecrets.get().key(),
tlsSecrets.get().certificate(),
null,
tlsCa.orElse(null),
null
);

server.addConnector(new ConnectorFactory(connectorName, 4443, sslProvider));
String serverName = server.getComponentId().getName();
var connectorFactory = tlsCa
.map(caCert -> new HostedSslConnectorFactory(serverName, tlsSecrets.get(), caCert))
.orElseGet(() -> new HostedSslConnectorFactory(serverName, tlsSecrets.get()));
server.addConnector(connectorFactory);
}
addComponent(getFS4ResourcePool()); // TODO Remove when FS4 based search protocol is gone
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.container.http.ssl;

import com.yahoo.config.model.api.TlsSecrets;
import com.yahoo.vespa.model.container.http.ConnectorFactory;

/**
* Component specification for {@link com.yahoo.jdisc.http.server.jetty.ConnectorFactory} with hosted specific configuration.
*
* @author bjorncs
*/
public class HostedSslConnectorFactory extends ConnectorFactory {

public HostedSslConnectorFactory(String serverName, TlsSecrets tlsSecrets) {
this(serverName, tlsSecrets, null);
}

public HostedSslConnectorFactory(String serverName, TlsSecrets tlsSecrets, String tlsCaCertificates) {
super("tls4443", 4443, createSslProvider(serverName, tlsSecrets, tlsCaCertificates));
}

private static ConfiguredDirectSslProvider createSslProvider(
String serverName, TlsSecrets tlsSecrets, String tlsCaCertificates) {
return new ConfiguredDirectSslProvider(
serverName,
tlsSecrets.key(),
tlsSecrets.certificate(),
/*caCertificatePath*/null,
tlsCaCertificates,
"disabled");
}

}

0 comments on commit 2ea2314

Please sign in to comment.