Search in sources :

Example 1 with ClientSecretCredential

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());
    }
}
Also used : ClientSecretCredentialBuilder(com.azure.identity.ClientSecretCredentialBuilder) SQLServerException(com.microsoft.sqlserver.jdbc.SQLServerException) ClientSecretCredential(com.azure.identity.ClientSecretCredential) SQLServerColumnEncryptionAzureKeyVaultProvider(com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Tag(org.junit.jupiter.api.Tag)

Example 2 with ClientSecretCredential

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;
}
Also used : SystemCredentialsProvider(com.cloudbees.plugins.credentials.SystemCredentialsProvider) ClientSecretCredentialBuilder(com.azure.identity.ClientSecretCredentialBuilder) ClientSecretCredential(com.azure.identity.ClientSecretCredential) ManagedIdentityCredentialBuilder(com.azure.identity.ManagedIdentityCredentialBuilder)

Example 3 with ClientSecretCredential

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());
    }
}
Also used : ClientSecretCredentialBuilder(com.azure.identity.ClientSecretCredentialBuilder) SQLServerException(com.microsoft.sqlserver.jdbc.SQLServerException) ClientSecretCredential(com.azure.identity.ClientSecretCredential) SQLServerColumnEncryptionAzureKeyVaultProvider(com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource) Tag(org.junit.jupiter.api.Tag)

Example 4 with ClientSecretCredential

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);
}
Also used : KeyVaultSecret(com.azure.security.keyvault.secrets.models.KeyVaultSecret) ClientSecretCredentialBuilder(com.azure.identity.ClientSecretCredentialBuilder) ClientSecretCredential(com.azure.identity.ClientSecretCredential) SecretClient(com.azure.security.keyvault.secrets.SecretClient)

Aggregations

ClientSecretCredential (com.azure.identity.ClientSecretCredential)4 ClientSecretCredentialBuilder (com.azure.identity.ClientSecretCredentialBuilder)4 SQLServerColumnEncryptionAzureKeyVaultProvider (com.microsoft.sqlserver.jdbc.SQLServerColumnEncryptionAzureKeyVaultProvider)2 SQLServerException (com.microsoft.sqlserver.jdbc.SQLServerException)2 Tag (org.junit.jupiter.api.Tag)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 ManagedIdentityCredentialBuilder (com.azure.identity.ManagedIdentityCredentialBuilder)1 SecretClient (com.azure.security.keyvault.secrets.SecretClient)1 KeyVaultSecret (com.azure.security.keyvault.secrets.models.KeyVaultSecret)1 SystemCredentialsProvider (com.cloudbees.plugins.credentials.SystemCredentialsProvider)1