Skip to content

Commit

Permalink
LinuxSecretCredentialStoreFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Aug 11, 2016
1 parent f51d675 commit ea6ab35
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
37 changes: 35 additions & 2 deletions platform/credential-store/src/MacOsCredentialStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>()

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?
Expand Down Expand Up @@ -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)
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,5 +445,6 @@
<additionalTextAttributes scheme="Darcula" file="idea/FindViewColorsScheme.xml"/>

<credentialStore implementation="com.intellij.credentialStore.MacOsCredentialStoreFactory" os="mac"/>
<credentialStore implementation="com.intellij.credentialStore.LinuxSecretCredentialStoreFactory" os="linux"/>
</extensions>
</idea-plugin>

0 comments on commit ea6ab35

Please sign in to comment.