mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
accountName -> userName
This commit is contained in:
@@ -112,7 +112,7 @@ internal class FileCredentialStore(keyToValue: Map<CredentialAttributes, Credent
|
||||
if (password == null) {
|
||||
// try old key - as hash
|
||||
val oldAttributes = toOldKey(requestor, accountName)
|
||||
val credentials = db.rootGroup.getGroup(GROUP_NAME)?.removeEntry(oldAttributes.serviceName, oldAttributes.accountName!!)
|
||||
val credentials = db.rootGroup.getGroup(GROUP_NAME)?.removeEntry(oldAttributes.serviceName, oldAttributes.userName!!)
|
||||
if (credentials != null) {
|
||||
set(CredentialAttributes(requestor, accountName), Credentials(accountName, credentials.password))
|
||||
return credentials.password
|
||||
@@ -122,16 +122,16 @@ internal class FileCredentialStore(keyToValue: Map<CredentialAttributes, Credent
|
||||
}
|
||||
|
||||
override fun get(attributes: CredentialAttributes): Credentials? {
|
||||
val entry = db.rootGroup.getGroup(GROUP_NAME)?.getEntry(attributes.serviceName, attributes.accountName) ?: return null
|
||||
val entry = db.rootGroup.getGroup(GROUP_NAME)?.getEntry(attributes.serviceName, attributes.userName) ?: return null
|
||||
return Credentials(entry.userName, entry.password)
|
||||
}
|
||||
|
||||
override fun set(attributes: CredentialAttributes, credentials: Credentials?) {
|
||||
if (credentials == null) {
|
||||
db.rootGroup.getGroup(GROUP_NAME)?.removeEntry(attributes.serviceName, attributes.accountName)
|
||||
db.rootGroup.getGroup(GROUP_NAME)?.removeEntry(attributes.serviceName, attributes.userName)
|
||||
}
|
||||
else {
|
||||
db.rootGroup.getOrCreateGroup(GROUP_NAME).getOrCreateEntry(attributes.serviceName, attributes.accountName ?: credentials.userName).password = credentials.password
|
||||
db.rootGroup.getOrCreateGroup(GROUP_NAME).getOrCreateEntry(attributes.serviceName, attributes.userName ?: credentials.userName).password = credentials.password
|
||||
}
|
||||
|
||||
if (db.isDirty) {
|
||||
|
||||
@@ -94,7 +94,7 @@ class PasswordSafeImpl(/* public - backward compatibility */val settings: Passwo
|
||||
}
|
||||
|
||||
override fun setPassword(attributes: CredentialAttributes, value: String?, memoryOnly: Boolean) {
|
||||
val credentials = value?.let { Credentials(attributes.accountName, it) }
|
||||
val credentials = value?.let { Credentials(attributes.userName, it) }
|
||||
if (memoryOnly) {
|
||||
memoryHelperProvider.value.set(attributes, credentials)
|
||||
// remove to ensure that on getPassword we will not return some value from default provider
|
||||
|
||||
@@ -101,7 +101,7 @@ internal fun convertOldDb(oldKey: String, @Suppress("DEPRECATION") db: PasswordD
|
||||
|
||||
// in old db we cannot get key value - it is hashed, so, we store it as a base64 encoded in the new DB
|
||||
val attributes = toOldKeyAsIdentity(EncryptionUtil.decryptKey(oldKeyB, key.unwrap()))
|
||||
newDb.put(attributes, Credentials(attributes.accountName, EncryptionUtil.decryptText(oldKeyB, value)))
|
||||
newDb.put(attributes, Credentials(attributes.userName, EncryptionUtil.decryptText(oldKeyB, value)))
|
||||
}
|
||||
return newDb
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ internal class SecretCredentialStore(schemeName: String) : CredentialStore {
|
||||
override fun get(attributes: CredentialAttributes): Credentials? {
|
||||
checkError("secret_password_lookup_sync") { errorRef ->
|
||||
val serviceNamePointer = stringPointer(attributes.serviceName.toByteArray())
|
||||
if (attributes.accountName == null) {
|
||||
if (attributes.userName == null) {
|
||||
LIBRARY.secret_password_lookup_sync(scheme, null, errorRef, serviceAttributeNamePointer, serviceNamePointer, null)?.let {
|
||||
// Secret Service doesn't allow to get attributes, so, we store joined data
|
||||
return splitData(it)
|
||||
@@ -44,7 +44,7 @@ internal class SecretCredentialStore(schemeName: String) : CredentialStore {
|
||||
else {
|
||||
LIBRARY.secret_password_lookup_sync(scheme, null, errorRef,
|
||||
serviceAttributeNamePointer, serviceNamePointer,
|
||||
accountAttributeNamePointer, stringPointer(attributes.accountName!!.toByteArray()),
|
||||
accountAttributeNamePointer, stringPointer(attributes.userName!!.toByteArray()),
|
||||
null)?.let {
|
||||
return splitData(it)
|
||||
}
|
||||
@@ -56,7 +56,7 @@ internal class SecretCredentialStore(schemeName: String) : CredentialStore {
|
||||
|
||||
override fun set(attributes: CredentialAttributes, credentials: Credentials?) {
|
||||
val serviceNamePointer = stringPointer(attributes.serviceName.toByteArray())
|
||||
val accountName = attributes.accountName ?: credentials?.userName
|
||||
val accountName = attributes.userName ?: credentials?.userName
|
||||
if (credentials.isEmpty()) {
|
||||
checkError("secret_password_store_sync") { errorRef ->
|
||||
if (accountName == null) {
|
||||
|
||||
@@ -37,17 +37,17 @@ private const val kSecAccountItemAttr = (('a'.toInt() shl 8 or 'c'.toInt()) shl
|
||||
|
||||
internal class KeyChainCredentialStore() : CredentialStore {
|
||||
override fun get(attributes: CredentialAttributes): Credentials? {
|
||||
return findGenericPassword(attributes.serviceName.toByteArray(), attributes.accountName)
|
||||
return findGenericPassword(attributes.serviceName.toByteArray(), attributes.userName)
|
||||
}
|
||||
|
||||
override fun set(attributes: CredentialAttributes, credentials: Credentials?) {
|
||||
if (credentials.isEmpty()) {
|
||||
deleteGenericPassword(attributes.serviceName.toByteArray(), attributes.accountName!!)
|
||||
deleteGenericPassword(attributes.serviceName.toByteArray(), attributes.userName!!)
|
||||
return
|
||||
}
|
||||
|
||||
val password = credentials!!.password!!.toByteArray()
|
||||
saveGenericPassword(attributes.serviceName.toByteArray(), attributes.accountName ?: credentials.userName, password, password.size)
|
||||
saveGenericPassword(attributes.serviceName.toByteArray(), attributes.userName ?: credentials.userName, password, password.size)
|
||||
password.fill(0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.intellij.credentialStore
|
||||
|
||||
import com.intellij.util.nullize
|
||||
|
||||
data class CredentialAttributes(val serviceName: String, val accountName: String? = null) {
|
||||
data class CredentialAttributes(val serviceName: String, val userName: String? = null) {
|
||||
}
|
||||
|
||||
// user cannot be empty, but password can be
|
||||
@@ -32,4 +32,4 @@ class Credentials(user: String?, val password: String?) {
|
||||
override fun hashCode() = (userName?.hashCode() ?: 0) * 37 + (password?.hashCode() ?: 0)
|
||||
}
|
||||
|
||||
fun CredentialAttributes(requestor: Class<*>, accountName: String) = CredentialAttributes(requestor.name, accountName)
|
||||
fun CredentialAttributes(requestor: Class<*>, userName: String) = CredentialAttributes(requestor.name, userName)
|
||||
@@ -31,6 +31,6 @@ public interface CredentialStore {
|
||||
void set(@NotNull CredentialAttributes attributes, @Nullable Credentials credentials);
|
||||
|
||||
default void setPassword(@NotNull CredentialAttributes attributes, @Nullable String password) {
|
||||
set(attributes, password == null ? null : new Credentials(attributes.getAccountName(), password));
|
||||
set(attributes, password == null ? null : new Credentials(attributes.getUserName(), password));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ public abstract class BasePasswordSafeProvider implements PasswordStorage {
|
||||
byte[] masterKey = key();
|
||||
byte[] encryptedPassword = getEncryptedPassword(EncryptionUtil.encryptKey(masterKey, EncryptionUtil.rawKey(attributes)));
|
||||
String password = encryptedPassword == null ? null : EncryptionUtil.decryptText(masterKey, encryptedPassword);
|
||||
return password == null ? null : new Credentials(attributes.getAccountName(), password);
|
||||
return password == null ? null : new Credentials(attributes.getUserName(), password);
|
||||
}
|
||||
|
||||
protected abstract byte[] getEncryptedPassword(@NotNull byte[] key);
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ public class EncryptionUtil {
|
||||
}
|
||||
|
||||
static byte[] rawKey(@NotNull CredentialAttributes attributes) {
|
||||
return hash(getUTF8Bytes(attributes.getServiceName() + "/" + attributes.getAccountName()));
|
||||
return hash(getUTF8Bytes(attributes.getServiceName() + "/" + attributes.getUserName()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user