当前位置: 首页>>代码示例>>Scala>>正文


Scala WrappedRequest类代码示例

本文整理汇总了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})"
} 
开发者ID:ejisan,项目名称:play-scalauth-secureaction,代码行数:41,代码来源:SecureRequest.scala

示例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))
} 
开发者ID:UKGovernmentBEIS,项目名称:das-alpha-hmrc-api-mock,代码行数:31,代码来源:AuthAction.scala

示例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
      }
  }

} 
开发者ID:toolsplus,项目名称:atlassian-connect-play,代码行数:27,代码来源:LifecycleActions.scala

示例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)
    }
  }

} 
开发者ID:tobnee,项目名称:sirenator,代码行数:19,代码来源:ConditionalLayout.scala

示例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 !!"))
    }
  }
} 
开发者ID:geetikagupta16,项目名称:PlayAuthentication,代码行数:24,代码来源:SecuredAction.scala

示例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
      }
    })
  }
} 
开发者ID:jeroenbellen,项目名称:todo-app,代码行数:33,代码来源:TodoAction.scala

示例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)
    }

} 
开发者ID:nmarcin92,项目名称:ranker,代码行数:25,代码来源:Secured.scala


注:本文中的play.api.mvc.WrappedRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。