Skip to main content

Access

Struct Access 

Source
pub struct Access<C, Who = Option<C>, Where = ()> { /* private fields */ }
Expand description

A configurable authentication, tenancy and permission policy.

C is the application’s caller type. Who and Where record what the route requires and become the types of its Grant; they change as the builder methods are called, starting from an optional caller and no tenancy. See the module documentation for the order of checks.

Implementations§

Source§

impl<C> Access<C>

Source

pub fn new( identify: impl Fn(&Claims) -> Option<C> + Send + Sync + 'static, ) -> Self

A policy whose callers are built from claims by identify.

identify returns None for claims that do not describe a caller. By default the caller is optional, gateway claims are trusted and no bearer token is verified.

Source§

impl<C, Who, Where> Access<C, Who, Where>

Source

pub fn gateway_claims(self, trust: bool) -> Self

Whether claims from an API Gateway authorizer identify the caller. On by default.

Source

pub fn gateway_token_claims(self, read: bool) -> Self

Reads gateway claims from the bearer token the authorizer verified, with their JSON types, instead of the authorizer’s strings. Off by default.

Turn it on when a claim is an object, such as Keycloak’s realm_access, only if the authorizer verifies the exact Authorization bearer token; see Claims::from_gateway_token’s trust requirements. A request whose token cannot be read is identified from the authorizer’s claims, as without this setting.

Source

pub fn verify_bearer(self, verifier: Arc<Verifier>) -> Self

Also identifies callers by an Authorization bearer token, verified with verifier.

The header may be Bearer <token> or the bare token. A value with another scheme (Basic …, a custom scheme) is not a caller token and leaves the request anonymous.

Source

pub fn permit( self, rule: impl Fn(Option<&C>, Option<&str>) -> bool + Send + Sync + 'static, ) -> Self

A permission rule over the caller and the selected tenant, checked last. Returning false refuses with Refusals::forbidden.

The caller is an Option even on a route that requires one, so a rule states explicitly what an anonymous request may do.

Source

pub fn refusals(self, refusals: Refusals) -> Self

Replaces the refusals, for an application with its own codes.

Source§

impl<C, Where> Access<C, Option<C>, Where>

Source

pub fn require_caller(self) -> Access<C, C, Where>

Refuses requests without a caller; the grant then holds a C.

Source§

impl<C, Who> Access<C, Who, ()>

Source

pub fn tenancy(self, tenancy: Tenancy<C>) -> Access<C, Who, Option<String>>

Selects a tenant per request; the grant then holds an Option<String>.

Source§

impl<C, Who> Access<C, Who, Option<String>>

Source

pub fn require_tenant(self) -> Access<C, Who, String>

Refuses requests without a tenant; the grant then holds a String.

Trait Implementations§

Source§

impl<C, Who, Where> Debug for Access<C, Who, Where>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C, Who, Where> Policy for Access<C, Who, Where>
where C: Send + 'static, Who: Requirement<C> + Send + 'static, Where: Requirement<String> + Send + 'static,

Source§

type Scope = Grant<Who, Where>

What a successful authorization establishes.
Source§

async fn authorize( &self, request: &Request<'_>, _invocation: &Invocation, ) -> Result<Self::Scope, Failure>

Authorizes the request, after it has been decoded. Read more

Auto Trait Implementations§

§

impl<C, Who = Option<C>, Where = ()> !RefUnwindSafe for Access<C, Who, Where>

§

impl<C, Who = Option<C>, Where = ()> !UnwindSafe for Access<C, Who, Where>

§

impl<C, Who, Where> Freeze for Access<C, Who, Where>

§

impl<C, Who, Where> Send for Access<C, Who, Where>
where Arc<dyn Fn(&Claims) -> Option<C> + Send + Sync>: Send, Option<Tenancy<C>>: Send, Option<Arc<dyn Fn(Option<&C>, Option<&str>) -> bool + Send + Sync>>: Send, PhantomData<fn() -> (Who, Where)>: Send,

§

impl<C, Who, Where> Sync for Access<C, Who, Where>
where Arc<dyn Fn(&Claims) -> Option<C> + Send + Sync>: Sync, Option<Tenancy<C>>: Sync, Option<Arc<dyn Fn(Option<&C>, Option<&str>) -> bool + Send + Sync>>: Sync, PhantomData<fn() -> (Who, Where)>: Sync,

§

impl<C, Who, Where> Unpin for Access<C, Who, Where>
where Arc<dyn Fn(&Claims) -> Option<C> + Send + Sync>: Unpin, Option<Tenancy<C>>: Unpin, Option<Arc<dyn Fn(Option<&C>, Option<&str>) -> bool + Send + Sync>>: Unpin, PhantomData<fn() -> (Who, Where)>: Unpin,

§

impl<C, Who, Where> UnsafeUnpin for Access<C, Who, Where>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Requirement<T> for T

Source§

const REQUIRED: bool = const REQUIRED: bool = true;

Whether a request without the value is refused.
Source§

fn fulfill(found: Option<T>) -> Option<T>

Converts what was found, or None when a required value is missing.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more