mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Revert "IDEA-127343 Pass ModalityState to PasswordSafe.getPassword"
This reverts commits13963225d11a5cf59c9cc4a16ffb7dca76151550that required ModalityState in PasswordSafe API and passed it to the code which displays the master password request dialog. Better fix will follow, that wouldn't introduce the ModalityState into the API, but just use ModalityState.any() to display the dialog.
This commit is contained in:
@@ -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,45 +43,9 @@ 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;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @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
|
||||
* @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;
|
||||
|
||||
String getPassword(@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.
|
||||
*
|
||||
* @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
|
||||
@@ -95,7 +53,15 @@ public interface PasswordStorage {
|
||||
* @return the plugin key
|
||||
* @throws PasswordSafeException if password safe cannot be accessed
|
||||
*/
|
||||
void removePassword(@Nullable Project project, @NotNull Class requestor, String key,
|
||||
@Nullable ModalityState modalityState) throws PasswordSafeException;
|
||||
|
||||
void removePassword(@Nullable Project project, @NotNull Class requestor, String key) throws PasswordSafeException;
|
||||
/**
|
||||
* 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
|
||||
* @param value the value to store
|
||||
* @throws PasswordSafeException if password safe cannot be accessed
|
||||
*/
|
||||
void storePassword(@Nullable Project project, @NotNull Class requestor, String key, String value) throws PasswordSafeException;
|
||||
}
|
||||
|
||||
+7
-30
@@ -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);
|
||||
provider().removePassword(project, requester, key);
|
||||
}
|
||||
|
||||
@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 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
-21
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-17
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -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.defaultModalityState());
|
||||
//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
|
||||
|
||||
+1
-3
@@ -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);
|
||||
|
||||
+3
-10
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -176,7 +176,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;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
|
||||
return "";
|
||||
}
|
||||
url = adjustUrl(url);
|
||||
Pair<GitHttpAuthDataProvider, AuthData> authData = findBestAuthData(url, myModalityState);
|
||||
Pair<GitHttpAuthDataProvider, AuthData> authData = findBestAuthData(url);
|
||||
if (authData != null && authData.second.getPassword() != null) {
|
||||
String password = authData.second.getPassword();
|
||||
myDataProvider = authData.first;
|
||||
@@ -114,7 +114,7 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
|
||||
@NotNull
|
||||
public String askUsername(@NotNull String url) {
|
||||
url = adjustUrl(url);
|
||||
Pair<GitHttpAuthDataProvider, AuthData> authData = findBestAuthData(url, myModalityState);
|
||||
Pair<GitHttpAuthDataProvider, AuthData> authData = findBestAuthData(url);
|
||||
String login = null;
|
||||
String password = null;
|
||||
if (authData != null) {
|
||||
@@ -223,10 +223,10 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
|
||||
|
||||
// return the first that knows username + password; otherwise return the first that knows just the username
|
||||
@Nullable
|
||||
private Pair<GitHttpAuthDataProvider, AuthData> findBestAuthData(@NotNull String url, @Nullable ModalityState modalityState) {
|
||||
private Pair<GitHttpAuthDataProvider, AuthData> findBestAuthData(@NotNull String url) {
|
||||
Pair<GitHttpAuthDataProvider, AuthData> candidate = null;
|
||||
for (GitHttpAuthDataProvider provider : getProviders()) {
|
||||
AuthData data = provider.getAuthData(url, modalityState);
|
||||
AuthData data = provider.getAuthData(url);
|
||||
if (data != null) {
|
||||
Pair<GitHttpAuthDataProvider, AuthData> pair = Pair.create(provider, data);
|
||||
if (data.getPassword() != null) {
|
||||
@@ -268,12 +268,12 @@ class GitHttpGuiAuthenticator implements GitHttpAuthenticator {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AuthData getAuthData(@NotNull String url, @Nullable ModalityState modalityState) {
|
||||
public AuthData getAuthData(@NotNull String url) {
|
||||
String userName = getUsername(url);
|
||||
String key = makeKey(url, userName);
|
||||
final PasswordSafe passwordSafe = PasswordSafe.getInstance();
|
||||
try {
|
||||
String password = passwordSafe.getPassword(myProject, PASS_REQUESTER, key, modalityState);
|
||||
String password = passwordSafe.getPassword(myProject, PASS_REQUESTER, key);
|
||||
return new AuthData(StringUtil.notNullize(userName), password);
|
||||
}
|
||||
catch (PasswordSafeException e) {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package git4idea.remote;
|
||||
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.util.AuthData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -32,7 +31,7 @@ public interface GitHttpAuthDataProvider {
|
||||
ExtensionPointName<GitHttpAuthDataProvider> EP_NAME = ExtensionPointName.create("Git4Idea.GitHttpAuthDataProvider");
|
||||
|
||||
@Nullable
|
||||
AuthData getAuthData(@NotNull String url, @Nullable ModalityState modalityState);
|
||||
AuthData getAuthData(@NotNull String url);
|
||||
|
||||
void forgetPassword(@NotNull String url);
|
||||
|
||||
|
||||
@@ -195,7 +195,7 @@ public class GithubRebaseAction extends DumbAwareAction {
|
||||
}
|
||||
|
||||
try {
|
||||
return GithubUtil.runTask(project, GithubAuthDataHolder.createFromSettings(indicator.getModalityState()), indicator,
|
||||
return GithubUtil.runTask(project, GithubAuthDataHolder.createFromSettings(), indicator,
|
||||
new ThrowableConvertor<GithubAuthData, GithubRepoDetailed, IOException>() {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -124,7 +124,7 @@ public class GithubShareAction extends DumbAwareAction {
|
||||
externalRemoteDetected = !gitRepository.getRemotes().isEmpty();
|
||||
}
|
||||
|
||||
final GithubAuthDataHolder authHolder = GithubAuthDataHolder.createFromSettings(null);
|
||||
final GithubAuthDataHolder authHolder = GithubAuthDataHolder.createFromSettings();
|
||||
|
||||
// get available GitHub repos with modal progress
|
||||
final GithubInfo githubInfo = loadGithubInfoWithModal(authHolder, project);
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ public class GithubCheckoutProvider implements CheckoutProvider {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<GithubRepo> convert(ProgressIndicator indicator) throws IOException {
|
||||
return GithubUtil.runTask(project, GithubAuthDataHolder.createFromSettings(indicator.getModalityState()), indicator,
|
||||
return GithubUtil.runTask(project, GithubAuthDataHolder.createFromSettings(), indicator,
|
||||
new ThrowableConvertor<GithubAuthData, List<GithubRepo>, IOException>() {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
+2
-3
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.github.extensions;
|
||||
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.AuthData;
|
||||
import git4idea.remote.GitHttpAuthDataProvider;
|
||||
@@ -32,7 +31,7 @@ public class GithubHttpAuthDataProvider implements GitHttpAuthDataProvider {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public AuthData getAuthData(@NotNull String url, @Nullable ModalityState modalityState) {
|
||||
public AuthData getAuthData(@NotNull String url) {
|
||||
if (!GithubUrlUtil.isGithubUrl(url)) {
|
||||
return null;
|
||||
}
|
||||
@@ -48,7 +47,7 @@ public class GithubHttpAuthDataProvider implements GitHttpAuthDataProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
GithubAuthData auth = settings.getAuthData(modalityState);
|
||||
GithubAuthData auth = settings.getAuthData();
|
||||
switch (auth.getAuthType()) {
|
||||
case BASIC:
|
||||
GithubAuthData.BasicAuth basicAuth = auth.getBasicAuth();
|
||||
|
||||
@@ -125,8 +125,7 @@ public class GithubRepositoryEditor extends BaseRepositoryEditor<GithubRepositor
|
||||
@Override
|
||||
public String convert(ProgressIndicator indicator) throws IOException {
|
||||
return GithubUtil
|
||||
.runTaskWithBasicAuthForHost(myProject, GithubAuthDataHolder.createFromSettings(indicator.getModalityState()),
|
||||
indicator, getHost(),
|
||||
.runTaskWithBasicAuthForHost(myProject, GithubAuthDataHolder.createFromSettings(), indicator, getHost(),
|
||||
new ThrowableConvertor<GithubAuthData, String, IOException>() {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -130,8 +130,7 @@ public class GithubSettingsPanel {
|
||||
@NotNull
|
||||
@Override
|
||||
public String convert(ProgressIndicator indicator) throws IOException {
|
||||
return GithubUtil.runTaskWithBasicAuthForHost(project, GithubAuthDataHolder.createFromSettings(indicator.getModalityState()),
|
||||
indicator, getHost(),
|
||||
return GithubUtil.runTaskWithBasicAuthForHost(project, GithubAuthDataHolder.createFromSettings(), indicator, getHost(),
|
||||
new ThrowableConvertor<GithubAuthData, String, IOException>() {
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -263,7 +262,7 @@ public class GithubSettingsPanel {
|
||||
@NotNull
|
||||
public GithubAuthData getAuthData() {
|
||||
if (!myCredentialsModified) {
|
||||
return mySettings.getAuthData(null);
|
||||
return mySettings.getAuthData();
|
||||
}
|
||||
Object selected = myAuthTypeComboBox.getSelectedItem();
|
||||
if (AUTH_PASSWORD.equals(selected)) return GithubAuthData.createBasicAuth(getHost(), getLogin(), getPassword());
|
||||
@@ -291,7 +290,7 @@ public class GithubSettingsPanel {
|
||||
|
||||
public void apply() {
|
||||
if (myCredentialsModified) {
|
||||
mySettings.setAuthData(getAuthData(), true, null);
|
||||
mySettings.setAuthData(getAuthData(), true);
|
||||
}
|
||||
mySettings.setConnectionTimeout(getConnectionTimeout());
|
||||
resetCredentialsModification();
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.github.util;
|
||||
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.github.api.GithubApiUtil;
|
||||
@@ -53,8 +52,8 @@ public class GithubAuthData {
|
||||
myUseProxy = useProxy;
|
||||
}
|
||||
|
||||
public static GithubAuthData createFromSettings(@Nullable ModalityState state) {
|
||||
return GithubSettings.getInstance().getAuthData(state);
|
||||
public static GithubAuthData createFromSettings() {
|
||||
return GithubSettings.getInstance().getAuthData();
|
||||
}
|
||||
|
||||
public static GithubAuthData createAnonymous() {
|
||||
|
||||
@@ -15,10 +15,8 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.github.util;
|
||||
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.util.ThrowableComputable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
public class GithubAuthDataHolder {
|
||||
@@ -42,7 +40,7 @@ public class GithubAuthDataHolder {
|
||||
myAuthData = task.compute();
|
||||
}
|
||||
|
||||
public static GithubAuthDataHolder createFromSettings(@Nullable ModalityState state) {
|
||||
return new GithubAuthDataHolder(GithubSettings.getInstance().getAuthData(state));
|
||||
public static GithubAuthDataHolder createFromSettings() {
|
||||
return new GithubAuthDataHolder(GithubSettings.getInstance().getAuthData());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.intellij.ide.passwordSafe.PasswordSafe;
|
||||
import com.intellij.ide.passwordSafe.PasswordSafeException;
|
||||
import com.intellij.ide.passwordSafe.config.PasswordSafeSettings;
|
||||
import com.intellij.ide.passwordSafe.impl.PasswordSafeImpl;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -152,10 +151,10 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String getPassword(@Nullable ModalityState state) {
|
||||
private String getPassword() {
|
||||
String password;
|
||||
try {
|
||||
password = PasswordSafe.getInstance().getPassword(null, GithubSettings.class, GITHUB_SETTINGS_PASSWORD_KEY, state);
|
||||
password = PasswordSafe.getInstance().getPassword(null, GithubSettings.class, GITHUB_SETTINGS_PASSWORD_KEY);
|
||||
}
|
||||
catch (PasswordSafeException e) {
|
||||
LOG.info("Couldn't get password for key [" + GITHUB_SETTINGS_PASSWORD_KEY + "]", e);
|
||||
@@ -165,10 +164,10 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
|
||||
return StringUtil.notNullize(password);
|
||||
}
|
||||
|
||||
private void setPassword(@NotNull String password, boolean rememberPassword, @Nullable ModalityState state) {
|
||||
private void setPassword(@NotNull String password, boolean rememberPassword) {
|
||||
try {
|
||||
if (rememberPassword) {
|
||||
PasswordSafe.getInstance().storePassword(null, GithubSettings.class, GITHUB_SETTINGS_PASSWORD_KEY, password, state);
|
||||
PasswordSafe.getInstance().storePassword(null, GithubSettings.class, GITHUB_SETTINGS_PASSWORD_KEY, password);
|
||||
}
|
||||
else {
|
||||
final PasswordSafeImpl passwordSafe = (PasswordSafeImpl)PasswordSafe.getInstance();
|
||||
@@ -197,13 +196,13 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GithubAuthData getAuthData(@Nullable ModalityState state) {
|
||||
public GithubAuthData getAuthData() {
|
||||
switch (getAuthType()) {
|
||||
case BASIC:
|
||||
//noinspection ConstantConditions
|
||||
return GithubAuthData.createBasicAuth(getHost(), getLogin(), getPassword(state));
|
||||
return GithubAuthData.createBasicAuth(getHost(), getLogin(), getPassword());
|
||||
case TOKEN:
|
||||
return GithubAuthData.createTokenAuth(getHost(), getPassword(state));
|
||||
return GithubAuthData.createTokenAuth(getHost(), getPassword());
|
||||
case ANONYMOUS:
|
||||
return GithubAuthData.createAnonymous();
|
||||
default:
|
||||
@@ -211,7 +210,7 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
|
||||
}
|
||||
}
|
||||
|
||||
public void setAuthData(@NotNull GithubAuthData auth, boolean rememberPassword, @Nullable ModalityState state) {
|
||||
public void setAuthData(@NotNull GithubAuthData auth, boolean rememberPassword) {
|
||||
setValidGitAuth(isValidGitAuth(auth));
|
||||
|
||||
setAuthType(auth.getAuthType());
|
||||
@@ -221,16 +220,16 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
|
||||
case BASIC:
|
||||
assert auth.getBasicAuth() != null;
|
||||
setLogin(auth.getBasicAuth().getLogin());
|
||||
setPassword(auth.getBasicAuth().getPassword(), rememberPassword, state);
|
||||
setPassword(auth.getBasicAuth().getPassword(), rememberPassword);
|
||||
break;
|
||||
case TOKEN:
|
||||
assert auth.getTokenAuth() != null;
|
||||
setLogin(null);
|
||||
setPassword(auth.getTokenAuth().getToken(), rememberPassword, state);
|
||||
setPassword(auth.getTokenAuth().getToken(), rememberPassword);
|
||||
break;
|
||||
case ANONYMOUS:
|
||||
setLogin(null);
|
||||
setPassword("", rememberPassword, state);
|
||||
setPassword("", rememberPassword);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("GithubSettings: setAuthData - wrong AuthType: " + auth.getAuthType());
|
||||
|
||||
@@ -161,7 +161,7 @@ public class GithubUtil {
|
||||
|
||||
if (ok[0]) {
|
||||
authData[0] = dialog.getAuthData();
|
||||
GithubSettings.getInstance().setAuthData(authData[0], dialog.isSavePasswordSelected(), indicator.getModalityState());
|
||||
GithubSettings.getInstance().setAuthData(authData[0], dialog.isSavePasswordSelected());
|
||||
}
|
||||
}
|
||||
}, indicator.getModalityState());
|
||||
@@ -195,7 +195,7 @@ public class GithubUtil {
|
||||
|
||||
final GithubSettings settings = GithubSettings.getInstance();
|
||||
if (settings.getAuthType() != GithubAuthData.AuthType.TOKEN) {
|
||||
GithubSettings.getInstance().setAuthData(authData[0], dialog.isSavePasswordSelected(), indicator.getModalityState());
|
||||
GithubSettings.getInstance().setAuthData(authData[0], dialog.isSavePasswordSelected());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ public class GithubUtil {
|
||||
@NotNull
|
||||
public static GithubAuthDataHolder getValidAuthDataHolderFromConfig(@NotNull Project project, @NotNull ProgressIndicator indicator)
|
||||
throws IOException {
|
||||
GithubAuthData auth = GithubAuthData.createFromSettings(indicator.getModalityState());
|
||||
GithubAuthData auth = GithubAuthData.createFromSettings();
|
||||
GithubAuthDataHolder authHolder = new GithubAuthDataHolder(auth);
|
||||
try {
|
||||
checkAuthData(project, authHolder, indicator);
|
||||
|
||||
@@ -54,12 +54,12 @@ public abstract class GithubCreateGistTestBase extends GithubTest {
|
||||
|
||||
@NotNull
|
||||
protected GithubAuthDataHolder getAuthDataHolder() {
|
||||
return new GithubAuthDataHolder(myGitHubSettings.getAuthData(null));
|
||||
return new GithubAuthDataHolder(myGitHubSettings.getAuthData());
|
||||
}
|
||||
|
||||
protected void deleteGist() throws IOException {
|
||||
if (GIST_ID != null) {
|
||||
GithubApiUtil.deleteGist(myGitHubSettings.getAuthData(null), GIST_ID);
|
||||
GithubApiUtil.deleteGist(myGitHubSettings.getAuthData(), GIST_ID);
|
||||
GIST = null;
|
||||
GIST_ID = null;
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public abstract class GithubCreateGistTestBase extends GithubTest {
|
||||
|
||||
if (GIST == null) {
|
||||
try {
|
||||
GIST = GithubApiUtil.getGist(myGitHubSettings.getAuthData(null), GIST_ID);
|
||||
GIST = GithubApiUtil.getGist(myGitHubSettings.getAuthData(), GIST_ID);
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println(e.getMessage());
|
||||
|
||||
@@ -36,7 +36,7 @@ public class GithubRequestPagingTest extends GithubTest {
|
||||
|
||||
public void testAvailableRepos() throws Throwable {
|
||||
|
||||
List<GithubRepo> availableRepos = GithubApiUtil.getUserRepos(myGitHubSettings.getAuthData(null), myLogin2);
|
||||
List<GithubRepo> availableRepos = GithubApiUtil.getUserRepos(myGitHubSettings.getAuthData(), myLogin2);
|
||||
List<String> realData = new ArrayList<String>();
|
||||
for (GithubRepo info : availableRepos) {
|
||||
realData.add(info.getName());
|
||||
|
||||
@@ -99,7 +99,7 @@ public class GithubShareProjectTest extends GithubShareProjectTestBase {
|
||||
}
|
||||
|
||||
protected void checkGithubExists() throws IOException {
|
||||
GithubAuthData auth = myGitHubSettings.getAuthData(null);
|
||||
GithubAuthData auth = myGitHubSettings.getAuthData();
|
||||
GithubRepoDetailed githubInfo = GithubApiUtil.getDetailedRepoInfo(auth, myLogin1, PROJECT_NAME);
|
||||
assertNotNull("GitHub repository does not exist", githubInfo);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public abstract class GithubShareProjectTestBase extends GithubTest {
|
||||
}
|
||||
|
||||
protected void deleteGithubRepo() throws IOException {
|
||||
GithubApiUtil.deleteGithubRepository(myGitHubSettings.getAuthData(null), myLogin1, PROJECT_NAME);
|
||||
GithubApiUtil.deleteGithubRepository(myGitHubSettings.getAuthData(), myLogin1, PROJECT_NAME);
|
||||
}
|
||||
|
||||
protected void registerDefaultShareDialogHandler() {
|
||||
|
||||
@@ -172,7 +172,7 @@ public abstract class GithubTest extends GitPlatformTest {
|
||||
myAuth = GithubAuthData.createBasicAuth(host, login1, password);
|
||||
|
||||
myGitHubSettings = GithubSettings.getInstance();
|
||||
myGitHubSettings.setAuthData(myAuth, false, null);
|
||||
myGitHubSettings.setAuthData(myAuth, false);
|
||||
|
||||
myHttpAuthService = (GitHttpAuthTestService)ServiceManager.getService(GitHttpAuthService.class);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.zmlx.hg4idea.HgVcsMessages;
|
||||
class HgCommandAuthenticator {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(HgCommandAuthenticator.class.getName());
|
||||
|
||||
|
||||
private GetPasswordRunnable myGetPassword;
|
||||
private final Project myProject;
|
||||
private boolean myForceAuthorization;
|
||||
@@ -71,7 +71,7 @@ class HgCommandAuthenticator {
|
||||
}
|
||||
|
||||
public boolean promptForAuthentication(Project project, String proposedLogin, String uri, String path, @Nullable ModalityState state) {
|
||||
GetPasswordRunnable runnable = new GetPasswordRunnable(project, proposedLogin, uri, path, myForceAuthorization, state);
|
||||
GetPasswordRunnable runnable = new GetPasswordRunnable(project, proposedLogin, uri, path, myForceAuthorization);
|
||||
ApplicationManager.getApplication().invokeAndWait(runnable, state == null ? ModalityState.defaultModalityState() : state);
|
||||
myGetPassword = runnable;
|
||||
return runnable.isOk();
|
||||
@@ -96,21 +96,14 @@ class HgCommandAuthenticator {
|
||||
@Nullable private String myURL;
|
||||
private boolean myRememberPassword;
|
||||
private boolean myForceAuthorization;
|
||||
@Nullable private ModalityState myState;
|
||||
|
||||
public GetPasswordRunnable(Project project,
|
||||
String proposedLogin,
|
||||
String uri,
|
||||
String path,
|
||||
boolean forceAuthorization,
|
||||
@Nullable ModalityState state) {
|
||||
public GetPasswordRunnable(Project project, String proposedLogin, String uri, String path, boolean forceAuthorization) {
|
||||
this.myProject = project;
|
||||
this.myProposedLogin = proposedLogin;
|
||||
this.myURL = uri + path;
|
||||
this.myForceAuthorization = forceAuthorization;
|
||||
myState = state;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
|
||||
// find if we've already been here
|
||||
@@ -135,9 +128,11 @@ class HgCommandAuthenticator {
|
||||
final String key = keyForUrlAndLogin(myURL, login);
|
||||
try {
|
||||
final PasswordSafeImpl passwordSafe = (PasswordSafeImpl)PasswordSafe.getInstance();
|
||||
password = passwordSafe.getPassword(myProject, HgCommandAuthenticator.class, key, myState);
|
||||
}
|
||||
catch (PasswordSafeException e) {
|
||||
password = passwordSafe.getMemoryProvider().getPassword(myProject, HgCommandAuthenticator.class, key);
|
||||
if (password == null) {
|
||||
password = passwordSafe.getPassword(myProject, HgCommandAuthenticator.class, key);
|
||||
}
|
||||
} catch (PasswordSafeException e) {
|
||||
LOG.info("Couldn't get password for key [" + key + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user