File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed
sdk/identity/azure-identity/src
main/java/com/azure/identity
test/java/com/azure/identity Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ class ArcIdentityCredential extends ManagedIdentityServiceCredential {
4242 * @return A publisher that emits an {@link AccessToken}.
4343 */
4444 public Mono <AccessToken > authenticate (TokenRequestContext request ) {
45- if (getClientId () = = null ) {
45+ if (getClientId () ! = null ) {
4646 return Mono .error (logger .logExceptionAsError (new ClientAuthenticationException (
4747 "User assigned identity is not supported by the Azure Arc Managed Identity Endpoint. To authenticate "
4848 + "with the system assigned identity omit the client id when constructing the"
Original file line number Diff line number Diff line change @@ -43,12 +43,12 @@ public final class ManagedIdentityCredential implements TokenCredential {
4343 managedIdentityServiceCredential = new AppServiceMsiCredential (clientId , identityClient );
4444 } else if (configuration .contains (Configuration .PROPERTY_IDENTITY_ENDPOINT )) {
4545 if (configuration .contains (Configuration .PROPERTY_IDENTITY_HEADER )) {
46- if (configuration .contains (PROPERTY_IDENTITY_SERVER_THUMBPRINT )) {
46+ if (configuration .get (PROPERTY_IDENTITY_SERVER_THUMBPRINT ) != null ) {
4747 managedIdentityServiceCredential = new ServiceFabricMsiCredential (clientId , identityClient );
4848 } else {
4949 managedIdentityServiceCredential = new VirtualMachineMsiCredential (clientId , identityClient );
5050 }
51- } else if (configuration .contains (PROPERTY_IMDS_ENDPOINT )) {
51+ } else if (configuration .get (PROPERTY_IMDS_ENDPOINT ) != null ) {
5252 managedIdentityServiceCredential = new ArcIdentityCredential (clientId , identityClient );
5353 } else {
5454 managedIdentityServiceCredential = new VirtualMachineMsiCredential (clientId , identityClient );
Original file line number Diff line number Diff line change 44package com .azure .identity ;
55
66import com .azure .core .credential .TokenRequestContext ;
7+ import com .azure .core .exception .ClientAuthenticationException ;
78import com .azure .core .util .Configuration ;
89import com .azure .identity .implementation .IdentityClient ;
910import com .azure .identity .util .TestUtils ;
@@ -86,4 +87,24 @@ public void testIMDS() throws Exception {
8687 && expiresOn .getSecond () == token .getExpiresAt ().getSecond ())
8788 .verifyComplete ();
8889 }
90+
91+ @ Test
92+ public void testArcUserAssigned () throws Exception {
93+ Configuration configuration = Configuration .getGlobalConfiguration ().clone ();
94+
95+ // setup
96+ String token1 = "token1" ;
97+ String endpoint = "http://localhost" ;
98+ TokenRequestContext request = new TokenRequestContext ().addScopes ("https://management.azure.com" );
99+ configuration .put ("IDENTITY_ENDPOINT" , endpoint );
100+ configuration .put ("IMDS_ENDPOINT" , endpoint );
101+
102+
103+ // test
104+ ManagedIdentityCredential credential = new ManagedIdentityCredentialBuilder ().clientId (CLIENT_ID ).build ();
105+ StepVerifier .create (credential .getToken (request ))
106+ .expectErrorMatches (t -> t instanceof ClientAuthenticationException )
107+ .verify ();
108+ }
109+
89110}
You can’t perform that action at this time.
0 commit comments