Skip to main content

SessionGuard

Struct SessionGuard 

Source
pub struct SessionGuard<S: SessionStore> { /* private fields */ }

Implementations§

Source§

impl<S: SessionStore> SessionGuard<S>

Source

pub fn new(store: S, config: SessionConfig) -> Self

Source

pub fn config(&self) -> &SessionConfig

Source

pub fn bind( &self, ctx: &RequestContext<'_>, now: u64, ) -> Result<SessionVerdict, SessionError>

登录:建会话 + 绑指纹 + 记位置,并返回异地判定。

登录本身总是成功(除非调用方误用或后端故障)—— 异地只影响 verdict, 由调用方决定是否走二次验证,不应阻断登录。

Source

pub fn verify(&self, ctx: &RequestContext<'_>, now: u64) -> SessionVerdict

每请求校验。

返回 SessionVerdict 而非 Result:认证路径上「拒绝」是正常结果而非错误, 强制调用方在类型层面处理每一种拒绝。

Source

pub fn revoke(&self, token: &str) -> Result<(), StoreError>

吊销单个会话(登出)。

Source

pub fn revoke_all(&self, subject: &str) -> Result<usize, StoreError>

吊销某 subject 的全部会话(改密码 / 踢下线),返回受影响条数。

Source

pub fn rotate( &self, old: &str, new: &str, ctx: &RequestContext<'_>, now: u64, ) -> Result<(), SessionError>

续期换 token:旧 token 吊销,新 token 由调用方提供。

旧会话必须存在、未吊销、未过期,且指纹与本次 ctx 相符 —— 否则等于允许攻击者拿别人的 token 换一个自己的新 token,是提权漏洞。

新记录的身份字段(subject / location / coords / signature)一律 以服务端记录为准,不接受 ctx 覆盖。

Auto Trait Implementations§

§

impl<S> Freeze for SessionGuard<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for SessionGuard<S>
where S: RefUnwindSafe,

§

impl<S> Send for SessionGuard<S>

§

impl<S> Sync for SessionGuard<S>

§

impl<S> Unpin for SessionGuard<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for SessionGuard<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for SessionGuard<S>
where S: UnwindSafe,

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, 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, 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.