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>
impl<H> Authorize<H>
Sourcepub fn new(inner: H, principal: Principal, required: RequiredPermission) -> Self
pub fn new(inner: H, principal: Principal, required: RequiredPermission) -> Self
Sourcepub fn from_ctx(inner: H, ctx: &Ctx, required: RequiredPermission) -> Self
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.