PageRenderTime 42ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/scala/com/ouchload/auth/SprayMongoAuthenticator.scala

https://github.com/ctcarrier/ouchload
Scala | 35 lines | 25 code | 6 blank | 4 comment | 0 complexity | e9ed59d7106549167649f5e9aec3a399 MD5 | raw file
  1. package com.ouchload.auth
  2. import org.bson.types.ObjectId
  3. import cc.spray._
  4. import cc.spray.http.{BasicHttpCredentials, HttpCredentials}
  5. import com.mongodb.casbah.MongoConnection._
  6. import com.mongodb.casbah.MongoConnection
  7. import com.mongodb.casbah.commons.MongoDBObject
  8. import com.mongodb.casbah.commons.Imports._
  9. import com.novus.salat._
  10. import com.novus.salat.global._
  11. import akka.event.EventHandler
  12. /**
  13. * @author chris_carrier
  14. * @version 10/19/11
  15. */
  16. object FromMongoUserPassAuthenticator extends UserPassAuthenticator[BasicUserContext] {
  17. def apply(userPass: Option[(String, String)]) = {
  18. EventHandler.info(this, "Mongo auth")
  19. userPass.flatMap {
  20. case (user, pass) => {
  21. val db = MongoConnection()("mycotrack")("users")
  22. val userResult = db.findOne(MongoDBObject("username" -> user) ++ ("password" -> pass))
  23. userResult.map(grater[BasicUserContext].asObject(_))
  24. }
  25. case _ => None
  26. }
  27. }
  28. }
  29. case class BasicUserContext(_id: ObjectId, username: String, password: String)