All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.azure.identity.DefaultAzureCredential Maven / Gradle / Ivy

The newest version!
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.identity;

import com.azure.core.annotation.Immutable;
import com.azure.core.credential.TokenCredential;

import java.util.List;

/**
 * 

DefaultAzureCredential simplifies authentication while developing apps that deploy to Azure by combining credentials * used in Azure hosting environments with credentials used in local development. In production, it's better to use something * else. For more information, see Usage guidance for DefaultAzureCredential. * *

Attempts to authenticate with each of these credentials, in the following order, stopping when one provides a token:

* *
    *
  1. {@link EnvironmentCredential}
  2. *
  3. {@link WorkloadIdentityCredential}
  4. *
  5. {@link ManagedIdentityCredential}
  6. *
  7. {@link SharedTokenCacheCredential}
  8. *
  9. {@link IntelliJCredential}
  10. *
  11. {@link AzureCliCredential}
  12. *
  13. {@link AzurePowerShellCredential}
  14. *
  15. {@link AzureDeveloperCliCredential}
  16. *
* *

Consult the documentation of these credentials for more information on how they attempt authentication.

* *

Configure DefaultAzureCredential

* *

DefaultAzureCredential supports a set of configurations through setters on the * {@link DefaultAzureCredentialBuilder} or environment variables.

* *
    *
  1. Setting the environment variables {@code AZURE_CLIENT_ID}, * {@code AZURE_CLIENT_SECRET/AZURE_CLIENT_CERTIFICATE_PATH}, and {@code AZURE_TENANT_ID} configures the * DefaultAzureCredential to authenticate as the service principal specified by the values.
  2. *
  3. Setting {@link DefaultAzureCredentialBuilder#managedIdentityClientId(String)} on the builder or the * environment variable AZURE_CLIENT_ID configures the DefaultAzureCredential to authenticate as a user-defined * managed identity, while leaving them empty configures it to authenticate as a system-assigned managed identity. *
  4. *
  5. Setting {@link DefaultAzureCredentialBuilder#tenantId(String)} on the builder or the environment * variable {@code AZURE_TENANT_ID} configures the DefaultAzureCredential to authenticate to a specific tenant for * Visual Studio Code, and IntelliJ IDEA.
  6. *
* *

Sample: Construct DefaultAzureCredential

* *

The following code sample demonstrates the creation of a DefaultAzureCredential, using * the {@link com.azure.identity.DefaultAzureCredentialBuilder} to configure it. Once this credential is created, it * may be passed into the builder of many of the Azure SDK for Java client builders as the 'credential' parameter.

* * *
 * TokenCredential defaultAzureCredential = new DefaultAzureCredentialBuilder().build();
 * 
* * *

Sample: Construct DefaultAzureCredential with User Assigned Managed Identity

* *

User-Assigned Managed Identity (UAMI) in Azure is a feature that allows you to create an identity in * Microsoft Entra ID that is * associated with one or more Azure resources. This identity can then be used to authenticate and * authorize access to various Azure services and resources. The following code sample demonstrates the creation of * a DefaultAzureCredential to target a user assigned managed identity, using the * {@link com.azure.identity.DefaultAzureCredentialBuilder} to configure it. Once this credential is created, it * may be passed into the builder of many of the Azure SDK for Java client builders as the 'credential' parameter.

* * *
 * TokenCredential dacWithUserAssignedManagedIdentity
 *     = new DefaultAzureCredentialBuilder().managedIdentityClientId("<Managed-Identity-Client-Id").build();
 * 
* * * @see com.azure.identity * @see DefaultAzureCredentialBuilder * @see ManagedIdentityCredential * @see EnvironmentCredential * @see ClientSecretCredential * @see ClientCertificateCredential * @see UsernamePasswordCredential * @see AzureCliCredential * @see IntelliJCredential */ @Immutable public final class DefaultAzureCredential extends ChainedTokenCredential { /** * Creates default DefaultAzureCredential instance to use. * * @param tokenCredentials the list of credentials to execute for authentication. */ DefaultAzureCredential(List tokenCredentials) { super(tokenCredentials); this.enableUseCachedWorkingCredential(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy