• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala WrappedRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala FilePart类代码示例发布时间:2022-05-23
下一篇:
Scala Provider类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap