pub struct SessionManager { /* private fields */ }Expand description
Manages session state with LRU eviction and hijack detection.
Thread-safe implementation using DashMap for lock-free concurrent access.
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(config: SessionConfig) -> Self
pub fn new(config: SessionConfig) -> Self
Create a new session manager with the given configuration.
Sourcepub fn config(&self) -> &SessionConfig
pub fn config(&self) -> &SessionConfig
Get the configuration.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if session tracking is enabled.
Sourcepub fn validate_request(
&self,
token_hash: &str,
ip: IpAddr,
ja4: Option<&str>,
) -> SessionDecision
pub fn validate_request( &self, token_hash: &str, ip: IpAddr, ja4: Option<&str>, ) -> SessionDecision
Validate an incoming request’s session.
This is the primary entry point - call on every request with a session token.
§Arguments
token_hash- Hash of the session token (not the raw token)ip- Client IP addressja4- Optional JA4 TLS fingerprint
§Returns
A SessionDecision indicating the validation result.
Sourcepub fn create_session(
&self,
token_hash: &str,
ip: IpAddr,
ja4: Option<&str>,
) -> SessionState
pub fn create_session( &self, token_hash: &str, ip: IpAddr, ja4: Option<&str>, ) -> SessionState
Sourcepub fn get_session(&self, token_hash: &str) -> Option<SessionState>
pub fn get_session(&self, token_hash: &str) -> Option<SessionState>
Get session by token hash.
Sourcepub fn get_session_by_id(&self, session_id: &str) -> Option<SessionState>
pub fn get_session_by_id(&self, session_id: &str) -> Option<SessionState>
Get session by session ID.
Sourcepub fn touch_session(&self, token_hash: &str)
pub fn touch_session(&self, token_hash: &str)
Touch session to update activity timestamp.
Sourcepub fn bind_to_actor(&self, token_hash: &str, actor_id: &str) -> bool
pub fn bind_to_actor(&self, token_hash: &str, actor_id: &str) -> bool
Sourcepub fn get_actor_sessions(&self, actor_id: &str) -> Vec<SessionState>
pub fn get_actor_sessions(&self, actor_id: &str) -> Vec<SessionState>
Sourcepub fn list_sessions_by_actor(
&self,
actor_id: &str,
limit: usize,
offset: usize,
) -> Vec<SessionState>
pub fn list_sessions_by_actor( &self, actor_id: &str, limit: usize, offset: usize, ) -> Vec<SessionState>
List sessions for an actor with pagination.
Results are sorted by last_activity (most recent first).
Sourcepub fn invalidate_session(&self, token_hash: &str) -> bool
pub fn invalidate_session(&self, token_hash: &str) -> bool
Sourcepub fn mark_suspicious(&self, token_hash: &str, alert: HijackAlert) -> bool
pub fn mark_suspicious(&self, token_hash: &str, alert: HijackAlert) -> bool
Sourcepub fn list_sessions(&self, limit: usize, offset: usize) -> Vec<SessionState>
pub fn list_sessions(&self, limit: usize, offset: usize) -> Vec<SessionState>
Sourcepub fn list_suspicious_sessions(&self) -> Vec<SessionState>
pub fn list_suspicious_sessions(&self) -> Vec<SessionState>
Sourcepub fn list_suspicious_sessions_paginated(
&self,
limit: usize,
offset: usize,
) -> Vec<SessionState>
pub fn list_suspicious_sessions_paginated( &self, limit: usize, offset: usize, ) -> Vec<SessionState>
List suspicious sessions with pagination.
Results are sorted by last_activity (most recent first).
Sourcepub fn start_background_tasks(self: Arc<Self>)
pub fn start_background_tasks(self: Arc<Self>)
Start background cleanup tasks.
Spawns a background task that periodically:
- Removes expired sessions (TTL and idle timeout)
- Evicts oldest sessions if over capacity
Sourcepub fn stats(&self) -> &SessionStats
pub fn stats(&self) -> &SessionStats
Get statistics.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SessionManager
impl !RefUnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnsafeUnpin for SessionManager
impl UnwindSafe for SessionManager
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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