From e6313d99092650f693c75336a90d0fff96fe5b3f Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Tue, 11 Jun 2019 14:02:20 +0200 Subject: Use Default SSLContext when none is set --- .../src/main/java/ai/vespa/hosted/auth/Authenticator.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tenant-auth') diff --git a/tenant-auth/src/main/java/ai/vespa/hosted/auth/Authenticator.java b/tenant-auth/src/main/java/ai/vespa/hosted/auth/Authenticator.java index 0242d0f891b..33c1d09c828 100644 --- a/tenant-auth/src/main/java/ai/vespa/hosted/auth/Authenticator.java +++ b/tenant-auth/src/main/java/ai/vespa/hosted/auth/Authenticator.java @@ -14,6 +14,7 @@ import java.net.http.HttpRequest; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.cert.X509Certificate; import java.time.Instant; @@ -32,7 +33,11 @@ public class Authenticator { * "key" and "cert" in that directory are used; otherwise, the system default SSLContext is returned. */ public SSLContext sslContext() { try { - Path credentialsRoot = Path.of(System.getProperty("vespa.test.credentials.root")); + Optional credentialsRootProperty = getNonBlankProperty("vespa.test.credentials.root"); + if (credentialsRootProperty.isEmpty()) + return SSLContext.getDefault(); + + Path credentialsRoot = Path.of(credentialsRootProperty.get()); Path certificateFile = credentialsRoot.resolve("cert"); Path privateKeyFile = credentialsRoot.resolve("key"); @@ -47,6 +52,9 @@ public class Authenticator { } catch (IOException e) { throw new UncheckedIOException(e); } + catch (NoSuchAlgorithmException e) { + throw new IllegalStateException(e); + } } /** Adds necessary authentication to the given HTTP request builder, to be verified by a Vespa endpoint. */ -- cgit v1.2.3