pub struct SecurityService { /* private fields */ }Expand description
Main security service combining all components
Implementations§
Source§impl SecurityService
impl SecurityService
Sourcepub async fn new(config: SecurityConfig) -> Result<Self>
pub async fn new(config: SecurityConfig) -> Result<Self>
Create a new security service with the given configuration
Sourcepub async fn authenticate_local(
&self,
identifier: &str,
password: &str,
) -> Result<AuthResult>
pub async fn authenticate_local( &self, identifier: &str, password: &str, ) -> Result<AuthResult>
Authenticate a user with username/email and password
Sourcepub async fn start_oauth2_flow(
&self,
provider: OAuth2Provider,
) -> Result<String>
pub async fn start_oauth2_flow( &self, provider: OAuth2Provider, ) -> Result<String>
Start OAuth2 authentication flow
Sourcepub async fn complete_oauth2_flow(
&self,
provider: OAuth2Provider,
code: &str,
state: &str,
) -> Result<AuthResult>
pub async fn complete_oauth2_flow( &self, provider: OAuth2Provider, code: &str, state: &str, ) -> Result<AuthResult>
Complete OAuth2 authentication flow
Sourcepub fn setup_mfa(&self, user_id: &str) -> Result<(String, String)>
pub fn setup_mfa(&self, user_id: &str) -> Result<(String, String)>
Generate MFA secret and QR code for user
Sourcepub fn validate_token(&self, token: &str) -> Result<JwtClaims>
pub fn validate_token(&self, token: &str) -> Result<JwtClaims>
Validate JWT token
Sourcepub fn generate_tokens(
&self,
user_id: &str,
roles: Vec<String>,
) -> Result<TokenPair>
pub fn generate_tokens( &self, user_id: &str, roles: Vec<String>, ) -> Result<TokenPair>
Generate new token pair
Sourcepub fn refresh_token(&self, refresh_token: &str) -> Result<TokenPair>
pub fn refresh_token(&self, refresh_token: &str) -> Result<TokenPair>
Refresh access token
Check authorization for principal on resource using capabilities
Sourcepub fn hash_password(&self, password: &str) -> Result<PasswordHash>
pub fn hash_password(&self, password: &str) -> Result<PasswordHash>
Hash password
Sourcepub fn verify_password(
&self,
password: &str,
hash: &PasswordHash,
) -> Result<bool>
pub fn verify_password( &self, password: &str, hash: &PasswordHash, ) -> Result<bool>
Verify password against hash
Sourcepub fn grant_capabilities(
&self,
principal_caps: &CapabilitySet,
new_caps: Vec<Capability>,
) -> CapabilitySet
pub fn grant_capabilities( &self, principal_caps: &CapabilitySet, new_caps: Vec<Capability>, ) -> CapabilitySet
Grant capabilities to a principal
Sourcepub fn revoke_capabilities(
&self,
principal_caps: &CapabilitySet,
caps_to_revoke: Vec<Capability>,
) -> CapabilitySet
pub fn revoke_capabilities( &self, principal_caps: &CapabilitySet, caps_to_revoke: Vec<Capability>, ) -> CapabilitySet
Revoke capabilities from a principal
Sourcepub fn attenuate_capabilities(
&self,
cap_set: &CapabilitySet,
restrictions: Vec<Capability>,
) -> CapabilitySet
pub fn attenuate_capabilities( &self, cap_set: &CapabilitySet, restrictions: Vec<Capability>, ) -> CapabilitySet
Create an attenuated capability set for safer operations
Sourcepub fn create_principal_with_capabilities(
&self,
user_id: String,
capabilities: CapabilitySet,
roles: Vec<String>,
permissions: Vec<String>,
attributes: HashMap<String, Value>,
) -> Principal
pub fn create_principal_with_capabilities( &self, user_id: String, capabilities: CapabilitySet, roles: Vec<String>, permissions: Vec<String>, attributes: HashMap<String, Value>, ) -> Principal
Create a principal with specific capabilities
Sourcepub fn create_resource(
&self,
resource_type: ResourceType,
action: Action,
resource_id: Option<String>,
attributes: HashMap<String, Value>,
) -> Resource
pub fn create_resource( &self, resource_type: ResourceType, action: Action, resource_id: Option<String>, attributes: HashMap<String, Value>, ) -> Resource
Create a resource for authorization checks
Sourcepub async fn log_audit_event(&self, event: AuditEvent) -> Result<()>
pub async fn log_audit_event(&self, event: AuditEvent) -> Result<()>
Log an audit event
Sourcepub async fn log_authentication(
&self,
user_id: Option<&str>,
ip_address: Option<&str>,
user_agent: Option<&str>,
result: AuditResult,
message: &str,
) -> Result<()>
pub async fn log_authentication( &self, user_id: Option<&str>, ip_address: Option<&str>, user_agent: Option<&str>, result: AuditResult, message: &str, ) -> Result<()>
Log authentication event
Log authorization event
Sourcepub async fn log_data_access(
&self,
user_id: &str,
resource: &str,
action: &str,
result: AuditResult,
metadata: HashMap<String, Value>,
) -> Result<()>
pub async fn log_data_access( &self, user_id: &str, resource: &str, action: &str, result: AuditResult, metadata: HashMap<String, Value>, ) -> Result<()>
Log data access event
Sourcepub async fn get_audit_events(
&self,
start_time: Option<DateTime<Utc>>,
end_time: Option<DateTime<Utc>>,
event_type: Option<&AuditEventType>,
user_id: Option<&str>,
limit: Option<usize>,
) -> Result<Vec<AuditEvent>>
pub async fn get_audit_events( &self, start_time: Option<DateTime<Utc>>, end_time: Option<DateTime<Utc>>, event_type: Option<&AuditEventType>, user_id: Option<&str>, limit: Option<usize>, ) -> Result<Vec<AuditEvent>>
Get audit events
Sourcepub async fn get_audit_statistics(&self) -> Result<AuditStatistics>
pub async fn get_audit_statistics(&self) -> Result<AuditStatistics>
Get audit statistics
Sourcepub async fn cleanup_audit_events(&self) -> Result<usize>
pub async fn cleanup_audit_events(&self) -> Result<usize>
Clean up old audit events
Sourcepub fn setup_policy_service(&mut self, config: PolicyEngineConfig) -> Result<()>
pub fn setup_policy_service(&mut self, config: PolicyEngineConfig) -> Result<()>
Set up policy service with RBAC and ABAC
Sourcepub fn set_policy_service(&mut self, policy_service: PolicyService)
pub fn set_policy_service(&mut self, policy_service: PolicyService)
Set policy service directly
Sourcepub async fn check_access_policy(
&self,
principal_id: &str,
resource_type: &ResourceType,
resource_id: Option<&str>,
action: &Action,
) -> Result<bool>
pub async fn check_access_policy( &self, principal_id: &str, resource_type: &ResourceType, resource_id: Option<&str>, action: &Action, ) -> Result<bool>
Check access permission using unified RBAC/ABAC policy engine
Authorize action with detailed policy decision
Sourcepub fn assign_role(&mut self, assignment: RoleAssignment) -> Result<()>
pub fn assign_role(&mut self, assignment: RoleAssignment) -> Result<()>
Assign role to principal
Sourcepub fn add_policy(&mut self, policy: Policy) -> Result<()>
pub fn add_policy(&mut self, policy: Policy) -> Result<()>
Add ABAC policy
Sourcepub fn setup_common_policies(&mut self) -> Result<()>
pub fn setup_common_policies(&mut self) -> Result<()>
Setup common roles and policies
Sourcepub fn policy_service(&self) -> Option<&PolicyService>
pub fn policy_service(&self) -> Option<&PolicyService>
Get policy service for advanced operations
Sourcepub fn policy_service_mut(&mut self) -> Option<&mut PolicyService>
pub fn policy_service_mut(&mut self) -> Option<&mut PolicyService>
Get mutable policy service
Auto Trait Implementations§
impl Freeze for SecurityService
impl !RefUnwindSafe for SecurityService
impl Send for SecurityService
impl Sync for SecurityService
impl Unpin for SecurityService
impl !UnwindSafe for SecurityService
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
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