From 73be5517a19a9784a8156a13ebaa8964b190744f Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Tue, 23 May 2023 02:10:02 -0700 Subject: [PATCH 1/3] update --- .../identity/implementation/IntelliJCacheAccessor.java | 7 +++++-- .../identity/implementation/PersistentTokenCacheImpl.java | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IntelliJCacheAccessor.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IntelliJCacheAccessor.java index 392156156df96..56b5839546a11 100644 --- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IntelliJCacheAccessor.java +++ b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IntelliJCacheAccessor.java @@ -12,6 +12,8 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.microsoft.aad.msal4j.TokenCache; +import com.microsoft.aad.msal4jextensions.persistence.CacheFileAccessor; import com.microsoft.aad.msal4jextensions.persistence.mac.KeyChainAccessor; import com.sun.jna.Platform; import com.sun.jna.platform.win32.Crypt32Util; @@ -94,8 +96,9 @@ public String getIntelliJCredentialsFromIdentityMsalCache() { } else if (Platform.isWindows()) { try { - String jsonCred = new WindowsCredentialAccessor("Microsoft.Developer.IdentityService", "azure-toolkit.cache").read(); - return parseRefreshTokenFromJson(jsonCred); + CacheFileAccessor cacheFileAccessor = new CacheFileAccessor(PersistentTokenCacheImpl.DEFAULT_CACHE_FILE_PATH + File.separator + "azure-toolkit.cache"); + String data = new String(cacheFileAccessor.read(), StandardCharsets.UTF_8); + return parseRefreshTokenFromJson(data); } catch (Exception | Error e) { LOGGER.verbose("IntelliJCredential => Refresh Token Cache Unavailable: " + e.getMessage()); } diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/PersistentTokenCacheImpl.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/PersistentTokenCacheImpl.java index c67a5fec54f66..da3475cbd7348 100644 --- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/PersistentTokenCacheImpl.java +++ b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/PersistentTokenCacheImpl.java @@ -18,7 +18,7 @@ public class PersistentTokenCacheImpl implements ITokenCacheAccessAspect { private static final String DEFAULT_CACHE_FILE_NAME = "msal.cache"; private static final String DEFAULT_CONFIDENTIAL_CACHE_FILE_NAME = "msal.confidential.cache"; - private static final Path DEFAULT_CACHE_FILE_PATH = Platform.isWindows() + static final Path DEFAULT_CACHE_FILE_PATH = Platform.isWindows() ? Paths.get(System.getProperty("user.home"), "AppData", "Local", ".IdentityService") : Paths.get(System.getProperty("user.home"), ".IdentityService"); private static final String DEFAULT_KEYCHAIN_SERVICE = "Microsoft.Developer.IdentityService"; From dca25ea10345c5be04a60d9167d5e1165f7abe0a Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Tue, 30 May 2023 09:45:35 -0700 Subject: [PATCH 2/3] update dev cli cred location in dac chain --- .../com/azure/identity/DefaultAzureCredentialBuilder.java | 2 +- .../azure/identity/implementation/IntelliJCacheAccessor.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/DefaultAzureCredentialBuilder.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/DefaultAzureCredentialBuilder.java index 74d7d8513a4d9..ad64181775eb0 100644 --- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/DefaultAzureCredentialBuilder.java +++ b/sdk/identity/azure-identity/src/main/java/com/azure/identity/DefaultAzureCredentialBuilder.java @@ -275,12 +275,12 @@ private ArrayList getCredentialsChain() { output.add(new EnvironmentCredential(identityClientOptions.clone())); output.add(getWorkloadIdentityCredential()); output.add(new ManagedIdentityCredential(managedIdentityClientId, managedIdentityResourceId, identityClientOptions.clone())); - output.add(new AzureDeveloperCliCredential(tenantId, identityClientOptions.clone())); output.add(new SharedTokenCacheCredential(null, IdentityConstants.DEVELOPER_SINGLE_SIGN_ON_ID, tenantId, identityClientOptions.clone())); output.add(new IntelliJCredential(tenantId, identityClientOptions.clone())); output.add(new AzureCliCredential(tenantId, identityClientOptions.clone())); output.add(new AzurePowerShellCredential(tenantId, identityClientOptions.clone())); + output.add(new AzureDeveloperCliCredential(tenantId, identityClientOptions.clone())); return output; } diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IntelliJCacheAccessor.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IntelliJCacheAccessor.java index 56b5839546a11..ee9d835f8d002 100644 --- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IntelliJCacheAccessor.java +++ b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IntelliJCacheAccessor.java @@ -12,7 +12,6 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.microsoft.aad.msal4j.TokenCache; import com.microsoft.aad.msal4jextensions.persistence.CacheFileAccessor; import com.microsoft.aad.msal4jextensions.persistence.mac.KeyChainAccessor; import com.sun.jna.Platform; @@ -47,6 +46,7 @@ */ public class IntelliJCacheAccessor { private static final ClientLogger LOGGER = new ClientLogger(IntelliJCacheAccessor.class); + public static final String INTELLIJ_TOOLKIT_CACHE = "azure-toolkit.cache"; private final String keePassDatabasePath; private static final byte[] CRYPTO_KEY = new byte[] {0x50, 0x72, 0x6f, 0x78, 0x79, 0x20, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x20, 0x53, 0x65, 0x63}; @@ -96,7 +96,7 @@ public String getIntelliJCredentialsFromIdentityMsalCache() { } else if (Platform.isWindows()) { try { - CacheFileAccessor cacheFileAccessor = new CacheFileAccessor(PersistentTokenCacheImpl.DEFAULT_CACHE_FILE_PATH + File.separator + "azure-toolkit.cache"); + CacheFileAccessor cacheFileAccessor = new CacheFileAccessor(PersistentTokenCacheImpl.DEFAULT_CACHE_FILE_PATH + File.separator + INTELLIJ_TOOLKIT_CACHE); String data = new String(cacheFileAccessor.read(), StandardCharsets.UTF_8); return parseRefreshTokenFromJson(data); } catch (Exception | Error e) { From 676dd4104c83cbbc06c5f1c4a3fa478758c19298 Mon Sep 17 00:00:00 2001 From: Vinay Gera Date: Mon, 5 Jun 2023 09:30:16 -0700 Subject: [PATCH 3/3] fix test --- .../test/java/com/azure/identity/DefaultAzureCredentialTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/DefaultAzureCredentialTest.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/DefaultAzureCredentialTest.java index 739f46e717b23..6acef96b77e17 100644 --- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/DefaultAzureCredentialTest.java +++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/DefaultAzureCredentialTest.java @@ -226,6 +226,7 @@ public void testUseAzureDeveloperCliCredential() { try (MockedConstruction mocked = mockConstruction(IdentityClient.class, (identityClient, context) -> { when(identityClient.authenticateWithAzureDeveloperCli(request)).thenReturn(TestUtils.getMockAccessToken(token1, expiresAt)); when(identityClient.authenticateWithAzureCli(request)).thenReturn(Mono.empty()); + when(identityClient.authenticateWithAzurePowerShell(request)).thenReturn(Mono.empty()); when(identityClient.authenticateWithManagedIdentityConfidentialClient(request)).thenReturn(Mono.empty()); when(identityClient.authenticateWithSharedTokenCache(request, null)).thenReturn(Mono.empty()); when(identityClient.authenticateWithIntelliJ(request)).thenReturn(Mono.empty());