pub struct Role { /* private fields */ }Expand description
A set of access permissions for resources.
Roles provide an intermediary for assigning access permissions to users by managing permission sets. Separete sets can be provided for specific resources, all other resources, and requests that do not operate on resources.
Currently, roles are given names and are defined in [Config::auth_roles][crate::daemon::config::Config::auth_roles] and referenced by authorization providers through those names.
Implementations§
Source§impl Role
impl Role
Sourcepub fn admin() -> Self
pub fn admin() -> Self
Creates the special admin role.
This role allows all access to everything.
Sourcepub fn readwrite() -> Self
pub fn readwrite() -> Self
Creates the default read-write role.
This role uses PermissionSet::READWRITE for everything.
Sourcepub fn readonly() -> Self
pub fn readonly() -> Self
Creates the default read-only role.
This role uses PermissionSet::READONLY for everything.
Sourcepub fn testbed() -> Self
pub fn testbed() -> Self
Creates the special testbed role.
This role uses PermissionSet::TESTBED for everything.
Sourcepub fn simple(permissions: PermissionSet) -> Self
pub fn simple(permissions: PermissionSet) -> Self
Creates a role that uses the provided permission set for all access.
Sourcepub fn with_resources(
permissions: PermissionSet,
resources: impl IntoIterator<Item = MyHandle>,
) -> Self
pub fn with_resources( permissions: PermissionSet, resources: impl IntoIterator<Item = MyHandle>, ) -> Self
Creates a role that uses the provided set for the given resources.
The role will allow access with the set to non-resource requests and all resources provided. Access to all other resources will be denied.
Sourcepub fn complex(
none: PermissionSet,
any: PermissionSet,
resources: HashMap<MyHandle, PermissionSet>,
) -> Self
pub fn complex( none: PermissionSet, any: PermissionSet, resources: HashMap<MyHandle, PermissionSet>, ) -> Self
Creates a comples role.
The permission set none will be used for non-resource requests.
The resources hash map contains special permission sets for the
provided resources. The any set will be used for all resources
not mentioned in the hash map.
Sourcepub fn is_allowed(
&self,
permission: Permission,
resource: Option<&MyHandle>,
) -> bool
pub fn is_allowed( &self, permission: Permission, resource: Option<&MyHandle>, ) -> bool
Returns whether access is allowed.
The method whether the role allows access with the provided
permission to the provided resource. If the resource is None,
access for non-resource requests is checked.
Returns true if access is allowed or false if not.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Role
impl<'de> Deserialize<'de> for Role
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>,
impl Eq for Role
impl StructuralPartialEq for Role
Auto Trait Implementations§
impl Freeze for Role
impl RefUnwindSafe for Role
impl Send for Role
impl Sync for Role
impl Unpin for Role
impl UnsafeUnpin for Role
impl UnwindSafe for Role
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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