diff options
Diffstat (limited to 'platform/platform-impl/src/com/intellij/ide/passwordSafe')
8 files changed, 46 insertions, 152 deletions
diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/PasswordStorage.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/PasswordStorage.java index e5b9f1530256..b1ea1332986e 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/PasswordStorage.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/PasswordStorage.java @@ -25,21 +25,15 @@ import org.jetbrains.annotations.Nullable; * The interface defines basic password management operations */ public interface PasswordStorage { - /** - * @deprecated To remove in IDEA 15. Use {@link #getPassword(Project, Class, String, ModalityState)} - */ - @Deprecated - @Nullable - String getPassword(@Nullable Project project, @NotNull Class requestor, String key) throws PasswordSafeException; - - /** - * Get password stored in a password safe. - * <p/> - * The method may be called from any thread. It may need to show a master password dialog to unlock the password database, - * and then will use {@link Application#invokeAndWait(Runnable, ModalityState) invokeAndWait()}. - * So make sure to pass correct {@link ModalityState} to the method to make sure the dialog is shown above all other dialog or progress - * windows. + * <p>Get password stored in a password safe.</p> + * + * <p><b>NB: </b> + * This method may be called from the background, + * and it may need to ask user to enter the master password to access the database by calling + * {@link Application#invokeAndWait(Runnable, ModalityState) invokeAndWait()} to show a modal dialog. + * So make sure not to call it from the read action. + * Calling this method from the dispatch thread is allowed.</p> * * @param project the project, that is used to ask for the master password if this is the first access to password safe * @param requestor the requestor class @@ -49,53 +43,25 @@ public interface PasswordStorage { * @throws IllegalStateException if the method is called from the read action. */ @Nullable - String getPassword(@Nullable Project project, @NotNull Class requestor, String key, - @Nullable ModalityState state) throws PasswordSafeException; - + String getPassword(@Nullable Project project, @NotNull Class requestor, String key) throws PasswordSafeException; /** - * Store password in password safe - * <p/> - * The method may be called from any thread. It may need to show a master password dialog to unlock the password database, - * and then will use {@link Application#invokeAndWait(Runnable, ModalityState) invokeAndWait()}. - * So make sure to pass correct {@link ModalityState} to the method to make sure the dialog is shown above all other dialog or progress - * windows. + * Remove password stored in a password safe * * @param project the project, that is used to ask for the master password if this is the first access to password safe * @param requestor the requestor class * @param key the key for the password - * @param value the value to store + * @return the plugin key * @throws PasswordSafeException if password safe cannot be accessed */ - void storePassword(@Nullable Project project, @NotNull Class requestor, String key, String value, - @Nullable ModalityState modalityState) throws PasswordSafeException; - - /** - * @deprecated To remove in IDEA 15. Use {@link #storePassword(Project, Class, String, String, ModalityState)} - */ - @Deprecated - void storePassword(@Nullable Project project, @NotNull Class requestor, String key, String value) throws PasswordSafeException; - - /** - * @deprecated To remove in IDEA 15. Use {@link #removePassword(Project, Class, String, ModalityState)} - */ - @Deprecated void removePassword(@Nullable Project project, @NotNull Class requestor, String key) throws PasswordSafeException; - /** - * Remove password stored in a password safe - * <p/> - * The method may be called from any thread. It may need to show a master password dialog to unlock the password database, - * and then will use {@link Application#invokeAndWait(Runnable, ModalityState) invokeAndWait()}. - * So make sure to pass correct {@link ModalityState} to the method to make sure the dialog is shown above all other dialog or progress - * windows. + * Store password in password safe * * @param project the project, that is used to ask for the master password if this is the first access to password safe * @param requestor the requestor class * @param key the key for the password - * @return the plugin key + * @param value the value to store * @throws PasswordSafeException if password safe cannot be accessed */ - void removePassword(@Nullable Project project, @NotNull Class requestor, String key, - @Nullable ModalityState modalityState) throws PasswordSafeException; - + void storePassword(@Nullable Project project, @NotNull Class requestor, String key, String value) throws PasswordSafeException; } diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/PasswordSafeImpl.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/PasswordSafeImpl.java index 34aee7aaad38..6d5127b376ad 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/PasswordSafeImpl.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/PasswordSafeImpl.java @@ -22,7 +22,6 @@ import com.intellij.ide.passwordSafe.impl.providers.masterKey.MasterKeyPasswordS import com.intellij.ide.passwordSafe.impl.providers.masterKey.PasswordDatabase; import com.intellij.ide.passwordSafe.impl.providers.memory.MemoryPasswordSafe; import com.intellij.ide.passwordSafe.impl.providers.nil.NilProvider; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; @@ -71,19 +70,11 @@ public class PasswordSafeImpl extends PasswordSafe { } @Nullable - @Override public String getPassword(@Nullable Project project, @NotNull Class requester, String key) throws PasswordSafeException { - return getPassword(project, requester, key, null); - } - - @Nullable - @Override - public String getPassword(@Nullable Project project, @NotNull Class requester, String key, - @Nullable ModalityState modalityState) throws PasswordSafeException { if (mySettings.getProviderType().equals(PasswordSafeSettings.ProviderType.MASTER_PASSWORD)) { - String password = getMemoryProvider().getPassword(project, requester, key, modalityState); + String password = getMemoryProvider().getPassword(project, requester, key); if (password == null) { - password = provider().getPassword(project, requester, key, modalityState); + password = provider().getPassword(project, requester, key); if (password != null) { // cache the password in memory as well for easier access during the session getMemoryProvider().storePassword(project, requester, key, password); @@ -91,35 +82,21 @@ public class PasswordSafeImpl extends PasswordSafe { } return password; } - return provider().getPassword(project, requester, key, modalityState); + return provider().getPassword(project, requester, key); } - @Override - public void removePassword(@Nullable Project project, @NotNull Class requestor, String key) throws PasswordSafeException { - removePassword(project, requestor, key, null); - } - - @Override - public void removePassword(@Nullable Project project, @NotNull Class requester, String key, - @Nullable ModalityState modalityState) throws PasswordSafeException { + public void removePassword(@Nullable Project project, @NotNull Class requester, String key) throws PasswordSafeException { if (mySettings.getProviderType().equals(PasswordSafeSettings.ProviderType.MASTER_PASSWORD)) { getMemoryProvider().removePassword(project, requester, key); } - provider().removePassword(project, requester, key, modalityState); - } - - @Override - public void storePassword(@Nullable Project project, @NotNull Class requestor, String key, String value) throws PasswordSafeException { - storePassword(project, requestor, key, value, null); + provider().removePassword(project, requester, key); } - @Override - public void storePassword(@Nullable Project project, @NotNull Class requester, String key, String value, - @Nullable ModalityState modalityState) throws PasswordSafeException { + public void storePassword(@Nullable Project project, @NotNull Class requester, String key, String value) throws PasswordSafeException { if (mySettings.getProviderType().equals(PasswordSafeSettings.ProviderType.MASTER_PASSWORD)) { getMemoryProvider().storePassword(project, requester, key, value); } - provider().storePassword(project, requester, key, value, modalityState); + provider().storePassword(project, requester, key, value); } /** diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/PasswordSafeProvider.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/PasswordSafeProvider.java index 3a40d617e99b..18dee7c755f5 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/PasswordSafeProvider.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/PasswordSafeProvider.java @@ -15,11 +15,7 @@ */ package com.intellij.ide.passwordSafe.impl; -import com.intellij.ide.passwordSafe.PasswordSafeException; import com.intellij.ide.passwordSafe.PasswordStorage; -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * The provider for password safe component @@ -38,21 +34,4 @@ public abstract class PasswordSafeProvider implements PasswordStorage { * @return the name of provider */ public abstract String getName(); - - @Nullable - @Override - public String getPassword(@Nullable Project project, @NotNull Class requestor, String key) throws PasswordSafeException { - return getPassword(project, requestor, key, null); - } - - @Override - public void storePassword(@Nullable Project project, @NotNull Class requestor, String key, String value) throws PasswordSafeException { - storePassword(project, requestor, key, value, null); - } - - @Override - public void removePassword(@Nullable Project project, @NotNull Class requestor, String key) throws PasswordSafeException { - removePassword(project, requestor, key, null); - } - } diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/BasePasswordSafeProvider.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/BasePasswordSafeProvider.java index 8c8f921f18b8..a0b001824d90 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/BasePasswordSafeProvider.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/BasePasswordSafeProvider.java @@ -43,15 +43,13 @@ public abstract class BasePasswordSafeProvider extends PasswordSafeProvider { * @throws PasswordSafeException in case of problems with access to the password database. * @throws IllegalStateException if the method is called from the read action. */ - protected abstract byte[] key(@Nullable Project project, @NotNull Class requestor, - @Nullable ModalityState modalityState) throws PasswordSafeException; + protected abstract byte[] key(@Nullable Project project, @NotNull Class requestor) throws PasswordSafeException; @Nullable - public String getPassword(@Nullable Project project, @NotNull Class requestor, String key, - @Nullable ModalityState modalityState) throws PasswordSafeException { - byte[] k = dbKey(project, requestor, key, modalityState); + public String getPassword(@Nullable Project project, @NotNull Class requestor, String key) throws PasswordSafeException { + byte[] k = dbKey(project, requestor, key); byte[] ct = getEncryptedPassword(k); - return ct == null ? null : EncryptionUtil.decryptText(key(project, requestor, modalityState), ct); + return ct == null ? null : EncryptionUtil.decryptText(key(project, requestor), ct); } /** @@ -68,17 +66,14 @@ public abstract class BasePasswordSafeProvider extends PasswordSafeProvider { * @param project * @param requestor the requestor class * @param key the key to use - * @param modalityState * @return the key to use for map */ - private byte[] dbKey(@Nullable Project project, @NotNull Class requestor, String key, - @Nullable ModalityState modalityState) throws PasswordSafeException { - return EncryptionUtil.dbKey(key(project, requestor, modalityState), requestor, key); + private byte[] dbKey(@Nullable Project project, Class requestor, String key) throws PasswordSafeException { + return EncryptionUtil.dbKey(key(project, requestor), requestor, key); } - public void removePassword(@Nullable Project project, @NotNull Class requester, String key, - @Nullable ModalityState modalityState) throws PasswordSafeException { - byte[] k = dbKey(project, requester, key, modalityState); + public void removePassword(@Nullable Project project, @NotNull Class requester, String key) throws PasswordSafeException { + byte[] k = dbKey(project, requester, key); removeEncryptedPassword(k); } @@ -89,10 +84,9 @@ public abstract class BasePasswordSafeProvider extends PasswordSafeProvider { */ protected abstract void removeEncryptedPassword(byte[] key); - public void storePassword(@Nullable Project project, @NotNull Class requestor, String key, String value, - @Nullable ModalityState modalityState) throws PasswordSafeException { - byte[] k = dbKey(project, requestor, key, modalityState); - byte[] ct = EncryptionUtil.encryptText(key(project, requestor, modalityState), value); + public void storePassword(@Nullable Project project, @NotNull Class requestor, String key, String value) throws PasswordSafeException { + byte[] k = dbKey(project, requestor, key); + byte[] ct = EncryptionUtil.encryptText(key(project, requestor), value); storeEncryptedPassword(k, ct); } diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java index b74e51315cd5..840159270a8d 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/masterKey/MasterKeyPasswordSafe.java @@ -154,8 +154,7 @@ public class MasterKeyPasswordSafe extends BasePasswordSafeProvider { } @Override - protected byte[] key(@Nullable final Project project, @NotNull final Class requestor, - @Nullable ModalityState modalityState) throws PasswordSafeException { + protected byte[] key(@Nullable final Project project, @NotNull final Class requestor) throws PasswordSafeException { Application application = ApplicationManager.getApplication(); if (!isTestMode() && application.isHeadlessEnvironment()) { throw new MasterPasswordUnavailableException("The provider is not available in headless environment"); @@ -200,7 +199,7 @@ public class MasterKeyPasswordSafe extends BasePasswordSafeProvider { } } } - }, modalityState == null ? ModalityState.defaultModalityState() : modalityState); + }, ModalityState.any()); //noinspection ThrowableResultOfMethodCallIgnored if (ex.get() != null) { throw ex.get(); @@ -211,12 +210,11 @@ public class MasterKeyPasswordSafe extends BasePasswordSafeProvider { } @Override - public String getPassword(@Nullable Project project, @NotNull Class requestor, String key, - @Nullable ModalityState modalityState) throws PasswordSafeException { + public String getPassword(@Nullable Project project, @NotNull Class requestor, String key) throws PasswordSafeException { if (database.isEmpty()) { return null; } - return super.getPassword(project, requestor, key, modalityState); + return super.getPassword(project, requestor, key); } @Override diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/memory/MemoryPasswordSafe.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/memory/MemoryPasswordSafe.java index da82bb986fdb..4989789b4ec0 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/memory/MemoryPasswordSafe.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/memory/MemoryPasswordSafe.java @@ -19,12 +19,10 @@ import com.intellij.ide.passwordSafe.impl.PasswordSafeTimed; import com.intellij.ide.passwordSafe.impl.providers.BasePasswordSafeProvider; import com.intellij.ide.passwordSafe.impl.providers.ByteArrayWrapper; import com.intellij.ide.passwordSafe.impl.providers.EncryptionUtil; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.registry.Registry; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.security.SecureRandom; import java.util.Collections; @@ -60,7 +58,7 @@ public class MemoryPasswordSafe extends BasePasswordSafeProvider { } @Override - protected byte[] key(Project project, @NotNull Class requestor, @Nullable ModalityState modalityState) { + protected byte[] key(Project project, @NotNull Class requestor) { if (key.get() == null) { byte[] rnd = new byte[EncryptionUtil.SECRET_KEY_SIZE_BYTES * 16]; new SecureRandom().nextBytes(rnd); diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/nil/NilProvider.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/nil/NilProvider.java index e3a77325b06e..4bf024d697c2 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/nil/NilProvider.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/impl/providers/nil/NilProvider.java @@ -17,7 +17,6 @@ package com.intellij.ide.passwordSafe.impl.providers.nil; import com.intellij.ide.passwordSafe.PasswordSafeException; import com.intellij.ide.passwordSafe.impl.PasswordSafeProvider; -import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,22 +41,16 @@ public final class NilProvider extends PasswordSafeProvider { return "Do not Store"; } - @Nullable - public String getPassword(@Nullable Project project, @NotNull Class requester, String key, - @Nullable ModalityState modalityState) throws PasswordSafeException { + public String getPassword(@Nullable Project project, @NotNull Class requester, String key) throws PasswordSafeException { // nothing is stored return null; } - @Override - public void removePassword(@Nullable Project project, @NotNull Class requester, String key, - @Nullable ModalityState modalityState) throws PasswordSafeException { + public void removePassword(@Nullable Project project, @NotNull Class requester, String key) throws PasswordSafeException { // do nothing } - @Override - public void storePassword(@Nullable Project project, @NotNull Class requester, String key, String value, - @Nullable ModalityState modalityState) throws PasswordSafeException { + public void storePassword(@Nullable Project project, @NotNull Class requester, String key, String value) throws PasswordSafeException { // just forget about password } } diff --git a/platform/platform-impl/src/com/intellij/ide/passwordSafe/ui/PasswordSafePromptDialog.java b/platform/platform-impl/src/com/intellij/ide/passwordSafe/ui/PasswordSafePromptDialog.java index 353e836f3f33..8aa0099ccd1d 100644 --- a/platform/platform-impl/src/com/intellij/ide/passwordSafe/ui/PasswordSafePromptDialog.java +++ b/platform/platform-impl/src/com/intellij/ide/passwordSafe/ui/PasswordSafePromptDialog.java @@ -73,10 +73,7 @@ public class PasswordSafePromptDialog extends DialogWrapper { /** * Ask password possibly asking password database first. The method could be invoked from any thread. If UI needs to be shown, * the method invokes {@link UIUtil#invokeAndWaitIfNeeded(Runnable)} - * * @param project the context project - * @param modalityState the modality state using which any prompts initiated by the git process should be shown in the UI. - * If null then {@link ModalityState#defaultModalityState() the default modality state} will be used. * @param title the dialog title * @param message the message describing a resource for which password is asked * @param requestor the password requestor @@ -86,13 +83,12 @@ public class PasswordSafePromptDialog extends DialogWrapper { */ @Nullable public static String askPassword(final Project project, - @Nullable ModalityState modalityState, final String title, final String message, @NotNull final Class<?> requestor, final String key, boolean resetPassword, String error) { - return askPassword(project, modalityState, title, message, requestor, key, resetPassword, error, null, null); + return askPassword(project, title, message, requestor, key, resetPassword, error, null, null); } /** @@ -112,17 +108,14 @@ public class PasswordSafePromptDialog extends DialogWrapper { @NotNull final Class<?> requestor, final String key, boolean resetPassword) { - return askPassword(null, null, title, message, requestor, key, resetPassword, null); + return askPassword(null, title, message, requestor, key, resetPassword, null); } /** * Ask passphrase possibly asking password database first. The method could be invoked from any thread. If UI needs to be shown, * the method invokes {@link UIUtil#invokeAndWaitIfNeeded(Runnable)} - * * @param project the context project (might be null) - * @param modalityState the modality state using which any prompts initiated by the git process should be shown in the UI. - * If null then {@link ModalityState#defaultModalityState() the default modality state} will be used. * @param title the dialog title * @param message the message describing a resource for which password is asked * @param requestor the password requestor @@ -132,13 +125,13 @@ public class PasswordSafePromptDialog extends DialogWrapper { */ @Nullable public static String askPassphrase(final Project project, - @Nullable ModalityState modalityState, final String title, + final String title, final String message, @NotNull final Class<?> requestor, final String key, boolean resetPassword, String error) { - return askPassword(project, modalityState, title, message, requestor, key, resetPassword, error, + return askPassword(project, title, message, requestor, key, resetPassword, error, "Passphrase:", "Remember the passphrase"); } @@ -146,10 +139,7 @@ public class PasswordSafePromptDialog extends DialogWrapper { /** * Ask password possibly asking password database first. The method could be invoked from any thread. If UI needs to be shown, * the method invokes {@link UIUtil#invokeAndWaitIfNeeded(Runnable)} - * * @param project the context project - * @param modalityState the modality state using which any prompts initiated by the git process should be shown in the UI. - * If null then {@link ModalityState#defaultModalityState() the default modality state} will be used. * @param title the dialog title * @param message the message describing a resource for which password is asked * @param requestor the password requestor @@ -161,7 +151,6 @@ public class PasswordSafePromptDialog extends DialogWrapper { */ @Nullable private static String askPassword(final Project project, - @Nullable ModalityState modalityState, final String title, final String message, @NotNull final Class<?> requestor, @@ -176,7 +165,7 @@ public class PasswordSafePromptDialog extends DialogWrapper { ps.removePassword(project, requestor, key); } else { - String pw = ps.getPassword(project, requestor, key, modalityState); + String pw = ps.getPassword(project, requestor, key); if (pw != null) { return pw; } @@ -214,7 +203,7 @@ public class PasswordSafePromptDialog extends DialogWrapper { } } } - }, modalityState == null ? ModalityState.defaultModalityState() : modalityState); + }, ModalityState.any()); return ref.get(); } } |