Skip to main content

StepUpMiddleware

Struct StepUpMiddleware 

Source
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>

Source

pub fn new<S>( manager: Arc<StepUpManager>, action: ActionRef, resolver: R, proof_store: S, ) -> Self

绑定管理器、目标 Action、服务端资源解析器与一次性 proof 存储。

proof 的一次性语义完全由该存储承担;StepUpManager::verify_proof 是无状态 的,不查任何共享状态。多实例部署必须传入 RedisStepUpProofStore。

Source

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>

Source§

fn role(&self) -> MiddlewareRole

返回构建期可验证的安全依赖角色。
Source§

fn target_action(&self) -> Option<&ActionRef>

返回只应执行此中间件的确定 Action。 Read more
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,

处理一次派发。 Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more