pub struct SessionManager { /* private fields */ }Expand description
Implementations§
Source§impl SessionManager
impl SessionManager
Sourcepub fn new(storage: Arc<dyn AuthStorage>) -> Self
pub fn new(storage: Arc<dyn AuthStorage>) -> Self
Sourcepub fn set_distributed_store(&mut self, store: Arc<dyn DistributedSessionStore>)
pub fn set_distributed_store(&mut self, store: Arc<dyn DistributedSessionStore>)
Sourcepub async fn create_session(
&self,
user_id: &str,
expires_in: Duration,
ip_address: Option<String>,
user_agent: Option<String>,
) -> Result<String>
pub async fn create_session( &self, user_id: &str, expires_in: Duration, ip_address: Option<String>, user_agent: Option<String>, ) -> Result<String>
Sourcepub async fn get_session(&self, session_id: &str) -> Result<Option<SessionData>>
pub async fn get_session(&self, session_id: &str) -> Result<Option<SessionData>>
Sourcepub async fn delete_session(&self, session_id: &str) -> Result<()>
pub async fn delete_session(&self, session_id: &str) -> Result<()>
Sourcepub async fn update_session_activity(&self, session_id: &str) -> Result<()>
pub async fn update_session_activity(&self, session_id: &str) -> Result<()>
Sourcepub async fn get_user_sessions(
&self,
user_id: &str,
) -> Result<Vec<(String, SessionData)>>
pub async fn get_user_sessions( &self, user_id: &str, ) -> Result<Vec<(String, SessionData)>>
Sourcepub async fn delete_user_sessions(&self, user_id: &str) -> Result<()>
pub async fn delete_user_sessions(&self, user_id: &str) -> Result<()>
Sourcepub async fn cleanup_expired_sessions(&self) -> Result<()>
pub async fn cleanup_expired_sessions(&self) -> Result<()>
Sourcepub async fn extend_session(
&self,
session_id: &str,
additional_time: Duration,
) -> Result<()>
pub async fn extend_session( &self, session_id: &str, additional_time: Duration, ) -> Result<()>
Sourcepub async fn create_session_limited(
&self,
user_id: &str,
expires_in: Duration,
ip_address: Option<String>,
user_agent: Option<String>,
) -> Result<(String, u64)>
pub async fn create_session_limited( &self, user_id: &str, expires_in: Duration, ip_address: Option<String>, user_agent: Option<String>, ) -> Result<(String, u64)>
Create a new session with resource-limit guards.
Enforces a global cap of 100 000 total sessions and a per-user cap of 50 sessions to prevent DoS / resource exhaustion.
Returns (session_id, new_total_count) so the caller can update monitoring.
§Example
ⓘ
let (sid, total) = mgr.create_session_limited(
"user-1", Duration::from_secs(3600), None, None,
).await?;
println!("created session {} (total active: {})", sid, total);Sourcepub async fn count_active_sessions(&self) -> Result<u64>
pub async fn count_active_sessions(&self) -> Result<u64>
Sourcepub async fn coordinate_distributed_sessions(
&self,
) -> Result<SessionCoordinationStats>
pub async fn coordinate_distributed_sessions( &self, ) -> Result<SessionCoordinationStats>
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<'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
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