1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//! # Role System
//!
//! This crate provides a complete framework for defining roles, permissions, and access policies
//! with support for dynamic role management, hierarchical roles, and fine-grained permission checking.
//!
//! ## Features
//!
//! - Hierarchical role definitions and inheritance
//! - Fine-grained permission control
//! - Dynamic role management at runtime
//! - Role assignment to users, groups, or resources
//! - Conditional permissions based on context
//! - Permission caching for performance
//! - Custom permission validators
//! - Serializable role definitions
//! - Audit logging of permission checks
//! - Integration with authentication systems
//! - Thread-safe implementation
//! - Support for temporary role elevation
//! - Role constraints (time-based, location-based, etc.)
//!
//! ## Quick Start
//!
//! ```rust
//! use role_system::{RoleSystem, Role, Permission, Subject, Resource};
//!
//! // Initialize the role system
//! let mut role_system = RoleSystem::new();
//!
//! // Define permissions
//! let read_docs = Permission::new("read", "documents");
//! let write_docs = Permission::new("write", "documents");
//!
//! // Define roles with permissions
//! let reader = Role::new("reader").add_permission(read_docs.clone());
//! let writer = Role::new("writer")
//! .add_permission(read_docs.clone())
//! .add_permission(write_docs.clone());
//!
//! // Register roles
//! role_system.register_role(reader)?;
//! role_system.register_role(writer)?;
//!
//! // Assign roles to subjects
//! let user = Subject::new("user1");
//! role_system.assign_role(&user, "reader")?;
//!
//! // Check permissions
//! let document = Resource::new("doc1", "documents");
//! let can_read = role_system.check_permission(&user, "read", &document)?;
//!
//! assert!(can_read);
//! # Ok::<(), role_system::Error>(())
//! ```
//!
//! ## Audit Logging
//!
//! When the `audit` feature is enabled, Role System logs important security events
//! using the standard Rust logging framework. To enable logging:
//!
//! ```rust
//! use role_system::init_audit_logger;
//!
//! // Initialize logging (must be called early in program execution)
//! init_audit_logger();
//!
//! // Configure log level through RUST_LOG environment variable:
//! // RUST_LOG=info,role_system=debug
//! ```
//!
//! The following events are logged:
//! - Role registration and updates
//! - Role hierarchy changes
//! - Role assignments and removals
//! - Permission checks (at debug level)
//! - Security-relevant errors
//!
// Testing and fuzzing
// Re-export main types for convenience
pub use crate::;
pub use crateAsyncRoleSystem;