pub struct StepUpMiddleware<R> { /* private fields */ }Expand description
为一个确定 Action 强制执行短期重认证的中间件。
中间件必须注册在身份认证中间件之后。它只拦截构造时绑定的 Action;当前实际
Action 身份由 Registry 在派发边界覆盖注入,不能由客户端声明。缺少 proof 时
返回携带短期 challenge 的 BaseError::StepUpRequired;存在但无效的 proof
直接拒绝,不降级为新 challenge。
§约束范围(重要)
step-up 仅约束 Registry::dispatch 路径(HTTP 传输与显式 dispatch 均经此路径)。
Registry::call / Plugins::api_run 等内部调用不经过中间件链,敏感 Action
被内部调用时不会触发 step-up(仅保留权限校验)。这是有意的语义划分:内部调用方
是受信代码,如需重认证必须自行编排 StepUpManager。该语义由
internal_call_bypasses_step_up_middleware_by_design 测试锁定,改动前请先评审。
Implementations§
Source§impl<R> StepUpMiddleware<R>where
R: StepUpResourceResolver,
impl<R> StepUpMiddleware<R>where
R: StepUpResourceResolver,
Sourcepub fn new(manager: Arc<StepUpManager>, action: ActionRef, resolver: R) -> Self
pub fn new(manager: Arc<StepUpManager>, action: ActionRef, resolver: R) -> Self
绑定管理器、目标 Action 与服务端资源解析器。
Sourcepub fn with_proof_store<S>(self, proof_store: S) -> Selfwhere
S: StepUpProofStore,
pub fn with_proof_store<S>(self, proof_store: S) -> Selfwhere
S: StepUpProofStore,
覆盖一次性 proof 存储。
多实例部署应传入 RedisStepUpProofStore,保证所有实例共享消费状态。
Trait Implementations§
Source§impl<R> Middleware for StepUpMiddleware<R>where
R: StepUpResourceResolver,
impl<R> Middleware for StepUpMiddleware<R>where
R: StepUpResourceResolver,
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> !RefUnwindSafe for StepUpMiddleware<R>
impl<R> !UnwindSafe for StepUpMiddleware<R>
impl<R> Freeze for StepUpMiddleware<R>where
R: Freeze,
impl<R> Send for StepUpMiddleware<R>where
R: Send,
impl<R> Sync for StepUpMiddleware<R>where
R: Sync,
impl<R> Unpin for StepUpMiddleware<R>where
R: Unpin,
impl<R> UnsafeUnpin for StepUpMiddleware<R>where
R: UnsafeUnpin,
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