pub struct SessionManager<S: SessionStorage, A: AuditStorage> { /* private fields */ }Expand description
Main session manager
Implementations§
Source§impl<S: SessionStorage, A: AuditStorage> SessionManager<S, A>
impl<S: SessionStorage, A: AuditStorage> SessionManager<S, A>
Sourcepub fn new(
storage: S,
config: SessionConfig,
audit_logger: AuditLogger<A>,
) -> Self
pub fn new( storage: S, config: SessionConfig, audit_logger: AuditLogger<A>, ) -> Self
Create a new session manager.
The storage backend persists session data, config specifies lifetimes
and security policies, and audit_logger records session lifecycle events.
Sourcepub async fn create_session(
&self,
user_id: &str,
device_info: DeviceInfo,
metadata: RequestMetadata,
) -> Result<Session>
pub async fn create_session( &self, user_id: &str, device_info: DeviceInfo, metadata: RequestMetadata, ) -> Result<Session>
Create a new session
Sourcepub async fn validate_session(
&self,
session_id: &str,
metadata: RequestMetadata,
) -> Result<Option<Session>>
pub async fn validate_session( &self, session_id: &str, metadata: RequestMetadata, ) -> Result<Option<Session>>
Validate and refresh a session
Sourcepub async fn revoke_session(&self, session_id: &str) -> Result<()>
pub async fn revoke_session(&self, session_id: &str) -> Result<()>
Revoke a session
Sourcepub async fn revoke_all_user_sessions(&self, user_id: &str) -> Result<u32>
pub async fn revoke_all_user_sessions(&self, user_id: &str) -> Result<u32>
Revoke all sessions for a user
Sourcepub async fn get_user_sessions(
&self,
user_id: &str,
include_inactive: bool,
) -> Result<Vec<Session>>
pub async fn get_user_sessions( &self, user_id: &str, include_inactive: bool, ) -> Result<Vec<Session>>
List sessions for a user.
When include_inactive is false, only SessionState::Active
sessions are returned.
Prefer list_user_sessions with a
SessionFilter for
self-documenting call sites.
Sourcepub async fn list_user_sessions(
&self,
user_id: &str,
filter: SessionFilter,
) -> Result<Vec<Session>>
pub async fn list_user_sessions( &self, user_id: &str, filter: SessionFilter, ) -> Result<Vec<Session>>
List sessions for a user with a typed SessionFilter.
use auth_framework::auth_operations::SessionFilter;
let active = mgr.list_user_sessions(user_id, SessionFilter::ActiveOnly).await?;Sourcepub async fn cleanup_expired_sessions(&self) -> Result<u32>
pub async fn cleanup_expired_sessions(&self) -> Result<u32>
Remove all expired sessions from storage and return how many were cleaned up.
Sourcepub fn generate_device_fingerprint(&self, metadata: &RequestMetadata) -> String
pub fn generate_device_fingerprint(&self, metadata: &RequestMetadata) -> String
Compute a device fingerprint from the request metadata (IP, User-Agent, etc.).
Sourcepub fn validate_device_fingerprint(
&self,
session: &Session,
metadata: &RequestMetadata,
) -> bool
pub fn validate_device_fingerprint( &self, session: &Session, metadata: &RequestMetadata, ) -> bool
Check whether metadata produces a fingerprint matching the session’s stored value.
Auto Trait Implementations§
impl<S, A> !Freeze for SessionManager<S, A>
impl<S, A> !RefUnwindSafe for SessionManager<S, A>
impl<S, A> Send for SessionManager<S, A>
impl<S, A> Sync for SessionManager<S, A>
impl<S, A> Unpin for SessionManager<S, A>
impl<S, A> UnsafeUnpin for SessionManager<S, A>where
S: UnsafeUnpin,
A: UnsafeUnpin,
impl<S, A> !UnwindSafe for SessionManager<S, A>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
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>
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>
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