zino_auth

Struct UserSession

Source
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>

Source

pub fn new(user_id: U, session_id: impl Into<Option<SessionId>>) -> Self

Creates a new instance with empty roles.

Source

pub fn set_session_id(&mut self, session_id: SessionId)

Sets the session ID.

Source

pub fn set_access_key_id(&mut self, access_key_id: AccessKeyId)

Sets the access key ID.

Source

pub fn set_roles(&mut self, roles: impl Into<Vec<R>>)

Sets the user roles.

Source

pub fn set_tenant_id(&mut self, tenant_id: T)

Sets the tenant ID.

Source

pub fn user_id(&self) -> &U

Returns the user ID.

Source

pub fn tenant_id(&self) -> Option<&T>

Returns the tenant ID.

Source

pub fn session_id(&self) -> Option<&SessionId>

Returns the session ID.

Source

pub fn access_key_id(&self) -> Option<&AccessKeyId>

Returns the access key ID.

Source

pub fn roles(&self) -> &[R]

Returns the roles.

Source§

impl<U, R, T> UserSession<U, R, T>
where U: FromStr, R: FromStr, T: FromStr, <U as FromStr>::Err: Error + Send + 'static,

Source

pub fn try_from_jwt_claims(claims: JwtClaims) -> Result<Self, Error>

Available on crate feature jwt only.

Attempts to construct an instance from a JwtClaims.

Source§

impl<U, T> UserSession<U, String, T>

Source

pub fn is_superuser(&self) -> bool

Returns true if the user has a role of superuser.

Source

pub fn is_user(&self) -> bool

Returns true if the user has a role of user.

Source

pub fn is_guest(&self) -> bool

Returns true if the user has a role of guest.

Source

pub fn is_agent(&self) -> bool

Returns true if the user has a role of agent.

Source

pub fn is_admin(&self) -> bool

Returns true if the user has a role of admin.

Source

pub fn is_worker(&self) -> bool

Returns true if the user has a role of worker.

Source

pub fn is_auditor(&self) -> bool

Returns true if the user has a role of auditor.

Source

pub fn has_user_role(&self) -> bool

Returns true if the user has one of the roles: superuser, user, admin, worker and auditor.

Source

pub fn has_admin_role(&self) -> bool

Returns true if the user has a role of superuser or admin.

Source

pub fn has_worker_role(&self) -> bool

Returns true if the user has a role of superuser or worker.

Source

pub fn has_auditor_role(&self) -> bool

Returns true if the user has a role of superuser or auditor.

Source

pub fn has_role(&self, role: &str) -> bool

Returns true if the user has the specific role.

Source

pub fn has_any_roles(&self, roles: &[&str]) -> bool

Returns true if the user has any of the specific roles.

Source

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>

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<U: Debug, R: Debug, T: Debug> Debug for UserSession<U, R, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, U, R, T> Deserialize<'de> for UserSession<U, R, T>
where U: Deserialize<'de>, R: Deserialize<'de>, T: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<U, R, T> Serialize for UserSession<U, R, T>
where U: Serialize, R: Serialize, T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<U, R, T> Freeze for UserSession<U, R, T>
where U: Freeze, T: Freeze,

§

impl<U, R, T> RefUnwindSafe for UserSession<U, R, T>

§

impl<U, R, T> Send for UserSession<U, R, T>
where U: Send, T: Send, R: Send,

§

impl<U, R, T> Sync for UserSession<U, R, T>
where U: Sync, T: Sync, R: Sync,

§

impl<U, R, T> Unpin for UserSession<U, R, T>
where U: Unpin, T: Unpin, R: Unpin,

§

impl<U, R, T> UnwindSafe for UserSession<U, R, T>
where U: UnwindSafe, T: UnwindSafe, R: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T