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<S>(
manager: Arc<StepUpManager>,
action: ActionRef,
resolver: R,
proof_store: S,
) -> Selfwhere
S: StepUpProofStore,
pub fn new<S>(
manager: Arc<StepUpManager>,
action: ActionRef,
resolver: R,
proof_store: S,
) -> Selfwhere
S: StepUpProofStore,
绑定管理器、目标 Action、服务端资源解析器与一次性 proof 存储。
proof 的一次性语义完全由该存储承担;StepUpManager::verify_proof 是无状态
的,不查任何共享状态。多实例部署必须传入 RedisStepUpProofStore。
Sourcepub fn in_process(
manager: Arc<StepUpManager>,
action: ActionRef,
resolver: R,
) -> Self
pub fn in_process( manager: Arc<StepUpManager>, action: ActionRef, resolver: R, ) -> Self
显式 opt-in 的进程内 proof 存储,仅适用于单实例部署与测试。
多实例部署使用本构造函数会把 proof 的一次性语义静默降级为「每实例一次」: 实例 A 消费过的 proof 可在实例 B 重放。命名与日志都要求调用方显式承担该决定。
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> Forget for StepUpMiddleware<R>
impl<R> Freeze for StepUpMiddleware<R>where
R: Freeze,
impl<R> Move for StepUpMiddleware<R>
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