Skip to main content

Authorize

Struct Authorize 

Source
pub struct Authorize<H> { /* private fields */ }
Expand description

A pre-transaction, fail-closed authorization behavior (ADR 0019).

It wraps an inner handler and holds the request’s Principal and the operation’s RequiredPermission (the facade method’s requires policy). On dispatch it runs the shared require_permission check and only delegates when it passes; on denial it returns a 403 Problem boxed as the port error and never calls the inner handler — so a caller without the permission cannot reach the mutation and, because this behavior is composed outside Transactional, no transaction is ever opened for the denied call.

It implements both CommandHandler and QueryHandler, so the same guard serves a write (Authorize → Validate → Transactional{…}) and a read (Authorize → CacheQueries → handler). An empty requirement (an unguarded operation) always passes, matching the tower permission_guard.

The returned 403 is status-bearing: it travels inside the port’s BoxError as a Problem, and Problem::from recovers it verbatim at the edge (it is not remapped to 500).

Implementations§

Source§

impl<H> Authorize<H>

Source

pub fn new(inner: H, principal: Principal, required: RequiredPermission) -> Self

Wraps inner, checking principal against required before each dispatch.

Use from_ctx to build directly from a request Ctx; this lower-level constructor is for a caller that already holds the principal and policy (and leaves the problem instance unset).

Source

pub fn from_ctx(inner: H, ctx: &Ctx, required: RequiredPermission) -> Self

Builds the behavior from a request Ctx and the operation’s RequiredPermission (read from the facade descriptor): the caller’s Principal and the path for the 403 instance are taken from the Ctx. This is the idiomatic per-request constructor.

Source

pub fn inner(&self) -> &H

Borrows the wrapped inner handler/behavior.

Trait Implementations§

Source§

impl<C, H> CommandHandler<C> for Authorize<H>
where C: Command, H: CommandHandler<C>,

Source§

async fn handle(&self, cmd: C) -> PortResult<C::Output>

Handle cmd, returning its Output or an error.
Source§

impl<Q, H> QueryHandler<Q> for Authorize<H>
where Q: Query, H: QueryHandler<Q>,

Source§

async fn handle(&self, query: Q) -> PortResult<Q::Output>

Handle query, returning its Output or an error.

Auto Trait Implementations§

§

impl<H> Forget for Authorize<H>

§

impl<H> Freeze for Authorize<H>
where H: Freeze,

§

impl<H> Move for Authorize<H>

§

impl<H> RefUnwindSafe for Authorize<H>
where H: RefUnwindSafe,

§

impl<H> Send for Authorize<H>
where H: Send,

§

impl<H> Sync for Authorize<H>
where H: Sync,

§

impl<H> Unpin for Authorize<H>
where H: Unpin,

§

impl<H> UnsafeUnpin for Authorize<H>
where H: UnsafeUnpin,

§

impl<H> UnwindSafe for Authorize<H>
where H: UnwindSafe,

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> 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<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