Skip to content

Commit de17979

Browse files
authored
Merge pull request #7633 from scottaddie/scottaddie/dac-java
Update Java credential chains doc for 1.17.0 release
2 parents 3d5f74b + 1107ea7 commit de17979

6 files changed

+43
-17
lines changed

articles/java/sdk/authentication/credential-chains.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: 'Credential chains in the Azure Identity library for Java'
33
description: 'This article describes the DefaultAzureCredential and ChainedTokenCredential classes in the Azure Identity library.'
4-
ms.date: 06/02/2025
4+
ms.date: 08/05/2025
55
ms.topic: article
66
author: KarlErickson
77
ms.author: karler
@@ -70,20 +70,24 @@ The order in which `DefaultAzureCredential` attempts credentials follows.
7070
| 1 | [Environment][env-cred] | Reads a collection of [environment variables][env-vars] to determine if an application service principal (application user) is configured for the app. If so, `DefaultAzureCredential` uses these values to authenticate the app to Azure. This method is most often used in server environments but can also be used when developing locally. |
7171
| 2 | [Workload Identity][wi-cred] | If the app is deployed to an Azure host with Workload Identity enabled, authenticate that account. |
7272
| 3 | [Managed Identity][mi-cred] | If the app is deployed to an Azure host with Managed Identity enabled, authenticate the app to Azure using that Managed Identity. |
73-
| 4 | [Shared Token Cache][stc-cred] | If the developer authenticated to Azure by logging into Visual Studio, authenticate the app to Azure using that same account. (Windows only.) |
74-
| 5 | [IntelliJ][ij-cred] | If the developer authenticated via Azure Toolkit for IntelliJ, authenticate that account. |
73+
| 4 | [IntelliJ][ij-cred] | If the developer authenticated via Azure Toolkit for IntelliJ, authenticate that account. |
74+
| 5 | [Visual Studio Code][vsc-cred] | If the developer authenticated via Visual Studio Code's [Azure Resources extension][vsc-ext] and the [azure-identity-broker package][broker-pkg] is installed, authenticate that account. |
7575
| 6 | [Azure CLI][az-cred] | If the developer authenticated to Azure using Azure CLI's `az login` command, authenticate the app to Azure using that same account. |
7676
| 7 | [Azure PowerShell][pwsh-cred] | If the developer authenticated to Azure using Azure PowerShell's `Connect-AzAccount` cmdlet, authenticate the app to Azure using that same account. |
7777
| 8 | [Azure Developer CLI][azd-cred] | If the developer authenticated to Azure using Azure Developer CLI's `azd auth login` command, authenticate with that account. |
78+
| 9 | [Broker][broker-cred] | Authenticates using the default account logged into the OS via a broker. Requires that the [azure-identity-broker package][broker-pkg] is installed, since a broker-enabled instance of `InteractiveBrowserCredential` is used. |
7879
7980
[env-cred]: /java/api/com.azure.identity.environmentcredential
8081
[wi-cred]: /java/api/com.azure.identity.workloadidentitycredential
8182
[mi-cred]: /java/api/com.azure.identity.managedidentitycredential
82-
[stc-cred]: /java/api/com.azure.identity.sharedtokencachecredential
8383
[az-cred]: /java/api/com.azure.identity.azureclicredential
8484
[pwsh-cred]: /java/api/com.azure.identity.azurepowershellcredential
8585
[azd-cred]: /java/api/com.azure.identity.azuredeveloperclicredential
8686
[ij-cred]: /java/api/com.azure.identity.intellijcredential
87+
[vsc-cred]: /java/api/com.azure.identity.visualstudiocodecredential
88+
[broker-cred]: /java/api/com.azure.identity.interactivebrowsercredential
89+
[vsc-ext]: https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureresourcegroups
90+
[broker-pkg]: https://central.sonatype.com/artifact/com.azure/azure-identity-broker
8791
8892
In its simplest form, you can use the parameterless version of `DefaultAzureCredential` as follows:
8993
@@ -99,6 +103,10 @@ DefaultAzureCredential credential = new DefaultAzureCredentialBuilder()
99103
100104
### How to customize DefaultAzureCredential
101105
106+
The following sections describe strategies for controlling which credentials are included in the chain.
107+
108+
#### Exclude a credential type category
109+
102110
To exclude all `Developer tool` or `Deployed service` credentials, set environment variable `AZURE_TOKEN_CREDENTIALS` to `prod` or `dev`, respectively. When a value of `prod` is used, the underlying credential chain looks as follows:
103111
104112
:::image type="content" source="../media/mermaidjs/default-azure-credential-environment-variable-production.svg" alt-text="Diagram that shows DefaultAzureCredential with AZURE_TOKEN_CREDENTIALS set to 'prod'.":::
@@ -110,6 +118,22 @@ When a value of `dev` is used, the chain looks as follows:
110118
> [!IMPORTANT]
111119
> The `AZURE_TOKEN_CREDENTIALS` environment variable is supported in `azure-identity` package versions 1.16.1 and later.
112120
121+
#### Use a specific credential
122+
123+
To exclude all credentials except for one, set environment variable `AZURE_TOKEN_CREDENTIALS` to the credential name. For example, you can reduce the `DefaultAzureCredential` chain to `AzureCliCredential` by setting `AZURE_TOKEN_CREDENTIALS` to `AzureCliCredential`. The string comparison is performed in a case-insensitive manner. Valid string values for the environment variable include:
124+
125+
- `AzureCliCredential`
126+
- `AzureDeveloperCliCredential`
127+
- `AzurePowerShellCredential`
128+
- `EnvironmentCredential`
129+
- `IntelliJCredential`
130+
- `ManagedIdentityCredential`
131+
- `VisualStudioCodeCredential`
132+
- `WorkloadIdentityCredential`
133+
134+
> [!IMPORTANT]
135+
> The `AZURE_TOKEN_CREDENTIALS` environment variable supports individual credential names in `azure-identity` package versions 1.17.0 and later.
136+
113137
## ChainedTokenCredential overview
114138
115139
[ChainedTokenCredential](/java/api/com.azure.identity.chainedtokencredential) is an empty chain to which you add credentials to suit your app's needs. For example:
@@ -163,14 +187,13 @@ For illustration purposes, assume the parameterless form of `DefaultAzureCredent
163187
[main] INFO com.azure.identity.ChainedTokenCredential - Azure Identity => Attempted credential WorkloadIdentityCredential is unavailable.
164188
[ForkJoinPool.commonPool-worker-1] WARN com.microsoft.aad.msal4j.ConfidentialClientApplication - [Correlation ID: aaaa0000-bb11-2222-33cc-444444dddddd] Execution of class com.microsoft.aad.msal4j.AcquireTokenByClientCredentialSupplier failed: java.util.concurrent.ExecutionException: com.azure.identity.CredentialUnavailableException: ManagedIdentityCredential authentication unavailable. Connection to IMDS endpoint cannot be established.
165189
[main] INFO com.azure.identity.ChainedTokenCredential - Azure Identity => Attempted credential ManagedIdentityCredential is unavailable.
166-
[main] INFO com.azure.identity.ChainedTokenCredential - Azure Identity => Attempted credential SharedTokenCacheCredential is unavailable.
167190
[main] INFO com.azure.identity.ChainedTokenCredential - Azure Identity => Attempted credential IntelliJCredential is unavailable.
168191
[main] INFO com.azure.identity.ChainedTokenCredential - Azure Identity => Attempted credential AzureCliCredential returns a token
169192
```
170193

171194
In the preceding output, notice that:
172195

173-
- `EnvironmentCredential`, `WorkloadIdentityCredential`, `ManagedIdentityCredential`, `SharedTokenCacheCredential`, and `IntelliJCredential` each failed to acquire a Microsoft Entra access token, in that order.
196+
- `EnvironmentCredential`, `WorkloadIdentityCredential`, `ManagedIdentityCredential`, and `IntelliJCredential` each failed to acquire a Microsoft Entra access token, in that order.
174197
- The `AzureCliCredential.getToken` call succeeds, as indicated by the `returns a token`-suffixed entry. Since `AzureCliCredential` succeeded, no credentials beyond it were tried.
175198

176199
<!-- LINKS -->
-319 Bytes
Loading

0 commit comments

Comments
 (0)