Skip to main content

backbone_authorization/
traits.rs

1//! Authorization traits
2//!
3//! Defines the core authorization trait that all authorization services must implement.
4
5use crate::types::*;
6use async_trait::async_trait;
7
8/// Authorization service trait
9#[async_trait]
10pub trait AuthorizationServiceTrait: Send + Sync {
11    /// Check if a user is authorized to perform an action on a resource
12    async fn check_authorization(
13        &self,
14        request: AuthorizationRequest,
15    ) -> Result<AuthorizationResponse, AuthorizationError>;
16
17    /// Grant a permission to a role
18    async fn grant_permission_to_role(
19        &self,
20        role: &str,
21        permission: Permission,
22    ) -> Result<(), AuthorizationError>;
23
24    /// Revoke a permission from a role
25    async fn revoke_permission_from_role(
26        &self,
27        role: &str,
28        permission: &Permission,
29    ) -> Result<(), AuthorizationError>;
30
31    /// Assign a role to a user
32    async fn assign_role_to_user(
33        &self,
34        user_id: &str,
35        role: &str,
36    ) -> Result<(), AuthorizationError>;
37
38    /// Remove a role from a user
39    async fn remove_role_from_user(
40        &self,
41        user_id: &str,
42        role: &str,
43    ) -> Result<(), AuthorizationError>;
44
45    /// Get all permissions for a user
46    async fn get_user_permissions(
47        &self,
48        user_id: &str,
49    ) -> Result<Vec<Permission>, AuthorizationError>;
50
51    /// Check if user has a specific permission
52    async fn user_has_permission(
53        &self,
54        user_id: &str,
55        permission: &Permission,
56    ) -> Result<bool, AuthorizationError>;
57}