我今天将我的 Play 应用程序从 2.5 升级到 2.6,但我遇到了 ActionBuilder 的问题。文档状态:
Scala ActionBuilder trait 已被修改为将主体的类型指定为类型参数,并添加一个抽象解析器成员作为默认的主体解析器。您将需要修改您的 ActionBuilders 并直接传递正文解析器。
可悲的是我没有找到任何例子,我不知道如何解决这个问题:
class AuthenticatedRequest[A](val token: ProfileTokenData, request: Request[A]) extends WrappedRequest[A](request)
trait Secured {
object SetExtractor {
def unapplySeq[T](s: Set[T]): Option[Seq[T]] = Some(s.toSeq)
}
def Authenticated = new ActionBuilder[AuthenticatedRequest] with JWTTokenProcess {
override def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] = {
request.jwtSession.claimData.asOpt[JWTToken] match {
case Some(token) => block(new AuthenticatedRequest(ProfileTokenData(null, token.sub, AuthRole.None), request)).map(_.refreshJwtSession(request))
case _ => Future.successful(Unauthorized)
}
}
}
def Registered = new ActionBuilder[AuthenticatedRequest] with JWTTokenProcess {
override def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] =
this.processJWTToken(request, block, Seq(AuthRole.Admin, AuthRole.Customer, AuthRole.Registered))
}
def Customer = new ActionBuilder[AuthenticatedRequest] with JWTTokenProcess {
override def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] =
this.processJWTToken(request, block, Seq(AuthRole.Admin, AuthRole.Customer))
}
def Admin = new ActionBuilder[AuthenticatedRequest] with JWTTokenProcess {
override def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] =
this.processJWTToken(request, block, Seq(AuthRole.Admin))
}
}
有谁知道我必须通过哪个 BodyParser 作为第二个参数?