2017-03-29 47 views
0
class AuthorizedFilter extends EssentialFilter { 

    private def authorizationRequired(request: RequestHeader) = { 
    val clientId = request.headers.get("clientId"); 
    val id = "74f6df0452"; //to match with clientID.Block remaining request 
    clientId match { 
     case Some(id) => 
     true; 
     case _ => 
     false; 
    } 

    } 

    def apply(next: EssentialAction):EssentialAction = new EssentialAction { 
    def apply(request: RequestHeader) = { 
     println("result...",request.headers.get("clientId")); 

     if(!authorizationRequired(request)) { 
     *Iteratee.ignore[Array[Byte]].map(_ => Results.forbidden())* 
     } 
     else { 
     println("YOU are authorized!!") 
     next(request) 
     } 
     } 
    } 
} 

上面的過濾器被添加來阻止clientID不匹配的所有請求。我在Iteratee.ignore [Array [Byte]]。map(_ => Results.forbidden())中收到了錯誤消息。類型Iteratee [Array [Byte],StatusHeader]的表達式與Play scala中期望的類型Accumulater [Byte,Result]不一致?

回答

2

問題是,您從舊版本的播放框架中獲取了一段代碼,並且您現在使用的版本> = 2.5。您需要更換線Iteratee...

Accumulator.done(Results.forbidden()) 

CF documentation

相關問題