@Test public void getCredentialsUsingInjectedParameters() throws Exception { Future<AuthenticationResult> response = mock(Future.class); AuthenticationResult authenticationResult = new AuthenticationResult(null,"accessToken",null,0L,null,null,false); when(response.get()).thenReturn(authenticationResult); when(authenticationContext.acquireToken(anyString(), any(ClientCredential.class), any())).thenReturn(response); String result = credentials.doAuthenticate("auth","resource",null); assertThat(result).isEqualTo("accessToken"); verify(authenticationContext).acquireToken(anyString(), any(ClientCredential.class), any()); Mockito.verifyNoMoreInteractions(authenticationContext); }
@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();  }