[JCLOUDS-1006] Fix DockerUntrustedSSLContextSupplier to allow tests runs against endpoints without TLS configured
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/4e308868 Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/4e308868 Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/4e308868 Branch: refs/heads/master Commit: 4e308868bdb2eebf1ac6e61b9550be76597a1042 Parents: e21767d Author: Josef Cacek <[email protected]> Authored: Mon Sep 28 11:08:59 2015 +0200 Committer: Josef Cacek <[email protected]> Committed: Mon Sep 28 11:19:02 2015 +0200 ---------------------------------------------------------------------- .../suppliers/DockerUntrustedSSLContextSupplier.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds/blob/4e308868/apis/docker/src/main/java/org/jclouds/docker/suppliers/DockerUntrustedSSLContextSupplier.java ---------------------------------------------------------------------- diff --git a/apis/docker/src/main/java/org/jclouds/docker/suppliers/DockerUntrustedSSLContextSupplier.java b/apis/docker/src/main/java/org/jclouds/docker/suppliers/DockerUntrustedSSLContextSupplier.java index d0c9077..42efa13 100644 --- a/apis/docker/src/main/java/org/jclouds/docker/suppliers/DockerUntrustedSSLContextSupplier.java +++ b/apis/docker/src/main/java/org/jclouds/docker/suppliers/DockerUntrustedSSLContextSupplier.java @@ -24,10 +24,11 @@ import org.jclouds.location.Provider; import javax.inject.Inject; import javax.inject.Singleton; import javax.net.ssl.SSLContext; + +import java.io.File; import java.io.IOException; import java.security.GeneralSecurityException; -import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Throwables.propagate; @Singleton @@ -44,10 +45,13 @@ public class DockerUntrustedSSLContextSupplier implements Supplier<SSLContext> { @Override public SSLContext get() { - Credentials currentCreds = checkNotNull(creds.get(), "credential supplier returned null"); + Credentials currentCreds = creds.get(); try { SSLContextBuilder builder = new SSLContextBuilder(); - builder.clientKeyAndCertificate(currentCreds.credential, currentCreds.identity); + // check if identity and credential are files, to set up sslContext + if (currentCreds!=null && new File(currentCreds.identity).isFile() && new File(currentCreds.credential).isFile()) { + builder.clientKeyAndCertificate(currentCreds.credential, currentCreds.identity); + } builder.trustManager(insecureTrustManager); return builder.build(); } catch (GeneralSecurityException e) {
