1616import static com .intellij .credentialStore .CredentialAttributesKt .generateServiceName ;
1717
1818public 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