我正在传播此博客以了解操作:
http://www.tzavellas.com/techblog/2015/02/10/action-composition-in-play-framework/
为什么需要扩展ActionBuilder?仅扩展ActionRefiner还不够吗?这里的ActionBuilder的目的是什么?
object AuthenticatedAction
extends ActionBuilder[AuthenticatedRequest]
with ActionRefiner[Request, AuthenticatedRequest] {
def refine[T](request: Request[T]): Future[Either[Result, AuthenticatedRequest[T]]] = {
val result = request.session.get("username")
.flatMap(User.findByUsername(_))
.map(user => new AuthenticatedRequest[T](user, request))
.toRight(left = Results.Forbidden)
Future.successful(result)
}
}