Skip to content

Commit 4f75a7b

Browse files
authored
Identity updates (Azure#36208)
1 parent 3e4a8c2 commit 4f75a7b

File tree

10 files changed

+38
-13
lines changed

10 files changed

+38
-13
lines changed

eng/code-quality-reports/src/main/resources/checkstyle/checkstyle-suppressions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ the main ServiceBusClientBuilder. -->
567567
<!-- Field additionallyAllowedTenants is not set in constructor and can be changed using the builder option. -->
568568
<suppress checks="com.azure.tools.checkstyle.checks.EnforceFinalFieldsCheck" files="com.azure.identity.DefaultAzureCredentialBuilder"/>
569569

570-
<suppress checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" files=".*(DeviceCodeCredential|InteractiveBrowserCredential|AzureCliCredential|AzureDeveloperCliCredential|ClientCertificateCredential|ClientSecretCredential|EnvironmentCredential|OnBehalfOfCredential|ChainedTokenCredential|ClientAssertionCredential|UsernamePasswordCredential).java"/>
570+
<suppress checks="com.azure.tools.checkstyle.checks.ThrowFromClientLoggerCheck" files=".*(DeviceCodeCredential|InteractiveBrowserCredential|AzureCliCredential|AzureDeveloperCliCredential|ClientCertificateCredential|ClientSecretCredential|EnvironmentCredential|OnBehalfOfCredential|WorkloadIdentityCredential|ChainedTokenCredential|ClientAssertionCredential|UsernamePasswordCredential).java"/>
571571

572572
<suppress checks="com.azure.tools.checkstyle.checks.EnforceFinalFieldsCheck" files="com.azure.search.documents.indexes.models.SynonymMap"/>
573573

eng/versioning/external_dependencies.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ com.microsoft.azure:azure-mgmt-resources;1.3.0
190190
com.microsoft.azure:azure-mgmt-search;1.24.1
191191
com.microsoft.azure:azure-mgmt-storage;1.3.0
192192
com.microsoft.azure:azure-storage;8.0.0
193-
com.microsoft.azure:msal4j;1.13.8
193+
com.microsoft.azure:msal4j;1.13.9
194194
com.microsoft.azure:msal4j-persistence-extension;1.2.0
195195
com.sun.activation:jakarta.activation;1.2.2
196196
io.opentelemetry:opentelemetry-api;1.28.0

sdk/eventhubs/microsoft-azure-eventhubs-eph/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<dependency>
6565
<groupId>com.microsoft.azure</groupId>
6666
<artifactId>msal4j</artifactId>
67-
<version>1.13.8</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
67+
<version>1.13.9</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
6868
<scope>test</scope>
6969
</dependency>
7070
<dependency>

sdk/eventhubs/microsoft-azure-eventhubs-extensions/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
<dependency>
6969
<groupId>com.microsoft.azure</groupId>
7070
<artifactId>msal4j</artifactId>
71-
<version>1.13.8</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
71+
<version>1.13.9</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
7272
<scope>test</scope>
7373
</dependency>
7474
<dependency>

sdk/eventhubs/microsoft-azure-eventhubs/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<dependency>
7878
<groupId>com.microsoft.azure</groupId>
7979
<artifactId>msal4j</artifactId>
80-
<version>1.13.8</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
80+
<version>1.13.9</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
8181
<scope>test</scope>
8282
</dependency>
8383
<dependency>

sdk/identity/azure-identity/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<dependency>
4444
<groupId>com.microsoft.azure</groupId>
4545
<artifactId>msal4j</artifactId>
46-
<version>1.13.8</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
46+
<version>1.13.9</version> <!-- {x-version-update;com.microsoft.azure:msal4j;external_dependency} -->
4747
</dependency>
4848
<dependency>
4949
<groupId>com.microsoft.azure</groupId>
@@ -128,7 +128,7 @@
128128
<rules>
129129
<bannedDependencies>
130130
<includes>
131-
<include>com.microsoft.azure:msal4j:[1.13.8]</include> <!-- {x-include-update;com.microsoft.azure:msal4j;external_dependency} -->
131+
<include>com.microsoft.azure:msal4j:[1.13.9]</include> <!-- {x-include-update;com.microsoft.azure:msal4j;external_dependency} -->
132132
<include>com.microsoft.azure:msal4j-persistence-extension:[1.2.0]</include> <!-- {x-include-update;com.microsoft.azure:msal4j-persistence-extension;external_dependency} -->
133133
<include>net.java.dev.jna:jna-platform:[5.6.0]</include> <!-- {x-include-update;net.java.dev.jna:jna-platform;external_dependency} -->
134134
<include>org.linguafranca.pwdb:KeePassJava2:[2.1.4]</include> <!-- {x-include-update;org.linguafranca.pwdb:KeePassJava2;external_dependency} -->

sdk/identity/azure-identity/src/main/java/com/azure/identity/WorkloadIdentityCredential.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.azure.identity.implementation.IdentityClientBuilder;
1414
import com.azure.identity.implementation.IdentityClientOptions;
1515
import com.azure.identity.implementation.IdentitySyncClient;
16+
import com.azure.identity.implementation.util.LoggingUtil;
1617
import com.azure.identity.implementation.util.ValidationUtil;
1718
import reactor.core.publisher.Mono;
1819

@@ -56,6 +57,8 @@ public class WorkloadIdentityCredential implements TokenCredential {
5657
private static final ClientLogger LOGGER = new ClientLogger(WorkloadIdentityCredential.class);
5758
private final IdentityClient identityClient;
5859
private final IdentitySyncClient identitySyncClient;
60+
private final IdentityClientOptions identityClientOptions;
61+
5962

6063
/**
6164
* WorkloadIdentityCredential supports Azure workload identity on Kubernetes.
@@ -86,7 +89,7 @@ public class WorkloadIdentityCredential implements TokenCredential {
8689
|| CoreUtils.isNullOrEmpty(identityClientOptions.getAuthorityHost()))) {
8790
IdentityClientBuilder builder = new IdentityClientBuilder()
8891
.clientAssertionPath(federatedTokenFilePathInput)
89-
.clientId(clientId)
92+
.clientId(clientIdInput)
9093
.tenantId(tenantIdInput)
9194
.identityClientOptions(identityClientOptions);
9295
identityClient = builder.build();
@@ -95,12 +98,14 @@ public class WorkloadIdentityCredential implements TokenCredential {
9598
identityClient = null;
9699
identitySyncClient = null;
97100
}
101+
this.identityClientOptions = identityClientOptions;
98102
}
99103

100104
@Override
101105
public Mono<AccessToken> getToken(TokenRequestContext request) {
102106
if (identityClient == null) {
103-
return Mono.error(LOGGER.logExceptionAsError(new CredentialUnavailableException("WorkloadIdentityCredential"
107+
return Mono.error(LoggingUtil.logCredentialUnavailableException(LOGGER, identityClientOptions,
108+
new CredentialUnavailableException("WorkloadIdentityCredential"
104109
+ " authentication unavailable. The workload options are not fully configured. See the troubleshooting"
105110
+ " guide for more information."
106111
+ " https://aka.ms/azsdk/java/identity/workloadidentitycredential/troubleshoot")));
@@ -111,7 +116,8 @@ public Mono<AccessToken> getToken(TokenRequestContext request) {
111116
@Override
112117
public AccessToken getTokenSync(TokenRequestContext request) {
113118
if (identitySyncClient == null) {
114-
throw LOGGER.logExceptionAsError(new CredentialUnavailableException("WorkloadIdentityCredential"
119+
throw LoggingUtil.logCredentialUnavailableException(LOGGER, identityClientOptions,
120+
new CredentialUnavailableException("WorkloadIdentityCredential"
115121
+ " authentication unavailable. The workload options are not fully configured. See the troubleshooting"
116122
+ " guide for more information."
117123
+ " https://aka.ms/azsdk/java/identity/workloadidentitycredential/troubleshoot"));

sdk/identity/azure-identity/src/main/java/com/azure/identity/WorkloadIdentityCredentialBuilder.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33

44
package com.azure.identity;
55

6+
import com.azure.core.util.Configuration;
7+
import com.azure.core.util.CoreUtils;
68
import com.azure.core.util.logging.ClientLogger;
79
import com.azure.identity.implementation.util.ValidationUtil;
810

11+
import static com.azure.identity.ManagedIdentityCredential.AZURE_FEDERATED_TOKEN_FILE;
12+
913
/**
1014
* Fluent credential builder for instantiating a {@link WorkloadIdentityCredential}.
1115
*
@@ -69,9 +73,22 @@ public WorkloadIdentityCredentialBuilder tokenFilePath(String tokenFilePath) {
6973
* @return a {@link WorkloadIdentityCredential} with the current configurations.
7074
*/
7175
public WorkloadIdentityCredential build() {
72-
ValidationUtil.validate(this.getClass().getSimpleName(), LOGGER, "Client ID", clientId,
73-
"Tenant ID", tenantId, "Service Token File Path", tokenFilePath);
76+
Configuration configuration = identityClientOptions.getConfiguration() == null
77+
? Configuration.getGlobalConfiguration().clone() : identityClientOptions.getConfiguration();
78+
79+
String tenantIdInput = CoreUtils.isNullOrEmpty(tenantId)
80+
? configuration.get(Configuration.PROPERTY_AZURE_TENANT_ID) : tenantId;
81+
82+
String federatedTokenFilePathInput = CoreUtils.isNullOrEmpty(tokenFilePath)
83+
? configuration.get(AZURE_FEDERATED_TOKEN_FILE) : tokenFilePath;
84+
85+
String clientIdInput = CoreUtils.isNullOrEmpty(clientId)
86+
? configuration.get(Configuration.PROPERTY_AZURE_CLIENT_ID) : clientId;
87+
88+
ValidationUtil.validate(this.getClass().getSimpleName(), LOGGER, "Client ID", clientIdInput,
89+
"Tenant ID", tenantIdInput, "Service Token File Path", federatedTokenFilePathInput);
7490

75-
return new WorkloadIdentityCredential(tenantId, clientId, tokenFilePath, identityClientOptions.clone());
91+
return new WorkloadIdentityCredential(tenantIdInput, clientIdInput, federatedTokenFilePathInput,
92+
identityClientOptions.clone());
7693
}
7794
}

sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClientBase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ ConfidentialClientApplication getManagedIdentityConfidentialClient() {
347347
: clientId, credential);
348348

349349
applicationBuilder
350+
.instanceDiscovery(false)
350351
.validateAuthority(false)
351352
.logPii(options.isSupportLoggingEnabled());
352353

sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ private void mockForManagedIdentityFlow(String secret, String clientId, TokenReq
513513
});
514514
when(builder.logPii(anyBoolean())).thenReturn(builder);
515515
when(builder.validateAuthority(anyBoolean())).thenReturn(builder);
516+
when(builder.instanceDiscovery(anyBoolean())).thenReturn(builder);
516517
when(builder.build()).thenReturn(application);
517518
})) {
518519
// Mocking the static builder to ensure we pass the right thing to it.

0 commit comments

Comments
 (0)