pub struct AuthorizationOperations<'a> { /* private fields */ }Expand description
Focused authorization operations exposed via AuthFramework::authorization().
Provides role-based access control (RBAC), direct permission grants, and effective-permission queries.
§Example
use auth_framework::permissions::{Permission, Role};
use auth_framework::tokens::AuthToken;
let authz = auth.authorization();
let token = AuthToken::builder("token_123", "user_123", "access_token").build();
// Create a role and assign it to a user
let mut editor = Role::new("editor");
editor.add_permission(Permission::new("articles", "edit"));
authz.create_role(editor).await?;
authz.assign_role("user_123", "editor").await?;
// Check permission via token
let allowed = authz.check(&token, "edit", "articles").await?;Implementations§
Source§impl AuthorizationOperations<'_>
impl AuthorizationOperations<'_>
Sourcepub async fn check(
&self,
token: &AuthToken,
action: &str,
resource: &str,
) -> Result<bool>
pub async fn check( &self, token: &AuthToken, action: &str, resource: &str, ) -> Result<bool>
Check whether a token grants access to an action on a resource.
Sourcepub async fn grant(
&self,
user_id: &str,
action: &str,
resource: &str,
) -> Result<()>
pub async fn grant( &self, user_id: &str, action: &str, resource: &str, ) -> Result<()>
Grant a direct permission to a user.
Sourcepub async fn revoke(
&self,
user_id: &str,
action: &str,
resource: &str,
) -> Result<()>
pub async fn revoke( &self, user_id: &str, action: &str, resource: &str, ) -> Result<()>
Revoke a direct permission from a user.
Sourcepub async fn create_role(&self, role: Role) -> Result<()>
pub async fn create_role(&self, role: Role) -> Result<()>
Create a role.
Sourcepub async fn list_roles(&self) -> Vec<Role>
pub async fn list_roles(&self) -> Vec<Role>
List all defined roles.
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<()>
Add a permission to an existing role.
Sourcepub async fn assign_role(&self, user_id: &str, role_name: &str) -> Result<()>
pub async fn assign_role(&self, user_id: &str, role_name: &str) -> Result<()>
Assign a role to a user.
Sourcepub async fn remove_role(&self, user_id: &str, role_name: &str) -> Result<()>
pub async fn remove_role(&self, user_id: &str, role_name: &str) -> Result<()>
Remove a role from a user.
Sourcepub async fn has_role(&self, user_id: &str, role_name: &str) -> Result<bool>
pub async fn has_role(&self, user_id: &str, role_name: &str) -> Result<bool>
Check whether a user currently has a role.
Sourcepub async fn effective_permissions(&self, user_id: &str) -> Result<Permissions>
pub async fn effective_permissions(&self, user_id: &str) -> Result<Permissions>
List effective permissions for a user.
Sourcepub async fn roles_for_user(&self, user_id: &str) -> Result<Roles>
pub async fn roles_for_user(&self, user_id: &str) -> Result<Roles>
List the currently assigned runtime roles for a user.
Auto Trait Implementations§
impl<'a> Freeze for AuthorizationOperations<'a>
impl<'a> !RefUnwindSafe for AuthorizationOperations<'a>
impl<'a> Send for AuthorizationOperations<'a>
impl<'a> Sync for AuthorizationOperations<'a>
impl<'a> Unpin for AuthorizationOperations<'a>
impl<'a> UnsafeUnpin for AuthorizationOperations<'a>
impl<'a> !UnwindSafe for AuthorizationOperations<'a>
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