Skip to content

Commit 7ffffe4

Browse files
committed
persistent keys with right service name, key and username.
1 parent ac3b9e2 commit 7ffffe4

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
id="Azure Activity Log"
7171
canCloseContents="true"
7272
icon="/icons/Common/AzureActivityLog.svg"/>
73+
<applicationService serviceImplementation="com.microsoft.intellij.configuration.IdeaSecureStoreSettings"/>
7374
<projectConfigurable groupId="root"
7475
id="com.microsoft.intellij.AzureConfigurable"
7576
provider="com.microsoft.intellij.AzureConfigurableProvider"

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/intellij/secure/IdeaSecureStore.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
import static com.intellij.credentialStore.CredentialAttributesKt.generateServiceName;
1717

1818
public class IdeaSecureStore implements SecureStore {
19-
private IdeaSecureStore() {
20-
}
21-
22-
// Leverage IntelliJ PasswordSafe component
2319
private PasswordSafe passwordSafe = PasswordSafe.getInstance();
20+
private final CredentialAttributes keysEntry = makeKey("SecureStore", "keys", null);
2421

2522
private static class LazyHolder {
2623
static final IdeaSecureStore INSTANCE = new IdeaSecureStore();
@@ -32,6 +29,13 @@ public static IdeaSecureStore getInstance() {
3229

3330
@Override
3431
public void savePassword(@Nonnull String serviceName, @Nullable String key, @Nullable String userName, @Nonnull String password) {
32+
final String compositeKey = StringUtils.joinWith("|", serviceName, StringUtils.defaultString(key), StringUtils.defaultString(userName));
33+
String savedKeys = passwordSafe.getPassword(keysEntry);
34+
if (StringUtils.contains(savedKeys, compositeKey) && StringUtils.isNotBlank(password)) {
35+
savedKeys = StringUtils.defaultString(savedKeys) + "\n" + compositeKey;
36+
passwordSafe.setPassword(keysEntry, savedKeys);
37+
}
38+
3539
passwordSafe.setPassword(makeKey(serviceName, key, userName), password);
3640
}
3741

@@ -58,11 +62,11 @@ public void migratePassword(@Nonnull String oldKeyOrServiceName, @Nullable Strin
5862
if (StringUtils.isBlank(passwordSafe.getPassword(newKey))) {
5963
passwordSafe.setPassword(newKey, passwordSafe.getPassword(oldKey));
6064
}
61-
passwordSafe.set(oldKey, null);
65+
passwordSafe.setPassword(oldKey, null);
6266
}
6367

6468
@Nonnull
65-
private CredentialAttributes makeKey(String serviceName, @Nullable String key, @Nullable String userName) {
69+
private static CredentialAttributes makeKey(String serviceName, @Nullable String key, @Nullable String userName) {
6670
String serverNameWithPrefix = serviceName;
6771
if (!StringUtils.contains(serviceName, "Azure IntelliJ Plugin")) {
6872
serverNameWithPrefix = StringUtils.join("Azure IntelliJ Plugin | " + serviceName);

0 commit comments

Comments
 (0)