Struct RoleSystem

Source
pub struct RoleSystem<S = MemoryStorage>
where S: Storage,
{ /* private fields */ }
Expand description

The main role-based access control system.

Implementations§

Source§

impl RoleSystem<MemoryStorage>

Source

pub fn new() -> Self

Create a new role system with default configuration and memory storage.

Source

pub fn with_config(config: RoleSystemConfig) -> Self

Create a new role system with custom configuration and memory storage.

Source§

impl<S> RoleSystem<S>
where S: Storage,

Source

pub fn with_storage(storage: S, config: RoleSystemConfig) -> Self

Create a new role system with custom storage.

Source

pub fn register_role(&mut self, role: Role) -> Result<()>

Register a new role in the system.

Source

pub fn get_role(&self, name: &str) -> Result<Option<Role>>

Get a role by name.

Source

pub fn update_role(&mut self, role: Role) -> Result<()>

Update an existing role.

Source

pub fn add_role_inheritance(&mut self, child: &str, parent: &str) -> Result<()>

Add role inheritance (child inherits from parent).

Source

pub fn remove_role_inheritance( &mut self, child: &str, parent: &str, ) -> Result<()>

Remove role inheritance.

Source

pub fn assign_role(&mut self, subject: &Subject, role_name: &str) -> Result<()>

Assign a role to a subject.

Source

pub fn remove_role(&mut self, subject: &Subject, role_name: &str) -> Result<()>

Remove a role from a subject.

Source

pub fn elevate_role( &mut self, subject: &Subject, role_name: &str, duration: Option<Duration>, ) -> Result<()>

Temporarily elevate a subject’s role.

Source

pub fn check_permission( &self, subject: &Subject, action: &str, resource: &Resource, ) -> Result<bool>

Check if a subject has a specific permission on a resource.

Source

pub fn check_permission_with_context( &self, subject: &Subject, action: &str, resource: &Resource, context: &HashMap<String, String>, ) -> Result<bool>

Check permission with additional context.

Source

pub fn get_subject_roles(&self, subject: &Subject) -> Result<HashSet<String>>

Get all roles assigned to a subject (including inherited roles).

Trait Implementations§

Source§

impl<S> Default for RoleSystem<S>
where S: Storage + Default,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for RoleSystem<S>
where S: Freeze,

§

impl<S = MemoryStorage> !RefUnwindSafe for RoleSystem<S>

§

impl<S> Send for RoleSystem<S>

§

impl<S> Sync for RoleSystem<S>

§

impl<S> Unpin for RoleSystem<S>
where S: Unpin,

§

impl<S> UnwindSafe for RoleSystem<S>
where S: 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.