pub struct StorageAccessController { /* private fields */ }Expand description
Thread-safe role-based and attribute-based access controller.
Implementations§
Source§impl StorageAccessController
impl StorageAccessController
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a controller with default (deny-by-default, audit-enabled) settings.
Sourcepub fn register_subject(
&self,
subject: SubjectAttributes,
) -> Result<(), AclError>
pub fn register_subject( &self, subject: SubjectAttributes, ) -> Result<(), AclError>
Register (or replace) a subject identity and its attributes.
Sourcepub fn register_role(&self, role: SacRole) -> Result<(), AclError>
pub fn register_role(&self, role: SacRole) -> Result<(), AclError>
Register (or replace) a role definition.
Returns AclError::CyclicRoleInheritance if adding this role would
introduce a cycle in the inheritance graph.
Sourcepub fn add_policy(&self, policy: ResourcePolicy) -> Result<(), AclError>
pub fn add_policy(&self, policy: ResourcePolicy) -> Result<(), AclError>
Append a resource policy.
Validates the resource pattern is non-empty.
Sourcepub fn remove_policy(&self, resource_pattern: &str) -> Result<(), AclError>
pub fn remove_policy(&self, resource_pattern: &str) -> Result<(), AclError>
Remove all policies whose resource_pattern equals resource_pattern.
Returns Err(AclError::InvalidPattern) if no policies matched.
Sourcepub fn check_access(
&self,
subject_id: &str,
resource: &str,
permission: Permission,
current_ts: u64,
) -> Result<AccessDecision, AclError>
pub fn check_access( &self, subject_id: &str, resource: &str, permission: Permission, current_ts: u64, ) -> Result<AccessDecision, AclError>
Evaluate whether subject_id may perform permission on resource.
current_ts is a caller-supplied Unix timestamp (milliseconds) used
only for audit log entries.
Sourcepub fn effective_permissions(
&self,
subject_id: &str,
resource: &str,
) -> Result<Vec<Permission>, AclError>
pub fn effective_permissions( &self, subject_id: &str, resource: &str, ) -> Result<Vec<Permission>, AclError>
Return all permissions the subject is granted (i.e. yields Allowed)
for the given resource across the known permission variants.
The set of probed permissions is:
[Read, Write, Delete, List, Admin, Share] plus any Execute ops that
appear in registered policies for this resource.
Sourcepub fn roles_for_subject(
&self,
subject_id: &str,
) -> Result<Vec<String>, AclError>
pub fn roles_for_subject( &self, subject_id: &str, ) -> Result<Vec<String>, AclError>
Return all role names the subject holds, including inherited roles (BFS).
Sourcepub fn audit_log_entries(
&self,
subject_id: Option<&str>,
resource: Option<&str>,
) -> Vec<SacAuditEntry>
pub fn audit_log_entries( &self, subject_id: Option<&str>, resource: Option<&str>, ) -> Vec<SacAuditEntry>
Query the audit log.
Both filters are optional; omitting them returns the full log. Entries are returned in insertion order (oldest first).
Sourcepub fn audit_log_len(&self) -> usize
pub fn audit_log_len(&self) -> usize
Current number of entries in the audit log.
Sourcepub fn with_audit_log<F, T>(&self, f: F) -> T
pub fn with_audit_log<F, T>(&self, f: F) -> T
Direct read access to the audit log via a closure (avoids cloning).
Auto Trait Implementations§
impl !Freeze for StorageAccessController
impl !RefUnwindSafe for StorageAccessController
impl Send for StorageAccessController
impl Sync for StorageAccessController
impl Unpin for StorageAccessController
impl UnsafeUnpin for StorageAccessController
impl UnwindSafe for StorageAccessController
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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