mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
get rid of getOrCreateEntry to make code more clear
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.credentialStore.kdbx
|
||||
|
||||
import com.intellij.credentialStore.LOG
|
||||
@@ -112,13 +112,10 @@ internal class KdbxGroup(internal val element: Element, private val database: Ke
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun getOrCreateEntry(title: String, userName: String?): KdbxEntry {
|
||||
var entry = getEntry(title, userName)
|
||||
if (entry == null) {
|
||||
entry = database.createEntry(title)
|
||||
entry.userName = userName
|
||||
addEntry(entry)
|
||||
}
|
||||
fun createEntry(title: String, userName: String?): KdbxEntry {
|
||||
val entry = database.createEntry(title)
|
||||
entry.userName = userName
|
||||
addEntry(entry)
|
||||
return entry
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.credentialStore.keePass
|
||||
|
||||
import com.intellij.credentialStore.CredentialAttributes
|
||||
@@ -13,7 +13,8 @@ internal abstract class BaseKeePassCredentialStore : CredentialStore {
|
||||
protected abstract val db: KeePassDatabase
|
||||
|
||||
override fun get(attributes: CredentialAttributes): Credentials? {
|
||||
val entry = db.rootGroup.getGroup(ROOT_GROUP_NAME)?.getEntry(attributes.serviceName, attributes.userName) ?: return null
|
||||
val group = db.rootGroup.getGroup(ROOT_GROUP_NAME) ?: return null
|
||||
val entry = group.getEntry(attributes.serviceName, attributes.userName) ?: return null
|
||||
return Credentials(attributes.userName ?: entry.userName, entry.password?.get())
|
||||
}
|
||||
|
||||
@@ -27,9 +28,11 @@ internal abstract class BaseKeePassCredentialStore : CredentialStore {
|
||||
val userName = attributes.userName ?: credentials.userName
|
||||
var entry = group.getEntry(attributes.serviceName, if (attributes.serviceName == SERVICE_NAME_PREFIX) userName else null)
|
||||
if (entry == null) {
|
||||
entry = group.getOrCreateEntry(attributes.serviceName, userName)
|
||||
entry = group.createEntry(attributes.serviceName, userName)
|
||||
}
|
||||
else {
|
||||
entry.userName = userName
|
||||
}
|
||||
entry.userName = userName
|
||||
entry.password = if (attributes.isPasswordMemoryOnly || credentials.password == null) null else db.protectValue(credentials.password!!)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user