Skip to content

Commit

Permalink
Updating custom SSLContext supplier with review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arankin-irl committed Jan 18, 2019
1 parent 874529b commit 69e0b6c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@ public int getSslHandshakeTimeoutMillis() {

@SuppressWarnings("unchecked")
public SSLContext createSSLContext(ZKConfig config) throws SSLContextException {
if (config.getProperty(sslContextSupplierClassProperty) != null) {
LOG.debug("Loading SSLContext supplier from property '" + sslContextSupplierClassProperty + "'");
String supplierContextClassName = config.getProperty(sslContextSupplierClassProperty);
final String supplierContextClassName = config.getProperty(sslContextSupplierClassProperty);
if (supplierContextClassName != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Loading SSLContext supplier from property '{}'", sslContextSupplierClassProperty);
}
try {
Class<?> sslContextClass = Class.forName(supplierContextClassName);
Supplier<SSLContext> sslContextSupplier = (Supplier<SSLContext>) sslContextClass.getConstructor().newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

package org.apache.zookeeper.common;

import org.apache.zookeeper.Environment;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
import org.apache.zookeeper.server.util.VerifyingFileFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -32,6 +26,12 @@
import java.util.Map.Entry;
import java.util.Properties;

import org.apache.zookeeper.Environment;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;
import org.apache.zookeeper.server.util.VerifyingFileFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* This class is a base class for the configurations of both client and server.
* It supports reading client configuration from both system properties and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

@RunWith(Parameterized.class)
Expand Down Expand Up @@ -419,18 +419,18 @@ public void testCreateSSLContext_invalidCustomSSLContextClass() throws Exception
public void testCreateSSLContext_validNullCustomSSLContextClass() throws X509Exception.SSLContextException {
ZKConfig zkConfig = new ZKConfig();
ClientX509Util clientX509Util = new ClientX509Util();
zkConfig.setProperty(clientX509Util.getSslContextSupplierClassProperty(), X509UtilTest.class.getCanonicalName() + "$" + NullSslContextSupplier.class.getSimpleName());
zkConfig.setProperty(clientX509Util.getSslContextSupplierClassProperty(), NullSslContextSupplier.class.getName());
final SSLContext sslContext = clientX509Util.createSSLContext(zkConfig);
assertNull(sslContext);
}

@Test
public void testCreateSSLContext_validCustomSSLContextClass() throws X509Exception.SSLContextException {
public void testCreateSSLContext_validCustomSSLContextClass() throws Exception {
ZKConfig zkConfig = new ZKConfig();
ClientX509Util clientX509Util = new ClientX509Util();
zkConfig.setProperty(clientX509Util.getSslContextSupplierClassProperty(), X509UtilTest.class.getCanonicalName() + "$" + SslContextSupplier.class.getSimpleName());
zkConfig.setProperty(clientX509Util.getSslContextSupplierClassProperty(), SslContextSupplier.class.getName());
final SSLContext sslContext = clientX509Util.createSSLContext(zkConfig);
assertNotNull(sslContext);
assertEquals(SSLContext.getDefault(), sslContext);
}

private static void forceClose(Socket s) {
Expand Down Expand Up @@ -535,7 +535,7 @@ public SSLContext get() {
try {
return SSLContext.getDefault();
} catch (NoSuchAlgorithmException e) {
return null;
throw new RuntimeException(e);
}
}

Expand Down

0 comments on commit 69e0b6c

Please sign in to comment.