pub struct AuthzEngine { /* private fields */ }Expand description
The central authorization engine.
Combines role-based access control, rate limiting, audit logging, and field redaction into a single, coherent API.
use stateset_authz::{AuthzEngineBuilder, Role, Action, Resource};
let mut engine = AuthzEngineBuilder::new()
.add_role(Role::admin())
.add_role(Role::viewer())
.assign_role("alice", "admin")
.assign_role("bob", "viewer")
.build();
let decision = engine.authorize("alice", &Resource::new("orders"), &Action::Delete);
assert!(decision.is_allowed());
let decision = engine.authorize("bob", &Resource::new("orders"), &Action::Delete);
assert!(decision.is_denied());Implementations§
Source§impl AuthzEngine
impl AuthzEngine
Checks whether actor_id is allowed to perform action on resource.
This method:
- Looks up the actor’s role
- Checks the role’s permission for the resource type
- Checks rate limits
- Checks approval-required rules
- Records an audit entry
use stateset_authz::{AuthzEngineBuilder, Role, Action, Resource};
let mut engine = AuthzEngineBuilder::new()
.add_role(Role::viewer())
.assign_role("bob", "viewer")
.build();
let d = engine.authorize("bob", &Resource::new("orders"), &Action::Read);
assert!(d.is_allowed());Sourcepub fn add_role(&mut self, role: Role)
pub fn add_role(&mut self, role: Role)
Adds a new role to the engine.
If a role with the same name already exists, it is replaced.
Sourcepub fn assign_role(
&mut self,
actor_id: &str,
role_name: &str,
) -> AuthzResult<()>
pub fn assign_role( &mut self, actor_id: &str, role_name: &str, ) -> AuthzResult<()>
Assigns a role to an actor.
Returns an error if the role does not exist.
Sourcepub fn remove_role(&mut self, actor_id: &str)
pub fn remove_role(&mut self, actor_id: &str)
Removes a role assignment for an actor.
Sourcepub fn actor_role(&self, actor_id: &str) -> Option<&str>
pub fn actor_role(&self, actor_id: &str) -> Option<&str>
Returns the role assigned to an actor, if any.
Sourcepub const fn rate_limiter(&self) -> &RateLimiter
pub const fn rate_limiter(&self) -> &RateLimiter
Returns a reference to the rate limiter.
Sourcepub const fn rate_limiter_mut(&mut self) -> &mut RateLimiter
pub const fn rate_limiter_mut(&mut self) -> &mut RateLimiter
Returns a mutable reference to the rate limiter.
Sourcepub fn query_audit(&self, filter: &AuditFilter) -> Vec<&AuditRecord>
pub fn query_audit(&self, filter: &AuditFilter) -> Vec<&AuditRecord>
Queries the audit log with the given filter.
Sourcepub const fn redaction_config(&self) -> &RedactionConfig
pub const fn redaction_config(&self) -> &RedactionConfig
Returns a reference to the redaction config.
Sourcepub fn redact(&self, value: &mut Value)
pub fn redact(&self, value: &mut Value)
Redacts sensitive fields in a JSON value using the engine’s redaction config.
Sourcepub fn add_rate_limit_rule(&mut self, rule: RateLimitRule)
pub fn add_rate_limit_rule(&mut self, rule: RateLimitRule)
Adds a rate limit rule.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AuthzEngine
impl RefUnwindSafe for AuthzEngine
impl Send for AuthzEngine
impl Sync for AuthzEngine
impl Unpin for AuthzEngine
impl UnsafeUnpin for AuthzEngine
impl UnwindSafe for AuthzEngine
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
Mutably borrows from an owned value. Read more