pub trait IDynamicAuthorizer: Send + Sync {
// Required method
fn authorize<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
claims: &'life1 dyn IClaims,
route_pattern: &'life2 str,
method: &'life3 str,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait;
// Provided method
fn authorize_with_rules<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>(
&'life0 self,
claims: &'life1 dyn IClaims,
route_pattern: &'life2 str,
method: &'life3 str,
_declared: &'life4 DeclaredRules<'life5>,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
'life5: 'async_trait,
Self: 'async_trait { ... }
}Expand description
Dynamic authorizer interface — pluggable authorization for protected routes.
Implement this trait and register it in the DI container:
svc.singleton::<dyn IDynamicAuthorizer>(|_| Arc::new(MyAuthorizer::default()))The framework automatically detects registered IDynamicAuthorizer implementations
and invokes them on every route that has #[authorize].
If no implementations are registered, authorization is pass-through (no dynamic checks).
§Methods
authorize— receives the user’s claims, matched route pattern, and HTTP method. ReturnsOk(())if allowed, orErrwith details if denied. Kept for source compatibility with 1.1.authorize_with_rules— same, plus the endpoint’sDeclaredRules(the rules written in#[authorize], AND-preserved per attribute). The framework calls this one; the default implementation forwards toauthorize, so an implementation that only overridesauthorizekeeps working unchanged.
Required Methods§
Validate whether the authenticated user can access the resource.
Provided Methods§
Validate access with the endpoint’s declared role / permission codes.
Override this instead of authorize when the authorization backend must
know which permission the endpoint declared (resource-instance checks,
permission-to-policy mapping, audit). Calls made through this method never
reach the overridden authorize when this one is overridden.
The default forwards to IDynamicAuthorizer::authorize, which keeps
1.1 implementations wire-compatible.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".