pub struct TenantResolverMiddleware<R> { /* private fields */ }Expand description
在 Action 派发前解析并注入可信租户上下文。
中间件读取 TENANT_ID_HEADER,只接受正整数。它不会自行信任该值,而是把候选
交给 TenantResolver;resolver 成功返回后才写入 ActionContext。
注册顺序必须放在身份认证中间件之后,使 resolver 能读取
ActionContext::authenticated_user。如果 resolver 允许匿名租户,它也必须显式
实现该策略。
Implementations§
Source§impl<R> TenantResolverMiddleware<R>where
R: TenantResolver,
impl<R> TenantResolverMiddleware<R>where
R: TenantResolver,
Trait Implementations§
Source§impl<R> Middleware for TenantResolverMiddleware<R>where
R: TenantResolver,
impl<R> Middleware for TenantResolverMiddleware<R>where
R: TenantResolver,
Source§fn role(&self) -> MiddlewareRole
fn role(&self) -> MiddlewareRole
返回构建期可验证的安全依赖角色。
Source§fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
context: ActionContext,
next: Next<'life1>,
) -> Pin<Box<dyn Future<Output = Result<ApiResponse, BaseError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
context: ActionContext,
next: Next<'life1>,
) -> Pin<Box<dyn Future<Output = Result<ApiResponse, BaseError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
处理一次派发。 Read more
Source§fn scope(&self) -> MiddlewareScope
fn scope(&self) -> MiddlewareScope
返回此中间件适用的 Action 范围。 Read more
Auto Trait Implementations§
impl<R> Freeze for TenantResolverMiddleware<R>where
R: Freeze,
impl<R> RefUnwindSafe for TenantResolverMiddleware<R>where
R: RefUnwindSafe,
impl<R> Send for TenantResolverMiddleware<R>where
R: Send,
impl<R> Sync for TenantResolverMiddleware<R>where
R: Sync,
impl<R> Unpin for TenantResolverMiddleware<R>where
R: Unpin,
impl<R> UnsafeUnpin for TenantResolverMiddleware<R>where
R: UnsafeUnpin,
impl<R> UnwindSafe for TenantResolverMiddleware<R>where
R: UnwindSafe,
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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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