move filtering into the database

This commit is contained in:
Herr Ritschwumm
2016-05-05 22:42:22 +02:00
parent 0a532d9774
commit 7b23bbf9ba
2 changed files with 2 additions and 5 deletions

View File

@@ -13,7 +13,7 @@ trait SshKeyService {
SshKeys.filter(_.userName === userName.bind).sortBy(_.sshKeyId).list SshKeys.filter(_.userName === userName.bind).sortBy(_.sshKeyId).list
def getAllKeys()(implicit s: Session): List[SshKey] = def getAllKeys()(implicit s: Session): List[SshKey] =
SshKeys.list SshKeys.filter(_.publicKey.trim =!= "").list
def deletePublicKey(userName: String, sshKeyId: Int)(implicit s: Session): Unit = def deletePublicKey(userName: String, sshKeyId: Int)(implicit s: Session): Unit =
SshKeys filter (_.byPrimaryKey(userName, sshKeyId)) delete SshKeys filter (_.byPrimaryKey(userName, sshKeyId)) delete

View File

@@ -51,10 +51,7 @@ class PublicKeyAuthenticator(genericUser:String) extends PublickeyAuthenticator
Database() Database()
.withSession { implicit dbSession => getAllKeys() } .withSession { implicit dbSession => getAllKeys() }
.filter { sshKey => .filter { sshKey =>
Option(sshKey.publicKey) SshUtil.str2PublicKey(sshKey.publicKey).exists(_ == key)
.filter(_.trim.nonEmpty)
.flatMap(SshUtil.str2PublicKey)
.exists(_ == key)
} }
.map(_.userName) .map(_.userName)
.distinct .distinct