convert fileStore to native credential store if eap or snapshot

This commit is contained in:
Vladimir Krivosheev
2016-08-05 21:42:50 +02:00
parent 00e0fd862d
commit 36a4a7fb3e
2 changed files with 20 additions and 3 deletions
@@ -155,6 +155,12 @@ class FileCredentialStore(keyToValue: Map<String, String>? = null, baseDirectory
needToSave.set(true)
}
}
fun copyTo(store: PasswordStorage) {
for ((k, v) in db) {
store.setPassword(k, v)
}
}
}
internal fun getRawKey(key: String?, requestor: Class<*>?) = "${if (requestor == null) "" else "${requestor.name}/"}$key"
@@ -20,6 +20,7 @@ import com.intellij.ide.passwordSafe.config.PasswordSafeSettings
import com.intellij.ide.passwordSafe.config.PasswordSafeSettings.ProviderType
import com.intellij.ide.passwordSafe.macOs.isMacOsCredentialStoreSupported
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.ex.ApplicationInfoEx
import com.intellij.openapi.components.SettingsSavingComponent
import com.intellij.openapi.diagnostic.catchAndLog
@@ -39,7 +40,8 @@ class PasswordSafeImpl(/* public - backward compatibility */val settings: Passwo
currentProvider = FileCredentialStore(memoryOnly = true)
}
else {
currentProvider = createPersistentCredentialStore()
val appInfo = ApplicationInfoEx.getInstanceEx()
currentProvider = createPersistentCredentialStore(convertFileStore = appInfo.build.isSnapshot || appInfo.isEAP)
}
ApplicationManager.getApplication().messageBus.connect().subscribe(PasswordSafeSettings.TOPIC, object: PasswordSafeSettingsListener {
@@ -124,10 +126,19 @@ class PasswordSafeImpl(/* public - backward compatibility */val settings: Passwo
internal const val CREDENTIAL_STORE_SERVICE_NAME = "IntelliJ Platform"
private fun createPersistentCredentialStore(existing: FileCredentialStore? = null): PasswordStorage {
private fun createPersistentCredentialStore(existing: FileCredentialStore? = null, convertFileStore: Boolean = false): PasswordStorage {
LOG.catchAndLog {
if (isMacOsCredentialStoreSupported && com.intellij.util.SystemProperties.getBooleanProperty("use.mac.keychain", true)) {
return MacOsCredentialStore(CREDENTIAL_STORE_SERVICE_NAME)
val store = MacOsCredentialStore(CREDENTIAL_STORE_SERVICE_NAME)
if (convertFileStore) {
LOG.catchAndLog {
val fileStore = FileCredentialStore()
fileStore.copyTo(store)
fileStore.clear()
fileStore.save()
}
}
return store
}
}