pub struct UserSession<U, R = String, T = U> { /* private fields */ }
Expand description
Role-based user sessions.
Implementations§
Source§impl<U, R, T> UserSession<U, R, T>
impl<U, R, T> UserSession<U, R, T>
Sourcepub fn new(user_id: U, session_id: impl Into<Option<SessionId>>) -> Self
pub fn new(user_id: U, session_id: impl Into<Option<SessionId>>) -> Self
Creates a new instance with empty roles.
Sourcepub fn set_session_id(&mut self, session_id: SessionId)
pub fn set_session_id(&mut self, session_id: SessionId)
Sets the session ID.
Sourcepub fn set_access_key_id(&mut self, access_key_id: AccessKeyId)
pub fn set_access_key_id(&mut self, access_key_id: AccessKeyId)
Sets the access key ID.
Sourcepub fn set_tenant_id(&mut self, tenant_id: T)
pub fn set_tenant_id(&mut self, tenant_id: T)
Sets the tenant ID.
Sourcepub fn session_id(&self) -> Option<&SessionId>
pub fn session_id(&self) -> Option<&SessionId>
Returns the session ID.
Sourcepub fn access_key_id(&self) -> Option<&AccessKeyId>
pub fn access_key_id(&self) -> Option<&AccessKeyId>
Returns the access key ID.
Source§impl<U, R, T> UserSession<U, R, T>
impl<U, R, T> UserSession<U, R, T>
Sourcepub fn try_from_jwt_claims(claims: JwtClaims) -> Result<Self, Error>
Available on crate feature jwt
only.
pub fn try_from_jwt_claims(claims: JwtClaims) -> Result<Self, Error>
jwt
only.Attempts to construct an instance from a JwtClaims
.
Source§impl<U, T> UserSession<U, String, T>
impl<U, T> UserSession<U, String, T>
Sourcepub fn is_superuser(&self) -> bool
pub fn is_superuser(&self) -> bool
Returns true
if the user has a role of superuser
.
Sourcepub fn is_auditor(&self) -> bool
pub fn is_auditor(&self) -> bool
Returns true
if the user has a role of auditor
.
Sourcepub fn has_user_role(&self) -> bool
pub fn has_user_role(&self) -> bool
Returns true
if the user has one of the roles: superuser
, user
,
admin
, worker
and auditor
.
Sourcepub fn has_admin_role(&self) -> bool
pub fn has_admin_role(&self) -> bool
Returns true
if the user has a role of superuser
or admin
.
Sourcepub fn has_worker_role(&self) -> bool
pub fn has_worker_role(&self) -> bool
Returns true
if the user has a role of superuser
or worker
.
Sourcepub fn has_auditor_role(&self) -> bool
pub fn has_auditor_role(&self) -> bool
Returns true
if the user has a role of superuser
or auditor
.
Sourcepub fn has_any_roles(&self, roles: &[&str]) -> bool
pub fn has_any_roles(&self, roles: &[&str]) -> bool
Returns true
if the user has any of the specific roles
.
Sourcepub fn has_all_roles(&self, roles: &[&str]) -> bool
pub fn has_all_roles(&self, roles: &[&str]) -> bool
Returns true
if the user has all of the specific roles
.
Trait Implementations§
Source§impl<U: Clone, R: Clone, T: Clone> Clone for UserSession<U, R, T>
impl<U: Clone, R: Clone, T: Clone> Clone for UserSession<U, R, T>
Source§fn clone(&self) -> UserSession<U, R, T>
fn clone(&self) -> UserSession<U, R, T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<'de, U, R, T> Deserialize<'de> for UserSession<U, R, T>
impl<'de, U, R, T> Deserialize<'de> for UserSession<U, R, T>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl<U, R, T> Freeze for UserSession<U, R, T>
impl<U, R, T> RefUnwindSafe for UserSession<U, R, T>
impl<U, R, T> Send for UserSession<U, R, T>
impl<U, R, T> Sync for UserSession<U, R, T>
impl<U, R, T> Unpin for UserSession<U, R, T>
impl<U, R, T> UnwindSafe for UserSession<U, R, T>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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