com.microsoft.azure.keyvault.KeyVaultClient Java Examples
The following examples show how to use
com.microsoft.azure.keyvault.KeyVaultClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyVault.java From remote-monitoring-services-java with MIT License | 6 votes |
public KeyVault(String name, String clientId, String clientSecret) { this.name = name; this.clientId = clientId; this.clientSecret = clientSecret; this.keyVaultClient = new KeyVaultClient(createCredentials()); this.getAllKeys(); }
Example #2
Source File: RangerKeyStore.java From ranger with Apache License 2.0 | 5 votes |
public RangerKeyStore(DaoManager daoManager, Configuration conf, KeyVaultClient kvClient) { this.daoManager = daoManager; this.kvKeyGen = new RangerKeyVaultKeyGenerator(conf, kvClient); if(conf != null && StringUtils.isNotEmpty(conf .get(AZURE_KEYVAULT_ENABLED)) && conf.get(AZURE_KEYVAULT_ENABLED).equalsIgnoreCase( "true")){ azureKeyVaultEnabled = true; } }
Example #3
Source File: KeyVault.java From remote-monitoring-services-java with MIT License | 5 votes |
public KeyVault(String name, String clientId, String clientSecret) { this.name = name; this.clientId = clientId; this.clientSecret = clientSecret; this.keyVaultClient = new KeyVaultClient(createCredentials()); this.getAllKeys(); }
Example #4
Source File: RangerKeyVaultKeyGenerator.java From ranger with Apache License 2.0 | 5 votes |
public RangerKeyVaultKeyGenerator(Configuration conf, KeyVaultClient kvClient) { this.keyVaultURL = conf.get(AZURE_KEYVAULT_URL); this.azureMasterKey = conf.get(AZURE_MASTER_KEY_ALIAS); this.azureMasterKeyType = conf.get(AZURE_MASTER_KEY_TYPE); this.zoneKeyEncryptionAlgo = conf.get(ZONE_KEY_ENCRYPTION_ALGO); this.keyVaultClient = kvClient; }
Example #5
Source File: TestAzureKeyVaultCredentialStore.java From datacollector with Apache License 2.0 | 5 votes |
@Test public void testAzureKeyVaultCredentialValueOptions() throws StageException { AzureKeyVaultCredentialStore store = new AzureKeyVaultCredentialStore(); CredentialStore.Context context = Mockito.mock(CredentialStore.Context.class); store = Mockito.spy(store); KeyVaultClient keyVaultClient = PowerMockito.mock(KeyVaultClient.class); Mockito.doReturn(keyVaultClient).when(store).createClient(); Mockito.when(keyVaultClient.getSecret(Mockito.any(), Mockito.any())).thenReturn(new SecretBundle()); Mockito.when(context.getConfig(Mockito.any())).thenReturn("test"); Configuration configuration = Mockito.mock(Configuration.class); Mockito.doReturn(configuration).when(store).getConfiguration(); Mockito.when(configuration.get(AzureKeyVaultCredentialStore.CREDENTIAL_REFRESH_PROP, AzureKeyVaultCredentialStore.CREDENTIAL_REFRESH_DEFAULT )) .thenReturn(AzureKeyVaultCredentialStore.CREDENTIAL_REFRESH_DEFAULT); Mockito.when(configuration.get(AzureKeyVaultCredentialStore.CREDENTIAL_RETRY_PROP, AzureKeyVaultCredentialStore.CREDENTIAL_RETRY_DEFAULT )) .thenReturn(AzureKeyVaultCredentialStore.CREDENTIAL_RETRY_DEFAULT); Mockito.when(context.getConfig(store.CACHE_EXPIRATION_PROP)).thenReturn(null); Assert.assertTrue(store.init(context).isEmpty()); CredentialValue c = store.get("g", "n", "refresh=1,retry=2"); Assert.assertNotNull(c); AzureKeyVaultCredentialStore.AzureKeyVaultCredentialValue cc = (AzureKeyVaultCredentialStore.AzureKeyVaultCredentialValue) c; Assert.assertEquals(1L, cc.getRefreshMillis()); Assert.assertEquals(2L, cc.getRetryMillis()); store.destroy(); }
Example #6
Source File: TestAzureKeyVaultCredentialStore.java From datacollector with Apache License 2.0 | 5 votes |
@Test public void testInit_noIssues() { AzureKeyVaultCredentialStore store = new AzureKeyVaultCredentialStore(); CredentialStore.Context context = Mockito.mock(CredentialStore.Context.class); store = Mockito.spy(store); KeyVaultClient keyVaultClient = PowerMockito.mock(KeyVaultClient.class); Mockito.doReturn(keyVaultClient).when(store).createClient(); Mockito.when(keyVaultClient.getSecret(Mockito.any(), Mockito.any())).thenReturn(new SecretBundle()); Mockito.when(context.getConfig(Mockito.any())).thenReturn("test"); Configuration configuration = Mockito.mock(Configuration.class); Mockito.doReturn(configuration).when(store).getConfiguration(); Mockito.when(configuration.get(AzureKeyVaultCredentialStore.CREDENTIAL_REFRESH_PROP, AzureKeyVaultCredentialStore.CREDENTIAL_REFRESH_DEFAULT )) .thenReturn(AzureKeyVaultCredentialStore.CREDENTIAL_REFRESH_DEFAULT); Mockito.when(configuration.get(AzureKeyVaultCredentialStore.CREDENTIAL_RETRY_PROP, AzureKeyVaultCredentialStore.CREDENTIAL_RETRY_DEFAULT )) .thenReturn(AzureKeyVaultCredentialStore.CREDENTIAL_RETRY_DEFAULT); Mockito.when(context.getConfig(store.CACHE_EXPIRATION_PROP)).thenReturn(null); Assert.assertEquals(0, store.init(context).size()); }
Example #7
Source File: TestAzureKeyVaultCredentialStore.java From datacollector with Apache License 2.0 | 5 votes |
@Test public void testInit_nullConfigs() { AzureKeyVaultCredentialStore store = new AzureKeyVaultCredentialStore(); CredentialStore.Context context = Mockito.mock(CredentialStore.Context.class); store = Mockito.spy(store); KeyVaultClient keyVaultClient = PowerMockito.mock(KeyVaultClient.class); Mockito.doReturn(keyVaultClient).when(store).createClient(); Mockito.when(context.getConfig(Mockito.any())).thenReturn(null); Assert.assertEquals(3, store.init(context).size()); }
Example #8
Source File: TestAzureKeyVaultCredentialStore.java From datacollector with Apache License 2.0 | 5 votes |
@Test public void testInit_emptyConfigs() { AzureKeyVaultCredentialStore store = new AzureKeyVaultCredentialStore(); CredentialStore.Context context = Mockito.mock(CredentialStore.Context.class); store = Mockito.spy(store); KeyVaultClient keyVaultClient = PowerMockito.mock(KeyVaultClient.class); Mockito.doReturn(keyVaultClient).when(store).createClient(); Mockito.when(context.getConfig(Mockito.any())).thenReturn(""); Assert.assertEquals(3, store.init(context).size()); }
Example #9
Source File: KeyVaultClientIntegrationTestBase.java From azure-keyvault-java with MIT License | 5 votes |
protected void initializeClients(RestClient restClient, String s, String s1) throws IOException { try { RestClient restClientWithTimeout = buildRestClient(new RestClient.Builder() .withBaseUrl("https://{vaultBaseUrl}").withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withCredentials(createTestCredentials()).withLogLevel(LogLevel.BODY_AND_HEADERS) .withNetworkInterceptor(interceptorManager.initInterceptor())); createTestCredentials(); keyVaultClient = new KeyVaultClient(restClientWithTimeout); // keyVaultClient = new KeyVaultClient(restClient); } catch (Exception e) { e.printStackTrace(); } }
Example #10
Source File: KeyVaultKey.java From azure-keyvault-java with MIT License | 5 votes |
protected KeyVaultKey(KeyVaultClient client, KeyBundle keyBundle) { if (client == null) { throw new IllegalArgumentException("client"); } if (keyBundle == null) { throw new IllegalArgumentException("keyBundle"); } JsonWebKey key = keyBundle.key(); if (key == null) { throw new IllegalArgumentException("keyBundle must contain a key"); } if (key.kty().equals(JsonWebKeyType.RSA)) { // The private key is not available for KeyVault keys implementation = new RsaKey(key.kid(), key.toRSA(false)); } else if (key.kty().equals(JsonWebKeyType.RSA_HSM)) { // The private key is not available for KeyVault keys implementation = new RsaKey(key.kid(), key.toRSA(false)); } if (implementation == null) { throw new IllegalArgumentException(String.format("The key type %s is not supported", key.kty())); } this.client = client; }
Example #11
Source File: VaultImpl.java From azure-libraries-for-java with MIT License | 5 votes |
VaultImpl(String key, VaultInner innerObject, KeyVaultManager manager, GraphRbacManager graphRbacManager) { super(key, innerObject, manager); this.graphRbacManager = graphRbacManager; this.accessPolicies = new ArrayList<>(); if (innerObject != null && innerObject.properties() != null && innerObject.properties().accessPolicies() != null) { for (AccessPolicyEntry entry : innerObject.properties().accessPolicies()) { this.accessPolicies.add(new AccessPolicyImpl(entry, this)); } } this.client = new KeyVaultClient( manager.inner().restClient().newBuilder().withBaseUrl("https://{vaultBaseUrl}").build()); }
Example #12
Source File: AzureKeyVaultStore.java From data-transfer-project with Apache License 2.0 | 5 votes |
public AzureKeyVaultStore( String keyVaultName, String tenantId, String clientId, String clientSecret) { vaultUrl = String.format(VAULT_ADDRESS, keyVaultName); ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(clientId, tenantId, clientSecret, AzureEnvironment.AZURE); vaultClient = new KeyVaultClient(credentials); }
Example #13
Source File: KeyVault.java From remote-monitoring-services-java with MIT License | 5 votes |
public KeyVault(String name, String clientId, String clientSecret) { this.name = name; this.clientId = clientId; this.clientSecret = clientSecret; this.keyVaultClient = new KeyVaultClient(createCredentials()); this.getAllKeys(); }
Example #14
Source File: KeyVault.java From remote-monitoring-services-java with MIT License | 5 votes |
public KeyVault(String name, String clientId, String clientSecret) { this.name = name; this.clientId = clientId; this.clientSecret = clientSecret; this.keyVaultClient = new KeyVaultClient(createCredentials()); this.getAllKeys(); }
Example #15
Source File: VaultImpl.java From azure-libraries-for-java with MIT License | 4 votes |
@Override public KeyVaultClient client() { return client; }
Example #16
Source File: SecretsImpl.java From azure-libraries-for-java with MIT License | 4 votes |
SecretsImpl(KeyVaultClient client, Vault vault) { this.inner = client; this.vault = vault; }
Example #17
Source File: KeyVaultKeyResolver.java From azure-keyvault-java with MIT License | 4 votes |
/** * Constructor. * @param client the key vault client */ public KeyVaultKeyResolver(KeyVaultClient client) { this.client = client; this.provider = null; }
Example #18
Source File: KeysImpl.java From azure-libraries-for-java with MIT License | 4 votes |
KeysImpl(KeyVaultClient client, Vault vault) { this.inner = client; this.vault = vault; }
Example #19
Source File: AzureKms.java From sfs with Apache License 2.0 | 4 votes |
protected KeyVaultClient createKeyVaultClient(VertxContext<Server> vertxContext) throws Exception { Configuration config = createConfiguration(vertxContext); return create(config); }
Example #20
Source File: AzureKeyVaultCredentialStore.java From datacollector with Apache License 2.0 | 4 votes |
@VisibleForTesting protected KeyVaultClient createClient() { AzureKeyVaultClientFactory azureKeyVaultClientFactory = new AzureKeyVaultClientFactoryImpl(); return new KeyVaultClient(azureKeyVaultClientFactory.create(clientID, clientKey)); }
Example #21
Source File: AzureKeyVaultCredentialStore.java From datacollector with Apache License 2.0 | 4 votes |
@VisibleForTesting protected KeyVaultClient getAzureClient() { return client; }
Example #22
Source File: AzureKeyVaultClientDelegate.java From tessera with Apache License 2.0 | 4 votes |
AzureKeyVaultClientDelegate(KeyVaultClient keyVaultClient) { this.keyVaultClient = Objects.requireNonNull(keyVaultClient); }
Example #23
Source File: AzureKeyVaultClientFactory.java From tessera with Apache License 2.0 | 4 votes |
KeyVaultClient getAuthenticatedClient() { return new KeyVaultClient(clientCredentials); }
Example #24
Source File: TestAzureKeyVaultCredentialStore.java From datacollector with Apache License 2.0 | 4 votes |
@Test public void testCache() throws StageException, InterruptedException { AzureKeyVaultCredentialStore store = new AzureKeyVaultCredentialStore(); CredentialStore.Context context = Mockito.mock(CredentialStore.Context.class); store = Mockito.spy(store); KeyVaultClient keyVaultClient = PowerMockito.mock(KeyVaultClient.class); Mockito.doReturn(keyVaultClient).when(store).createClient(); SecretBundle secretBundle = Mockito.mock(SecretBundle.class); Mockito.when(secretBundle.value()).thenReturn("secret"); Mockito.when(keyVaultClient.getSecret(Mockito.any(), Mockito.any())).thenReturn(secretBundle); Mockito.when(context.getConfig(Mockito.any())).thenReturn("test"); Configuration configuration = Mockito.mock(Configuration.class); Mockito.doReturn(configuration).when(store).getConfiguration(); Mockito.when(configuration.get(AzureKeyVaultCredentialStore.CREDENTIAL_REFRESH_PROP, AzureKeyVaultCredentialStore.CREDENTIAL_REFRESH_DEFAULT )) .thenReturn(AzureKeyVaultCredentialStore.CREDENTIAL_REFRESH_DEFAULT); Mockito.when(configuration.get(AzureKeyVaultCredentialStore.CREDENTIAL_RETRY_PROP, AzureKeyVaultCredentialStore.CREDENTIAL_RETRY_DEFAULT )) .thenReturn(AzureKeyVaultCredentialStore.CREDENTIAL_RETRY_DEFAULT); Mockito.when(context.getConfig(store.CACHE_EXPIRATION_PROP)).thenReturn(null); Assert.assertTrue(store.init(context).isEmpty()); CredentialValue credential1 = store.get("g", "n", "a=A,b=B"); Assert.assertNotNull(credential1); Assert.assertEquals("secret", credential1.get()); //within cache time CredentialValue credential2 = store.get("g", "n", "a=A,b=B"); Assert.assertEquals(((AzureKeyVaultCredentialStore.AzureKeyVaultCredentialValue) credential1).getName(), ((AzureKeyVaultCredentialStore.AzureKeyVaultCredentialValue) credential2).getName() ); Assert.assertEquals(((AzureKeyVaultCredentialStore.AzureKeyVaultCredentialValue) credential1).getOptions(), ((AzureKeyVaultCredentialStore.AzureKeyVaultCredentialValue) credential2).getOptions() ); Assert.assertEquals(((AzureKeyVaultCredentialStore.AzureKeyVaultCredentialValue) credential1).getGroup(), ((AzureKeyVaultCredentialStore.AzureKeyVaultCredentialValue) credential2).getGroup() ); Thread.sleep(201); //outside cache time. CredentialValue credential3 = store.get("g", "n", "a=A,b=B"); Assert.assertNotSame(credential1, credential3); store.destroy(); }
Example #25
Source File: KeyVaultKeyResolver.java From azure-keyvault-java with MIT License | 2 votes |
/** * Constructor. * @param client the key vault client * @param provider the java security provider */ public KeyVaultKeyResolver(KeyVaultClient client, Provider provider) { this.client = client; this.provider = provider; }
Example #26
Source File: Vault.java From azure-libraries-for-java with MIT License | 2 votes |
/** * @return an authenticated Key Vault data client */ @Beta(SinceVersion.V1_6_0) KeyVaultClient client();