From ea6ab3594945f6e00857361cd7a526828145bee4 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 11 Aug 2016 18:22:14 +0200 Subject: [PATCH] LinuxSecretCredentialStoreFactory --- .../src/MacOsCredentialStore.kt | 37 ++++++++++++++++++- .../src/META-INF/PlatformExtensions.xml | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/platform/credential-store/src/MacOsCredentialStore.kt b/platform/credential-store/src/MacOsCredentialStore.kt index 87468d48150f..ef0255be4885 100644 --- a/platform/credential-store/src/MacOsCredentialStore.kt +++ b/platform/credential-store/src/MacOsCredentialStore.kt @@ -22,14 +22,29 @@ import com.intellij.ide.passwordSafe.PasswordStorage import com.intellij.openapi.diagnostic.catchAndLog import com.intellij.openapi.util.SystemInfo import com.intellij.util.SystemProperties +import com.intellij.util.concurrency.QueueProcessor +import com.intellij.util.containers.ContainerUtil + +private const val nullPassword = "\u0000" private class CredentialStoreWrapper(private val store: CredentialStore) : PasswordStorage { private val fallbackStore = lazy { FileCredentialStore(memoryOnly = true) } + private val queueProcessor = QueueProcessor<() -> Unit>({ + it() + }) + + private val postponedCredentials = ContainerUtil.newConcurrentMap() + override fun getPassword(requestor: Class<*>?, key: String): String? { + val rawKey = getRawKey(key, requestor) + + postponedCredentials.get(rawKey)?.let { + return if (it == nullPassword) null else it + } + var store = if (fallbackStore.isInitialized()) fallbackStore.value else store - val rawKey = getRawKey(key, requestor) // try old key - as hash @Suppress("CanBeVal") var value: String? @@ -62,7 +77,25 @@ private class CredentialStoreWrapper(private val store: CredentialStore) : Passw override fun setPassword(requestor: Class<*>?, key: String, value: String?) { LOG.catchAndLog { val store = if (fallbackStore.isInitialized()) fallbackStore.value else store - store.set(getRawKey(key, requestor), value?.toByteArray()) + val rawKey = getRawKey(key, requestor) + val passwordData = value?.toByteArray() + if (fallbackStore.isInitialized()) { + store.set(rawKey, passwordData) + } + else { + postponedCredentials.put(rawKey, value ?: nullPassword) + queueProcessor.add { + if (!fallbackStore.isInitialized()) { + LOG.catchAndLog { + store.set(rawKey, passwordData) + postponedCredentials.remove(rawKey) + return@add + } + } + fallbackStore.value.set(rawKey, passwordData) + postponedCredentials.remove(rawKey) + } + } } } } diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index 3876bfb786e4..0432a2ac4d79 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -445,5 +445,6 @@ +