Skip to main content

Authorizer

Trait Authorizer 

Source
pub trait Authorizer<B> {
    // Required method
    fn process(
        &self,
        req: ServiceRequest,
        user: Option<&User>,
        next: impl FnOnce(ServiceRequest) -> LocalBoxFuture<'static, Result<ServiceResponse<B>, Error>> + 'static,
    ) -> LocalBoxFuture<'static, Result<ServiceResponse<EitherBody<B>>, Error>>;
}
Expand description

Trait for deciding whether an authenticated user can access a resource.

§Spring Equivalent

AccessDecisionManager / AuthorizationManager

The process method returns a boxed future that resolves to:

  • EitherBody::left() when forwarding to the inner service
  • EitherBody::right() for custom responses (redirects, forbidden, etc.)

Required Methods§

Source

fn process( &self, req: ServiceRequest, user: Option<&User>, next: impl FnOnce(ServiceRequest) -> LocalBoxFuture<'static, Result<ServiceResponse<B>, Error>> + 'static, ) -> LocalBoxFuture<'static, Result<ServiceResponse<EitherBody<B>>, Error>>

Processes the authorization decision.

§Arguments
  • req - The incoming request
  • user - The authenticated user (if any)
  • next - Closure to call the next service in the chain

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§