@Test(expected = RuntimeException.class) public void ifFutureAbortsThenExecutionExceptionThrownAsRuntimeException() throws ExecutionException, InterruptedException { Future<AuthenticationResult> response = mock(Future.class); when(response.get()).thenThrow(ExecutionException.class); when(authenticationContext.acquireToken(anyString(), any(ClientCredential.class), any())).thenReturn(response); credentials.doAuthenticate("auth", "resource", null); }
@Override public String doAuthenticate(String authorization, String resource, String scope) { if(clientId == null || clientSecret == null) { throw new AzureCredentialNotSetException(AZURE_CLIENT_ID + " and " + AZURE_CLIENT_SECRET + " environment variables must be set"); } try { if(Objects.isNull(authenticationContext)) { this.authenticationContext = new AuthenticationContext(authorization, false, executorService); } ClientCredential credential = new ClientCredential(clientId, clientSecret); return authenticationContext.acquireToken(resource, credential, null).get().getAccessToken(); } catch (ExecutionException | MalformedURLException ex) { throw new RuntimeException(ex); } catch(InterruptedException ex) { LOGGER.warn("Key vault executor executorService interrupted"); throw new RuntimeException(ex); } }
AzureKeyVaultClientCredentials extends KeyVaultCredentials { @Override public String doAuthenticate(String authorization, String resource, String scope) { if(clientId == null || clientSecret == null) { throw new AzureCredentialNotSetException(AZURE_CLIENT_ID + " and " + AZURE_CLIENT_SECRET + " environment variables must be set"); } try { if(Objects.isNull(authenticationContext)) { this.authenticationContext = new AuthenticationContext(authorization, false, executorService); } ClientCredential credential = new ClientCredential(clientId, clientSecret); return authenticationContext.acquireToken(resource, credential, null).get().getAccessToken(); } catch (ExecutionException | MalformedURLException ex) { throw new RuntimeException(ex); } catch(InterruptedException ex) { LOGGER.warn("Key vault executor executorService interrupted"); throw new RuntimeException(ex); } } }
AzureKeyVaultClientCredentials extends KeyVaultCredentials { @Override public String doAuthenticate(String authorization, String resource, String scope) { if(clientId == null || clientSecret == null) { throw new AzureCredentialNotSetException(AZURE_CLIENT_ID + " and " + AZURE_CLIENT_SECRET + " environment variables must be set"); } try { if(Objects.isNull(authenticationContext)) { this.authenticationContext = new AuthenticationContext(authorization, false, executorService); } ClientCredential credential = new ClientCredential(clientId, clientSecret); return authenticationContext.acquireToken(resource, credential, null).get().getAccessToken(); } catch (ExecutionException | MalformedURLException ex) { throw new RuntimeException(ex); } catch(InterruptedException ex) { LOGGER.warn("Key vault executor executorService interrupted"); throw new RuntimeException(ex); } } AzureKeyVaultClientCredentials(String clientId, String clientSecret, ExecutorService executorService); }
AzureKeyVaultClientCredentials extends KeyVaultCredentials { @Override public String doAuthenticate(String authorization, String resource, String scope) { if(clientId == null || clientSecret == null) { throw new AzureCredentialNotSetException(AZURE_CLIENT_ID + " and " + AZURE_CLIENT_SECRET + " environment variables must be set"); } try { if(Objects.isNull(authenticationContext)) { this.authenticationContext = new AuthenticationContext(authorization, false, executorService); } ClientCredential credential = new ClientCredential(clientId, clientSecret); return authenticationContext.acquireToken(resource, credential, null).get().getAccessToken(); } catch (ExecutionException | MalformedURLException ex) { throw new RuntimeException(ex); } catch(InterruptedException ex) { LOGGER.warn("Key vault executor executorService interrupted"); throw new RuntimeException(ex); } } AzureKeyVaultClientCredentials(String clientId, String clientSecret, ExecutorService executorService); @Override String doAuthenticate(String authorization, String resource, String scope); @PreDestroy void onDestroy(); }
AzureKeyVaultClientCredentials extends KeyVaultCredentials { @Override public String doAuthenticate(String authorization, String resource, String scope) { if(clientId == null || clientSecret == null) { throw new AzureCredentialNotSetException(AZURE_CLIENT_ID + " and " + AZURE_CLIENT_SECRET + " environment variables must be set"); } try { if(Objects.isNull(authenticationContext)) { this.authenticationContext = new AuthenticationContext(authorization, false, executorService); } ClientCredential credential = new ClientCredential(clientId, clientSecret); return authenticationContext.acquireToken(resource, credential, null).get().getAccessToken(); } catch (ExecutionException | MalformedURLException ex) { throw new RuntimeException(ex); } catch(InterruptedException ex) { LOGGER.warn("Key vault executor executorService interrupted"); throw new RuntimeException(ex); } } AzureKeyVaultClientCredentials(String clientId, String clientSecret, ExecutorService executorService); @Override String doAuthenticate(String authorization, String resource, String scope); @PreDestroy void onDestroy();  }