Skip to content

Commit

Permalink
using instance of the service on-demand instead. #8473
Browse files Browse the repository at this point in the history
  • Loading branch information
wangmingliang-ms committed Aug 28, 2024
1 parent d16baaf commit 46d4364
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
import static com.intellij.credentialStore.CredentialAttributesKt.generateServiceName;

public class IntelliJSecureStore implements ISecureStore {
private static class LazyHolder {
static final IntelliJSecureStore INSTANCE = new IntelliJSecureStore();
}
static IntelliJSecureStore INSTANCE = null;

public static IntelliJSecureStore getInstance() {
return LazyHolder.INSTANCE;
public static synchronized IntelliJSecureStore getInstance() {
if (INSTANCE == null) {
INSTANCE = new IntelliJSecureStore();
}
return INSTANCE;
}

private IntelliJSecureStore() {
Expand Down Expand Up @@ -61,7 +62,7 @@ public String loadPassword(@Nonnull String serviceName, @Nullable String key, @N
@Override
public void forgetPassword(@Nonnull String serviceName, @Nullable String key, @Nullable String userName) {
CredentialAttributes oldKey = StringUtils.isNotBlank(userName) ? new CredentialAttributes(key, userName) :
new CredentialAttributes(key);
new CredentialAttributes(key);
passwordSafe.setPassword(oldKey, null);
passwordSafe.setPassword(makeKey(serviceName, key, userName), null);
}
Expand All @@ -70,7 +71,7 @@ public void forgetPassword(@Nonnull String serviceName, @Nullable String key, @N
public void migratePassword(@Nonnull String oldKeyOrServiceName, @Nullable String oldUsername,
@Nonnull String serviceName, @Nullable String key, @Nullable String userName) {
CredentialAttributes oldKey = StringUtils.isNotBlank(oldUsername) ? new CredentialAttributes(oldKeyOrServiceName, userName) :
new CredentialAttributes(oldKeyOrServiceName);
new CredentialAttributes(oldKeyOrServiceName);
CredentialAttributes newKey = makeKey(serviceName, key, userName);
if (StringUtils.isBlank(passwordSafe.getPassword(newKey))) {
passwordSafe.setPassword(newKey, passwordSafe.getPassword(oldKey));
Expand Down

0 comments on commit 46d4364

Please sign in to comment.