Scala Play 2.5使用Deadbolt-2操作的动作组合

问题描述:

我正在开发一个Scala Play应用程序,并且需要许多控制器操作,通过在响应的HTTP标头中设置参数来禁用浏览器的缓存。我决定创建一个NoCache复合动作,因为我也是用呆-2(并且需要呆-2的AuthenticatedRequest[_])它看起来像这样:Scala Play 2.5使用Deadbolt-2操作的动作组合

package action 

import be.objectify.deadbolt.scala.AuthenticatedRequest 
import play.api.http.HeaderNames 
import play.api.mvc._ 

import scala.concurrent.Future 
import scala.util.Success 

case class NoCache[A](action: Action[A]) extends Action[A] with HeaderNames { 
    def apply(request: AuthenticatedRequest[A]): Future[Result] = { 
    action(request).andThen { 
     case Success(result) => result.withHeaders(
     (CACHE_CONTROL -> "no-cache, no-store, must-revalidate"), 
     (PRAGMA -> "no-cache"), 
     (EXPIRES -> "0") 
    ) 
    } 
    } 

    lazy val parser = action.parser 
} 

但那么它不会编译试图在这一混合行动到我的控制器行动实施例如

def link = deadbolt.SubjectPresent()() andThen NoCache() { implicit request => 

def link = NoCache(deadbolt.SubjectPresent()()) { implicit request => 

,但不能看到如何撰写他们......

我发现如何做到这一点的一个动作:

def index = NoCache { 
    deadbolt.WithAuthRequest()() { implicit request => 
    Future { 
     Ok(views.html.index(userService)) 
    } 
    } 
} 

然而,我还没有找到如何将NoCache应用于整个控制器类。