play.api.mvc.Security

AuthenticatedBuilder

class AuthenticatedBuilder[U] extends ActionBuilder[[A]AuthenticatedRequest[A, U]]

An authenticated action builder.

This can be used to create an action builder, like so:

// in a Security trait
object Authenticated extends AuthenticatedBuilder(req => getUserFromRequest(req))

// then in a controller
def index = Authenticated { implicit request =>
  Ok("Hello " + request.user)
}

It can also be used from an action builder, for example:

class AuthenticatedDbRequest[A](val user: User,
                                val conn: Connection,
                                request: Request[A]) extends WrappedRequest[A](request)

object Authenticated extends ActionBuilder[AuthenticatedDbRequest] {
  def invokeBlock[A](request: Request[A], block: (AuthenticatedDbRequest[A]) => Future[SimpleResult]) = {
    AuthenticatedBuilder(req => getUserFromRequest(req)).authenticate(request, { authRequest: AuthenticatedRequest[A, User] =>
      DB.withConnection { conn =>
        block(new AuthenticatedDbRequest[A](authRequest.user, conn, request))
      }
    })
  }
}
Source
Security.scala
Linear Supertypes
ActionBuilder[[A]AuthenticatedRequest[A, U]], AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. AuthenticatedBuilder
  2. ActionBuilder
  3. AnyRef
  4. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new AuthenticatedBuilder(userinfo: (RequestHeader) ⇒ Option[U], onUnauthorized: (RequestHeader) ⇒ SimpleResult = ...)

    userinfo

    The function that looks up the user info.

    onUnauthorized

    The function to get the result for when no authenticated user can be found.

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def apply(block: ⇒ Result): Action[AnyContent]

    Constructs an Action with default content, and no request parameter.

    Constructs an Action with default content, and no request parameter.

    For example:

    val hello = Action {
    Ok("Hello!")
    }
    block

    the action code

    returns

    an action

    Definition Classes
    ActionBuilder
  7. final def apply(block: (AuthenticatedRequest[AnyContent, U]) ⇒ Result): Action[AnyContent]

    Constructs an Action with default content.

    Constructs an Action with default content.

    For example:

    val echo = Action { request =>
    Ok("Got request [" + request + "]")
    }
    block

    the action code

    returns

    an action

    Definition Classes
    ActionBuilder
  8. final def apply[A](bodyParser: BodyParser[A])(block: (AuthenticatedRequest[A, U]) ⇒ Result): Action[A]

    Constructs an Action.

    Constructs an Action.

    For example:

    val echo = Action(parse.anyContent) { request =>
    Ok("Got request [" + request + "]")
    }
    A

    the type of the request body

    bodyParser

    the BodyParser to use to parse the request body

    block

    the action code

    returns

    an action

    Definition Classes
    ActionBuilder
  9. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  10. final def async[A](bodyParser: BodyParser[A])(block: (AuthenticatedRequest[A, U]) ⇒ Future[SimpleResult]): Action[A]

    Constructs an Action that returns a future of a result, with default content.

    Constructs an Action that returns a future of a result, with default content.

    For example:

    val hello = Action.async { request =>
    WS.url(request.getQueryString("url").get).get().map { r =>
      if (r.status == 200) Ok("The website is up") else NotFound("The website is down")
    }
    }
    block

    the action code

    returns

    an action

    Definition Classes
    ActionBuilder
  11. final def async(block: (AuthenticatedRequest[AnyContent, U]) ⇒ Future[SimpleResult]): Action[AnyContent]

    Constructs an Action that returns a future of a result, with default content.

    Constructs an Action that returns a future of a result, with default content.

    For example:

    val hello = Action.async { request =>
    WS.url(request.getQueryString("url").get).get().map { r =>
      if (r.status == 200) Ok("The website is up") else NotFound("The website is down")
    }
    }
    block

    the action code

    returns

    an action

    Definition Classes
    ActionBuilder
  12. final def async(block: ⇒ Future[SimpleResult]): Action[AnyContent]

    Constructs an Action that returns a future of a result, with default content, and no request parameter.

    Constructs an Action that returns a future of a result, with default content, and no request parameter.

    For example:

    val hello = Action.async {
    WS.url("http://www.playframework.com").get().map { r =>
      if (r.status == 200) Ok("The website is up") else NotFound("The website is down")
    }
    }
    block

    the action code

    returns

    an action

    Definition Classes
    ActionBuilder
  13. def authenticate[A](request: Request[A], block: (AuthenticatedRequest[A, U]) ⇒ Future[SimpleResult]): Future[SimpleResult]

    Authenticate the given block.

  14. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  15. def composeAction[A](action: Action[A]): Action[A]

    Compose the action with other actions.

    Compose the action with other actions. This allows mixing in of various actions together.

    action

    The action to compose

    returns

    The composed action

    Attributes
    protected
    Definition Classes
    ActionBuilder
  16. def composeParser[A](bodyParser: BodyParser[A]): BodyParser[A]

    Compose the parser.

    Compose the parser. This allows the action builder to potentially intercept requests before they are parsed.

    bodyParser

    The body parser to compose

    returns

    The composed body parser

    Attributes
    protected
    Definition Classes
    ActionBuilder
  17. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  18. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  19. def executionContext: ExecutionContext

    Get the execution context to run the request in.

    Get the execution context to run the request in. Override this if you want a custom execution context

    returns

    The execution context

    Attributes
    protected
    Definition Classes
    ActionBuilder
  20. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  21. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  22. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  23. def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A, U]) ⇒ Future[SimpleResult]): Future[SimpleResult]

    Invoke the block.

    Invoke the block. This is the main method that an ActionBuilder has to implement, at this stage it can wrap it in any other actions, modify the request object or potentially use a different class to represent the request.

    request

    The request

    block

    The block of code to invoke

    returns

    A future of the result

    Definition Classes
    AuthenticatedBuilderActionBuilder
  24. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  25. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  26. final def notify(): Unit

    Definition Classes
    AnyRef
  27. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  28. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  29. def toString(): String

    Definition Classes
    AnyRef → Any
  30. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from ActionBuilder[[A]AuthenticatedRequest[A, U]]

Inherited from AnyRef

Inherited from Any

Ungrouped