本文整理汇总了Scala中play.api.mvc.WrappedRequest类的典型用法代码示例。如果您正苦于以下问题:Scala WrappedRequest类的具体用法?Scala WrappedRequest怎么用?Scala WrappedRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WrappedRequest类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: isSuccess
//设置package包名称以及导入依赖的类
package ejisan.play.libs.scalauth
import play.api.mvc.{ Request, WrappedRequest }
trait SecureRequest[A] extends WrappedRequest[A] {
def isSuccess: Boolean
def isFailure: Boolean = ! isSuccess
override def toString: String = s"SecureRequest(${SecureRequest.unapply(this).get.toString})"
}
object SecureRequest {
def apply[A](request: Request[A]): UnauthorizedRequest[A] =
new UnauthorizedRequest(request)
def apply[A, S](request: Request[A], subject: S): AuthenticatedRequest[A, S] =
new AuthenticatedRequest(request, subject)
def anonymous[A](request: Request[A]): AuthenticatedRequest[A, _] = apply(request, None)
def unapply[A](request: SecureRequest[A]): Option[(Request[A])]
= Some((request.map(r => r)))
}
class AuthenticatedRequest[A, S](request: Request[A], subject: S)
extends WrappedRequest[A](request) with SecureRequest[A] {
def isSuccess: Boolean = true
def get: S = subject
override def toString: String = s"AuthenticatedRequest(${request.toString}, ${subject.toString})"
}
class AnonymousRequest[A](request: Request[A])
extends WrappedRequest[A](request) with SecureRequest[A] {
def isSuccess: Boolean = true
override def toString: String = s"AnonymousRequest(${request.toString})"
}
class UnauthorizedRequest[A](request: Request[A]) extends AnonymousRequest[A](request) {
override def isSuccess: Boolean = false
override def toString: String = s"UnauthorizedRequest(${request.toString})"
}
示例2: AuthRequest
//设置package包名称以及导入依赖的类
package uk.gov.bis.levyApiMock.actions
import play.api.mvc.Results._
import play.api.mvc.{ActionBuilder, Request, Result, WrappedRequest}
import uk.gov.bis.levyApiMock.data.oauth2.AuthRecord
import scala.concurrent.{ExecutionContext, Future}
case class AuthRequest[+A](authRecord: AuthRecord, request: Request[A]) extends WrappedRequest(request)
trait AuthAction extends ActionBuilder[AuthRequest] {
implicit val ec: ExecutionContext
override def invokeBlock[A](request: Request[A], next: (AuthRequest[A]) => Future[Result]): Future[Result] = {
val BearerToken = "Bearer (.+)".r
request.headers.get("Authorization") match {
case Some(BearerToken(accessToken)) => validateToken(accessToken).flatMap {
case Some(authRecord) => next(AuthRequest(authRecord, request))
case None => unauthorized("Bearer token does not grant access to the requested resource")
}
case Some(h) => unauthorized("Authorization header should be a Bearer token")
case None => unauthorized("No Authorization header found")
}
}
def validateToken(accessToken: String): Future[Option[AuthRecord]]
private def unauthorized(message: String): Future[Result] = Future.successful(Unauthorized(message))
}
示例3: LifecycleActions
//设置package包名称以及导入依赖的类
package io.toolsplus.atlassian.connect.play.actions
import io.toolsplus.atlassian.connect.play.models.LifecycleEvent
import play.api.mvc.{ActionFilter, Request, Result, WrappedRequest}
import play.api.mvc.Results._
import scala.concurrent.Future
object LifecycleActions {
case class LifecycleRequest[A](event: LifecycleEvent, request: Request[A])
extends WrappedRequest[A](request)
case class CheckLifecycleEventTypeAction(expectedEventType: String)
extends ActionFilter[LifecycleRequest] {
override def filter[A](
request: LifecycleRequest[A]): Future[Option[Result]] =
Future.successful {
if (request.event.eventType != expectedEventType)
Some(BadRequest("Invalid lifecycle event type"))
else
None
}
}
}
示例4: ConditionalLayoutRequest
//设置package包名称以及导入依赖的类
package helpers
import play.api.mvc.{ActionBuilder, WrappedRequest, Request, ActionTransformer}
import scala.concurrent.Future
trait ConditionalLayout {
class ConditionalLayoutRequest[A](val requiresLayout: Boolean,
request: Request[A]) extends WrappedRequest[A](request)
object ConditionalLayoutAction extends ActionBuilder[ConditionalLayoutRequest] with ActionTransformer[Request, ConditionalLayoutRequest] {
override protected def transform[A](request: Request[A]) = Future.successful {
val layoutRequired = request.headers.get("X-PJAX") != Some("true")
new ConditionalLayoutRequest[A](requiresLayout = layoutRequired, request)
}
}
}
示例5: UserRequest
//设置package包名称以及导入依赖的类
package controllers.security
import scala.concurrent.Future
import models.User
import play.api.mvc.{ActionBuilder, Request, Result, Results, WrappedRequest}
import services.UserService
case class UserRequest[A](val userName: String, val request: Request[A])
extends WrappedRequest[A](request)
object SecuredAction extends ActionBuilder[UserRequest] {
override def invokeBlock[A](request: Request[A],
block: (UserRequest[A]) => Future[Result]): Future[Result] = {
val userName = request.headers.get("username").fold("")(identity)
if (UserService.getAllUsers().contains(User(userName))) {
block(UserRequest(userName, request))
} else {
Future.successful(Results.Unauthorized("Unauthorized access !!"))
}
}
}
示例6: TodoRequest
//设置package包名称以及导入依赖的类
package todo
import javax.inject.{Inject, Singleton}
import play.api.http.HttpVerbs
import play.api.mvc.{ActionBuilder, Request, Result, WrappedRequest}
import scala.concurrent.{ExecutionContext, Future}
class TodoRequest[A](request: Request[A])
extends WrappedRequest(request)
@Singleton
class TodoAction @Inject()(implicit ec: ExecutionContext)
extends ActionBuilder[TodoRequest]
with HttpVerbs {
override def invokeBlock[A](request: Request[A], block: (TodoRequest[A]) => Future[Result]) = {
val future = block(new TodoRequest(request))
future.map(result => {
request.method match {
case GET | HEAD =>
result.withHeaders("Cache-Control" -> s"max-age: 1000")
case other =>
result
}
})
}
}
示例7: AuthenticatedRequest
//设置package包名称以及导入依赖的类
package controllers.auth
import pdi.jwt._
import play.api.libs.concurrent.Execution.Implicits._
import play.api.mvc.Results._
import play.api.mvc.{ActionBuilder, Request, Result, WrappedRequest}
import scala.concurrent.Future
class AuthenticatedRequest[A](val userInfo: UserAuthInfo, request: Request[A]) extends WrappedRequest[A](request)
trait Secured {
def Authenticated = AuthenticatedAction
}
object AuthenticatedAction extends ActionBuilder[AuthenticatedRequest] {
override def invokeBlock[A](request: Request[A],
block: (AuthenticatedRequest[A]) => Future[Result]): Future[Result] =
request.jwtSession.getAs[UserAuthInfo]("user") match {
case Some(user) => block(new AuthenticatedRequest(user, request)).map(_.refreshJwtSession(request))
case _ => Future.successful(Unauthorized)
}
}