AuthorizationPolicy

mbauer83.zio_http_authorization.AuthorizationPolicy$.AuthorizationPolicy
trait AuthorizationPolicy[U <: User[_, _], R <: Resource[_]]

Defines a policy for authorizing a specific type U of User.User to access a specific type R of Resource.Resource.

Reflection using scala.reflect.ClassTag is used so that the policy can be registered with an EndpointPolicyProvider.EndpointPolicyProvider.

Attributes

Example

Example usage

package mbauer83.zio_http_authorization
import zio.{ZIO, Console, ZIOAppDefault}
object PolicyAuthorizationExample extends ZIOAppDefault:
 type ResourceType <: Resource[_]
 type UserType <: User[_, _]
 def getUser: ZIO[Any, Nothing, UserType] = ???
 def getResource: ZIO[Any, Nothing, ResourceType] = ???
 def getPolicy: ZIO[Any, Nothing, AuthorizationPolicy[UserType, ResourceType]] = ???
 override val run = for {
   user <- getUser
   resource <- getResource
   policy <- getPolicy
   authorizedResource <- policy.authorized(user)(resource)
   _ <-  Console.printLine(authorizedResource)
 } yield ()
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Type members

Types

type ResourceType = R
type UserType = U

Value members

Abstract methods

def authorized[Res <: R | Iterable[R]](user: U)(resource: Res): ZIO[Any, UserNotAuthorizedForResourceException[_], Res]

An effect which either fails with a UserNotAuthorizedForResourceException or succeeds with the resource if the user is authorized to access the resource.

An effect which either fails with a UserNotAuthorizedForResourceException or succeeds with the resource if the user is authorized to access the resource.

If the resource is an scala.collection.Iterable, the effect must fail if and only if the user is not authorized to access any of the resources in the collection. Otherwise, it must succeed with a filtered version of the resource.

Attributes