@Test @DisplayName("validate auth with certificate throws exception when missing or invalid parameters") void acquireWithClientCertificateNullKey() throws CertificateException, OperatorCreationException, PKCSException, IOException, URISyntaxException { String certFilePath = Paths.get("src", "test", "resources", "cert.cer").toString(); String privateKeyPath = Paths.get("src", "test", "resources", "key.pem").toString(); X509Certificate x509Certificate = readPem(certFilePath, "basic").getCertificate(); PrivateKey privateKey = readPem(privateKeyPath, "basic").getKey(); ConnectionStringBuilder csb = ConnectionStringBuilder .createWithAadApplicationCertificate("resource.uri", "client-id", x509Certificate, privateKey); AadAuthenticationHelper aadAuthenticationHelper = new AadAuthenticationHelper(csb); Assertions.assertThrows(ExecutionException.class, () -> aadAuthenticationHelper.acquireWithClientCertificate()); }
AuthenticationResult acquireWithClientCertificate() throws InterruptedException, ExecutionException, ServiceUnavailableException { AuthenticationContext context; AuthenticationResult result = null; ExecutorService service = null; try { service = Executors.newSingleThreadExecutor(); context = new AuthenticationContext(aadAuthorityUri, false, service); AsymmetricKeyCredential asymmetricKeyCredential = AsymmetricKeyCredential.create(applicationClientId, privateKey, x509Certificate); result = context.acquireToken(clusterUrl, asymmetricKeyCredential, null).get(); } catch (MalformedURLException e) { e.printStackTrace(); } finally { if (service != null) { service.shutdown(); } } if (result == null) { throw new ServiceUnavailableException("authentication result was null"); } return result; }
AadAuthenticationHelper { AuthenticationResult acquireWithClientCertificate() throws InterruptedException, ExecutionException, ServiceUnavailableException { AuthenticationContext context; AuthenticationResult result = null; ExecutorService service = null; try { service = Executors.newSingleThreadExecutor(); context = new AuthenticationContext(aadAuthorityUri, false, service); AsymmetricKeyCredential asymmetricKeyCredential = AsymmetricKeyCredential.create(applicationClientId, privateKey, x509Certificate); result = context.acquireToken(clusterUrl, asymmetricKeyCredential, null).get(); } catch (MalformedURLException e) { e.printStackTrace(); } finally { if (service != null) { service.shutdown(); } } if (result == null) { throw new ServiceUnavailableException("authentication result was null"); } return result; } }
AadAuthenticationHelper { AuthenticationResult acquireWithClientCertificate() throws InterruptedException, ExecutionException, ServiceUnavailableException { AuthenticationContext context; AuthenticationResult result = null; ExecutorService service = null; try { service = Executors.newSingleThreadExecutor(); context = new AuthenticationContext(aadAuthorityUri, false, service); AsymmetricKeyCredential asymmetricKeyCredential = AsymmetricKeyCredential.create(applicationClientId, privateKey, x509Certificate); result = context.acquireToken(clusterUrl, asymmetricKeyCredential, null).get(); } catch (MalformedURLException e) { e.printStackTrace(); } finally { if (service != null) { service.shutdown(); } } if (result == null) { throw new ServiceUnavailableException("authentication result was null"); } return result; } AadAuthenticationHelper(@NotNull ConnectionStringBuilder csb); }
AadAuthenticationHelper { AuthenticationResult acquireWithClientCertificate() throws InterruptedException, ExecutionException, ServiceUnavailableException { AuthenticationContext context; AuthenticationResult result = null; ExecutorService service = null; try { service = Executors.newSingleThreadExecutor(); context = new AuthenticationContext(aadAuthorityUri, false, service); AsymmetricKeyCredential asymmetricKeyCredential = AsymmetricKeyCredential.create(applicationClientId, privateKey, x509Certificate); result = context.acquireToken(clusterUrl, asymmetricKeyCredential, null).get(); } catch (MalformedURLException e) { e.printStackTrace(); } finally { if (service != null) { service.shutdown(); } } if (result == null) { throw new ServiceUnavailableException("authentication result was null"); } return result; } AadAuthenticationHelper(@NotNull ConnectionStringBuilder csb);  }
AadAuthenticationHelper { AuthenticationResult acquireWithClientCertificate() throws InterruptedException, ExecutionException, ServiceUnavailableException { AuthenticationContext context; AuthenticationResult result = null; ExecutorService service = null; try { service = Executors.newSingleThreadExecutor(); context = new AuthenticationContext(aadAuthorityUri, false, service); AsymmetricKeyCredential asymmetricKeyCredential = AsymmetricKeyCredential.create(applicationClientId, privateKey, x509Certificate); result = context.acquireToken(clusterUrl, asymmetricKeyCredential, null).get(); } catch (MalformedURLException e) { e.printStackTrace(); } finally { if (service != null) { service.shutdown(); } } if (result == null) { throw new ServiceUnavailableException("authentication result was null"); } return result; } AadAuthenticationHelper(@NotNull ConnectionStringBuilder csb);   }