mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-164692 Only one instance of password is saved
This commit is contained in:
@@ -80,7 +80,7 @@ private class CredentialStoreWrapper(private val store: CredentialStore) : Passw
|
||||
|
||||
val appInfo = ApplicationInfoEx.getInstanceEx()
|
||||
if (appInfo.isEAP || appInfo.build.isSnapshot) {
|
||||
setNew(CredentialAttributes("IntelliJ Platform", "${requestor.name}/$userName"))?.let { return it }
|
||||
setNew(CredentialAttributes(SERVICE_NAME_PREFIX, "${requestor.name}/$userName"))?.let { return it }
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.*
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
|
||||
private const val GROUP_NAME = "IntelliJ Platform"
|
||||
private const val GROUP_NAME = SERVICE_NAME_PREFIX
|
||||
|
||||
internal val DB_FILE_NAME = "c.kdbx"
|
||||
|
||||
|
||||
@@ -27,8 +27,6 @@ import javax.crypto.spec.SecretKeySpec
|
||||
|
||||
internal val LOG = Logger.getInstance(CredentialStore::class.java)
|
||||
|
||||
internal val SERVICE_NAME_PREFIX = "IntelliJ Platform"
|
||||
|
||||
private fun toOldKey(hash: ByteArray) = "old-hashed-key|" + Base64.getEncoder().encodeToString(hash)
|
||||
|
||||
internal fun toOldKeyAsIdentity(hash: ByteArray) = CredentialAttributes(SERVICE_NAME_PREFIX, toOldKey(hash))
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
import java.util.*
|
||||
|
||||
private const val TEST_SERVICE_NAME = "IntelliJ Platform Test"
|
||||
private const val TEST_SERVICE_NAME = "$SERVICE_NAME_PREFIX Test"
|
||||
|
||||
inline fun macTest(task: () -> Unit) {
|
||||
if (SystemInfo.isMacIntel64 && !UsefulTestCase.IS_UNDER_TEAMCITY) {
|
||||
|
||||
@@ -26,11 +26,12 @@ import java.nio.CharBuffer
|
||||
import java.nio.charset.CodingErrorAction
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
const val SERVICE_NAME_PREFIX = "IntelliJ Platform"
|
||||
|
||||
/**
|
||||
* requestor is deprecated. Never use it in new code.
|
||||
*/
|
||||
data class CredentialAttributes @JvmOverloads constructor(val serviceName: String, val userName: String? = null, val requestor: Class<*>? = null, val isPasswordMemoryOnly: Boolean = false) {
|
||||
}
|
||||
data class CredentialAttributes @JvmOverloads constructor(val serviceName: String, val userName: String? = null, val requestor: Class<*>? = null, val isPasswordMemoryOnly: Boolean = false)
|
||||
|
||||
fun CredentialAttributes.toPasswordStoreable() = if (isPasswordMemoryOnly) CredentialAttributes(serviceName, userName, requestor) else this
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.diagnostic
|
||||
|
||||
import com.intellij.credentialStore.CredentialAttributes
|
||||
import com.intellij.credentialStore.Credentials
|
||||
import com.intellij.credentialStore.SERVICE_NAME_PREFIX
|
||||
import com.intellij.ide.passwordSafe.PasswordSafe
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.util.io.decodeBase64
|
||||
@@ -33,7 +34,7 @@ internal class ErrorReportConfigurable : PersistentStateComponent<OldState> {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val SERVICE_NAME = "IntelliJ Platform — JetBrains Account"
|
||||
val SERVICE_NAME = "$SERVICE_NAME_PREFIX — JetBrains Account"
|
||||
|
||||
val instance: ErrorReportConfigurable
|
||||
get() = ServiceManager.getService(ErrorReportConfigurable::class.java)
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
// limitations under the License.
|
||||
package org.zmlx.hg4idea.execution;
|
||||
|
||||
import com.intellij.credentialStore.CredentialAttributes;
|
||||
import com.intellij.credentialStore.CredentialAttributesKt;
|
||||
import com.intellij.credentialStore.Credentials;
|
||||
import com.intellij.ide.passwordSafe.PasswordSafe;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -26,8 +28,6 @@ import org.zmlx.hg4idea.HgGlobalSettings;
|
||||
import org.zmlx.hg4idea.HgVcs;
|
||||
import org.zmlx.hg4idea.HgVcsMessages;
|
||||
|
||||
import static com.intellij.credentialStore.CredentialAttributesKt.CredentialAttributes;
|
||||
|
||||
/**
|
||||
* Base class for any command interacting with a remote repository and which needs authentication.
|
||||
*/
|
||||
@@ -45,7 +45,7 @@ class HgCommandAuthenticator {
|
||||
public void forgetPassword() {
|
||||
if (myGetPassword == null) return; // prompt was not suggested;
|
||||
String url = VirtualFileManager.extractPath(myGetPassword.getURL());
|
||||
PasswordSafe.getInstance().setPassword(HgCommandAuthenticator.class, keyForUrlAndLogin(url, getUserName()), null);
|
||||
PasswordSafe.getInstance().set(createCredentialAttributes(url, null), null);
|
||||
}
|
||||
|
||||
public boolean promptForAuthentication(Project project, @NotNull String proposedLogin, @NotNull String uri, @NotNull String path, @Nullable ModalityState state) {
|
||||
@@ -84,6 +84,7 @@ class HgCommandAuthenticator {
|
||||
mySilent = silent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
// find if we've already been here
|
||||
@@ -105,10 +106,10 @@ class HgCommandAuthenticator {
|
||||
login = rememberedLoginsForUrl;
|
||||
}
|
||||
|
||||
String password = null;
|
||||
if (!StringUtil.isEmptyOrSpaces(login)) {
|
||||
// if we've logged in with this login, search for password
|
||||
password = PasswordSafe.getInstance().getPassword(HgCommandAuthenticator.class, keyForUrlAndLogin(url, login));
|
||||
Credentials savedCredentials = PasswordSafe.getInstance().get(createCredentialAttributes(url, null));
|
||||
String password = savedCredentials == null ? null : savedCredentials.getPasswordAsString();
|
||||
if (savedCredentials != null && StringUtil.isEmptyOrSpaces(login)) {
|
||||
login = savedCredentials.getUserName();
|
||||
}
|
||||
|
||||
// don't show dialog if we don't have to (both fields are known) except force authorization required
|
||||
@@ -130,7 +131,7 @@ class HgCommandAuthenticator {
|
||||
ok = true;
|
||||
Credentials credentials = new Credentials(dialog.getUsername(), dialog.getPassword());
|
||||
myCredentials = credentials;
|
||||
PasswordSafe.getInstance().set(CredentialAttributes(HgCommandAuthenticator.class, keyForUrlAndLogin(url, credentials.getUserName())), credentials, !dialog.isRememberPassword());
|
||||
PasswordSafe.getInstance().set(createCredentialAttributes(url, login), credentials, !dialog.isRememberPassword());
|
||||
hgGlobalSettings.addRememberedUrl(url, credentials.getUserName());
|
||||
}
|
||||
}
|
||||
@@ -153,7 +154,8 @@ class HgCommandAuthenticator {
|
||||
}
|
||||
}
|
||||
|
||||
private static String keyForUrlAndLogin(String stringUrl, String login) {
|
||||
return login + ":" + stringUrl;
|
||||
@NotNull
|
||||
private static CredentialAttributes createCredentialAttributes(@NotNull String url, @Nullable String login) {
|
||||
return new CredentialAttributes(CredentialAttributesKt.SERVICE_NAME_PREFIX + " HG — " + url, login);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.jetbrains.settingsRepository
|
||||
|
||||
import com.intellij.credentialStore.CredentialAttributes
|
||||
import com.intellij.credentialStore.Credentials
|
||||
import com.intellij.credentialStore.SERVICE_NAME_PREFIX
|
||||
import com.intellij.ide.passwordSafe.PasswordSafe
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ class IcsCredentialsStore() {
|
||||
|
||||
private fun CredentialAttributes(host: String?, sshKeyFile: String?, accountName: String?): CredentialAttributes? {
|
||||
if (sshKeyFile == null) {
|
||||
return CredentialAttributes("IntelliJ Platform Settings Repository — $host", accountName)
|
||||
return CredentialAttributes("$SERVICE_NAME_PREFIX Settings Repository — $host", accountName)
|
||||
}
|
||||
else {
|
||||
return CredentialAttributes("SSH", sshKeyFile)
|
||||
|
||||
Reference in New Issue
Block a user