pub struct AuthorizationManager { /* private fields */ }Expand description
Authorization manager that owns the PermissionChecker and exposes
all role and permission operations for delegation from AuthFramework.
§Example
ⓘ
use auth_framework::auth_modular::AuthorizationManager;
let am = AuthorizationManager::new(checker.clone(), storage.clone());
am.create_default_roles().await;Implementations§
Source§impl AuthorizationManager
impl AuthorizationManager
Sourcepub fn new(
checker: Arc<RwLock<PermissionChecker>>,
storage: Arc<dyn AuthStorage>,
) -> Self
pub fn new( checker: Arc<RwLock<PermissionChecker>>, storage: Arc<dyn AuthStorage>, ) -> Self
Sourcepub async fn create_default_roles(&self)
pub async fn create_default_roles(&self)
Sourcepub async fn load_persisted_roles(&self) -> Result<()>
pub async fn load_persisted_roles(&self) -> Result<()>
Sourcepub async fn reset_runtime_state(&self)
pub async fn reset_runtime_state(&self)
Sourcepub async fn grant_permission(
&self,
user_id: &str,
action: &str,
resource: &str,
) -> Result<()>
pub async fn grant_permission( &self, user_id: &str, action: &str, resource: &str, ) -> Result<()>
Sourcepub async fn revoke_permission(
&self,
user_id: &str,
action: &str,
resource: &str,
) -> Result<()>
pub async fn revoke_permission( &self, user_id: &str, action: &str, resource: &str, ) -> Result<()>
Sourcepub async fn create_role(&self, role: Role) -> Result<()>
pub async fn create_role(&self, role: Role) -> Result<()>
Sourcepub async fn list_roles(&self) -> Vec<Role>
pub async fn list_roles(&self) -> Vec<Role>
Sourcepub async fn add_role_permission(
&self,
role_name: &str,
permission: Permission,
) -> Result<()>
pub async fn add_role_permission( &self, role_name: &str, permission: Permission, ) -> Result<()>
Sourcepub async fn set_role_inheritance(
&self,
child_role: &str,
parent_role: &str,
) -> Result<()>
pub async fn set_role_inheritance( &self, child_role: &str, parent_role: &str, ) -> Result<()>
Sourcepub async fn check_token_permission(
&self,
token: &AuthToken,
action: &str,
resource: &str,
) -> Result<bool>
pub async fn check_token_permission( &self, token: &AuthToken, action: &str, resource: &str, ) -> Result<bool>
Sourcepub async fn check_user_permission(
&self,
user_id: &str,
action: &str,
resource: &str,
) -> bool
pub async fn check_user_permission( &self, user_id: &str, action: &str, resource: &str, ) -> bool
Sourcepub async fn get_metrics(&self) -> (usize, usize, usize)
pub async fn get_metrics(&self) -> (usize, usize, usize)
Sourcepub async fn map_user_attribute(
&self,
user_id: &str,
attribute: &str,
value: &str,
) -> Result<()>
pub async fn map_user_attribute( &self, user_id: &str, attribute: &str, value: &str, ) -> Result<()>
Sourcepub async fn get_user_attribute(
&self,
user_id: &str,
attribute: &str,
) -> Result<Option<String>>
pub async fn get_user_attribute( &self, user_id: &str, attribute: &str, ) -> Result<Option<String>>
Sourcepub async fn check_dynamic_permission(
&self,
user_id: &str,
action: &str,
resource: &str,
context: HashMap<String, String>,
) -> Result<bool>
pub async fn check_dynamic_permission( &self, user_id: &str, action: &str, resource: &str, context: HashMap<String, String>, ) -> Result<bool>
Sourcepub async fn create_resource(&self, resource: &str) -> Result<()>
pub async fn create_resource(&self, resource: &str) -> Result<()>
Sourcepub async fn delegate_permission(
&self,
delegator_id: &str,
delegatee_id: &str,
action: &str,
resource: &str,
duration: Duration,
) -> Result<()>
pub async fn delegate_permission( &self, delegator_id: &str, delegatee_id: &str, action: &str, resource: &str, duration: Duration, ) -> Result<()>
Sourcepub async fn get_permission_metrics(
&self,
active_sessions: u64,
permission_checks_last_hour: u64,
) -> Result<HashMap<String, u64>>
pub async fn get_permission_metrics( &self, active_sessions: u64, permission_checks_last_hour: u64, ) -> Result<HashMap<String, u64>>
Assemble aggregated permission metrics.
active_sessions and permission_checks_last_hour are provided by the
caller so that the manager stays independent from the session and audit
subsystems.
§Example
ⓘ
let metrics = am.get_permission_metrics(42, 1000).await?;
println!("total_roles: {}", metrics["total_roles"]);Auto Trait Implementations§
impl Freeze for AuthorizationManager
impl !RefUnwindSafe for AuthorizationManager
impl Send for AuthorizationManager
impl Sync for AuthorizationManager
impl Unpin for AuthorizationManager
impl UnsafeUnpin for AuthorizationManager
impl !UnwindSafe for AuthorizationManager
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