use of com.azure.identity.ClientSecretCredential in project mssql-jdbc by Microsoft.
the class JDBCEncryptionDecryptionTest method testAkvNameWithTokenCredential.
@ParameterizedTest
@MethodSource("enclaveParams")
@Tag(Constants.reqExternalSetup)
public void testAkvNameWithTokenCredential(String serverName, String url, String protocol) throws Exception {
setAEConnectionString(serverName, url, protocol);
ClientSecretCredential credential = new ClientSecretCredentialBuilder().tenantId(tenantID).clientId(applicationClientID).clientSecret(applicationKey).build();
try {
SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(credential);
String keystoreName = "keystoreName";
akv.setName(keystoreName);
assertTrue(akv.getName().equals(keystoreName));
} catch (SQLServerException e) {
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}
}
use of com.azure.identity.ClientSecretCredential in project azure-credentials-plugin by jenkinsci.
the class AzureCredentials method getSystemCredentialById.
/**
* Only checks the system provider for credentials.
* Use if you need to bypass other providers, e.g. in a credential provider.
*/
public static TokenCredential getSystemCredentialById(String credentialID) {
if (StringUtils.isEmpty(credentialID)) {
return null;
}
SystemCredentialsProvider systemCredentialsProvider = SystemCredentialsProvider.getInstance();
List<AzureImdsCredentials> azureImdsCredentials = DomainCredentials.getCredentials(systemCredentialsProvider.getDomainCredentialsMap(), AzureImdsCredentials.class, Collections.emptyList(), CredentialsMatchers.withId(credentialID));
if (!azureImdsCredentials.isEmpty()) {
return new ManagedIdentityCredentialBuilder().build();
}
List<AzureCredentials> azureCredentials = DomainCredentials.getCredentials(systemCredentialsProvider.getDomainCredentialsMap(), AzureCredentials.class, Collections.emptyList(), CredentialsMatchers.withId(credentialID));
ClientSecretCredential credential = null;
if (!azureCredentials.isEmpty()) {
AzureCredentials azureCredential = azureCredentials.get(0);
credential = new ClientSecretCredentialBuilder().clientId(azureCredential.getClientId()).clientSecret(azureCredential.getPlainClientSecret()).httpClient(HttpClientRetriever.get()).tenantId(azureCredential.getTenant()).build();
}
if (credential == null) {
throw new RuntimeException(String.format("Credential: %s was not found for supported credentials " + "type.", credentialID));
}
return credential;
}
use of com.azure.identity.ClientSecretCredential in project mssql-jdbc by microsoft.
the class JDBCEncryptionDecryptionTest method testAkvNameWithTokenCredential.
@ParameterizedTest
@MethodSource("enclaveParams")
@Tag(Constants.reqExternalSetup)
public void testAkvNameWithTokenCredential(String serverName, String url, String protocol) throws Exception {
setAEConnectionString(serverName, url, protocol);
ClientSecretCredential credential = new ClientSecretCredentialBuilder().tenantId(tenantID).clientId(applicationClientID).clientSecret(applicationKey).build();
try {
SQLServerColumnEncryptionAzureKeyVaultProvider akv = new SQLServerColumnEncryptionAzureKeyVaultProvider(credential);
String keystoreName = "keystoreName";
akv.setName(keystoreName);
assertTrue(akv.getName().equals(keystoreName));
} catch (SQLServerException e) {
fail(TestResource.getResource("R_unexpectedException") + e.getMessage());
}
}
use of com.azure.identity.ClientSecretCredential in project azure-credentials-plugin by jenkinsci.
the class KeyVaultIntegrationTestBase method createSecret.
protected KeyVaultSecret createSecret(final String name, final String value) {
KeyVaultSecret keyVaultSecret = new KeyVaultSecret(name, value);
ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder().clientId(testEnv.clientId).clientSecret(testEnv.clientSecret).tenantId(testEnv.tenantId).build();
SecretClient secretClient = AzureCredentials.createKeyVaultClient(clientSecretCredential, vaultUri);
return secretClient.setSecret(keyVaultSecret);
}
Aggregations