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>
impl<C> Access<C>
Sourcepub fn new(
identify: impl Fn(&Claims) -> Option<C> + Send + Sync + 'static,
) -> Self
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>
impl<C, Who, Where> Access<C, Who, Where>
Sourcepub fn gateway_claims(self, trust: bool) -> Self
pub fn gateway_claims(self, trust: bool) -> Self
Whether claims from an API Gateway authorizer identify the caller. On by default.
Sourcepub fn gateway_token_claims(self, read: bool) -> Self
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.
Sourcepub fn verify_bearer(self, verifier: Arc<Verifier>) -> Self
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.
Sourcepub fn permit(
self,
rule: impl Fn(Option<&C>, Option<&str>) -> bool + Send + Sync + 'static,
) -> Self
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§impl<C, Where> Access<C, Option<C>, Where>
impl<C, Where> Access<C, Option<C>, Where>
Sourcepub fn require_caller(self) -> Access<C, C, Where>
pub fn require_caller(self) -> Access<C, C, Where>
Refuses requests without a caller; the grant then holds a C.
Trait Implementations§
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,
impl<C, Who, Where> Policy for Access<C, Who, Where>where
C: Send + 'static,
Who: Requirement<C> + Send + 'static,
Where: Requirement<String> + Send + 'static,
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>
impl<C, Who, Where> Sync for Access<C, Who, Where>
impl<C, Who, Where> Unpin for Access<C, Who, Where>
impl<C, Who, Where> UnsafeUnpin for Access<C, Who, Where>where
Arc<dyn Fn(&Claims) -> Option<C> + Send + Sync>: UnsafeUnpin,
Option<Tenancy<C>>: UnsafeUnpin,
Option<Arc<dyn Fn(Option<&C>, Option<&str>) -> bool + Send + Sync>>: UnsafeUnpin,
PhantomData<fn() -> (Who, Where)>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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