Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE:195 Provide SSL support to SchemaRegistryClient #221

Merged
merged 1 commit into from
Aug 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.11</junit.version>
<junit.version>4.12</junit.version>
<snakeyaml.version>1.15</snakeyaml.version>
<jackson.version>2.7.3</jackson.version>
<commons-cli.version>1.3.1</commons-cli.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.hortonworks.registries.schemaregistry.serde.pull.PullSerializer;
import com.hortonworks.registries.schemaregistry.serde.push.PushDeserializer;
import org.apache.commons.io.IOUtils;
import org.glassfish.jersey.SslConfigurator;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.media.multipart.BodyPart;
Expand All @@ -59,6 +60,8 @@
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.security.auth.Subject;
import javax.security.auth.login.LoginException;
import javax.ws.rs.NotFoundException;
Expand Down Expand Up @@ -171,6 +174,9 @@ public class SchemaRegistryClient implements ISchemaRegistryClient {
private final SchemaMetadataCache schemaMetadataCache;
private final Cache<SchemaDigestEntry, SchemaIdVersion> schemaTextCache;

private static final String SSL_CONFIGURATION_KEY = "schema.registry.client.ssl";
private static final String HOSTNAME_VERIFIER_CLASS_KEY = "hostnameVerifierClass";

/**
* Creates {@link SchemaRegistryClient} instance with the given yaml config.
* @param confFile config file which contains the configuration entries.
Expand All @@ -190,10 +196,24 @@ public SchemaRegistryClient(Map<String, ?> conf) {
configuration = new Configuration(conf);

ClientConfig config = createClientConfig(conf);
client = ClientBuilder.newBuilder()
ClientBuilder clientBuilder = ClientBuilder.newBuilder()
.withConfig(config)
.property(ClientProperties.FOLLOW_REDIRECTS, Boolean.TRUE)
.build();
.property(ClientProperties.FOLLOW_REDIRECTS, Boolean.TRUE);
if(conf.containsKey(SSL_CONFIGURATION_KEY)) {
Map<String,String> sslConfigurations = (Map<String, String>) conf.get(SSL_CONFIGURATION_KEY);
clientBuilder.sslContext(createSSLContext(sslConfigurations));
if(sslConfigurations.containsKey(HOSTNAME_VERIFIER_CLASS_KEY)) {
HostnameVerifier hostNameVerifier= null;
String hostNameVerifierClassName = sslConfigurations.get(HOSTNAME_VERIFIER_CLASS_KEY);
try {
hostNameVerifier = (HostnameVerifier) Class.forName(hostNameVerifierClassName).newInstance();
} catch (Exception e) {
throw new RuntimeException("Failed to instantiate hostNameVerifierClass : "+hostNameVerifierClassName, e);
}
clientBuilder.hostnameVerifier(hostNameVerifier);
}
}
client = clientBuilder.build();
client.register(MultiPartFeature.class);

// get list of urls and create given or default UrlSelector.
Expand Down Expand Up @@ -228,6 +248,27 @@ public SchemaVersionInfo retrieveSchemaVersion(SchemaIdVersion key) throws Schem
.build();
}

protected SSLContext createSSLContext(Map<String, String> sslConfigurations) {
SslConfigurator sslConfigurator = SslConfigurator.newInstance();
String keyPassword = "keyPassword";
sslConfigurator.keyStoreType(sslConfigurations.get("keyStoreType"))
.keyStoreFile(sslConfigurations.get("keyStorePath"))
.keyStorePassword(sslConfigurations.get("keyStorePassword"))
.trustStoreType(sslConfigurations.get("trustStoreType"))
.trustStoreFile(sslConfigurations.get("trustStorePath"))
.trustStorePassword(sslConfigurations.get("trustStorePassword"))
.keyStoreProvider(sslConfigurations.get("keyStoreProvider"))
.trustStoreProvider(sslConfigurations.get("trustStoreProvider"))
.keyManagerFactoryAlgorithm(sslConfigurations.get("keyManagerFactoryAlgorithm"))
.keyManagerFactoryProvider(sslConfigurations.get("keyManagerFactoryProvider"))
.trustManagerFactoryAlgorithm(sslConfigurations.get("trustManagerFactoryAlgorithm"))
.trustManagerFactoryProvider(sslConfigurations.get("trustManagerFactoryProvider"))
.securityProtocol(sslConfigurations.get("protocol"));
if(sslConfigurations.containsKey(keyPassword))
sslConfigurator.keyPassword(sslConfigurations.get(keyPassword));
return sslConfigurator.createSSLContext();
}

private SchemaRegistryTargets currentSchemaRegistryTargets() {
String url = urlSelector.select();
urlWithTargets.computeIfAbsent(url, s -> new SchemaRegistryTargets(client.target(s)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,21 @@ schema.registry.client.schema.version.cache.expiry.interval : 300
schema.registry.client.schema.metadata.cache.expiry.interval : 300
schema.registry.client.schema.text.cache.size : 1024
schema.registry.client.schema.text.cache.expiry.interval : 300
schema.registry.client.url.selector : "com.hortonworks.registries.schemaregistry.client.FailoverUrlSelector"
schema.registry.client.url.selector : "com.hortonworks.registries.schemaregistry.client.FailoverUrlSelector"

#schema.registry.client.ssl:
# protocol: SSL
# hostnameVerifierClass:
# keyStoreType:
# keyStorePath:
# keyStorePassword:
# keyStoreProvider:
# keyPassword:
# keyManagerFactoryProvider:
# keyManagerFactoryAlgorithm:
# trustStoreType:
# trustStorePath:
# trustStorePassword:
# trustStoreProvider:
# trustManagerFactoryProvider:
# trustManagerFactoryAlgorithm:
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public int getAdminPort() {
return registryApplication.getAdminPort();
}

public String getLocalURL() {
return registryApplication.localServer.getURI().toString();
}

/**
* Returns true if this server is the leader in registry cluster.
*/
Expand Down
Loading