Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Dev CLI Cred in DAC Chain + Update IntelliJ Cache Read #35194

Merged
merged 3 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ private ArrayList<TokenCredential> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
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;
Expand Down Expand Up @@ -45,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};
Expand Down Expand Up @@ -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 + INTELLIJ_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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public void testUseAzureDeveloperCliCredential() {
try (MockedConstruction<IdentityClient> 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());
Expand Down