2014-05-19 152 views
4

我在噴霧項目中出現這個錯誤。爲什麼認證指令導致「錯誤:類型不匹配」?

Error:(41, 28) type mismatch; 
found : spray.routing.authentication.ContextAuthenticator[co.s4n.authentication.entities.Usuario] 
    (which expands to) spray.routing.RequestContext => scala.concurrent.Future[scala.util.Either[spray.routing.Rejection,co.s4n.authentication.entities.Usuario]] 
required: spray.routing.directives.AuthMagnet[?] 
       authenticate(validateToken) { 
         ^

這是我TokenValidator特質

trait TokenValidator { 

    def validateToken: ContextAuthenticator[Usuario] = { 
    ctx => 
     val header = ctx.request.headers.find(_.name == "Access_Token") 
     if (header isDefined) { 
     doAuth(header.get) 
     } 
     else { 
     Future(Left(AuthenticationFailedRejection(AuthenticationFailedRejection.CredentialsMissing, List()))) 
     } 
    } 

    def doAuth(header: HttpHeader): Future[Authentication[Usuario]] = { 
    Dao.validateToken(header.value).map { 
     case Some(usuario) => Right(usuario) 
     case None => Left(AuthenticationFailedRejection(AuthenticationFailedRejection.CredentialsRejected, List())) 
    } 
    } 


} 

而這正是I¡m收到這個錯誤

//@DELETE 
    //localhost:9090/authenticacion/users/{{userEmail}} 
    val `users/{{email}}` = 
    pathPrefix(`path-prefix`) { 
     pathPrefix(`users-path-prefix`/Segment) { 
     emailRef => { 
      delete { 
       authenticate(validateToken) { **HERE!!!!** 
       usuario => 
        ..... 
       } 
      } 
     } 
     } 
    } 

有誰知道我在做什麼錯了行?

泰克你提前!

回答

11

我唯一缺少的是ExecutionContext的範圍和import ExecutionContext.Implicits.global工作正常。

Future工作,因爲他們聲明瞭一個隱含的ExecutionContext參數。

+0

謝謝你,救了我一些時間) – Ashalynd

0

我知道這是一個很長的時間,因爲實際的問題就來了,但去與這對噴塗的方法是確定與噴霧提供的工具執行上下文:

implicit def executionContext = actorRefFactory.dispatcher 
相關問題