#[derive(Debug, thiserror::Error)]
pub enum SecurityError {
#[error("Authentication failed: {0}")]
AuthenticationFailed(String),
#[error("Authorization denied: {0}")]
AuthorizationDenied(String),
#[error("Token error: {0}")]
TokenError(String),
#[error("Session error: {0}")]
SessionError(String),
#[error("Configuration error: {0}")]
ConfigurationError(String),
#[error("Audit error: {0}")]
AuditError(String),
#[error("Data governance violation: {0}")]
DataGovernanceViolation(String),
}
impl SecurityError {
pub fn authentication_failed(message: impl Into<String>) -> Self {
Self::AuthenticationFailed(message.into())
}
pub fn authorization_denied(message: impl Into<String>) -> Self {
Self::AuthorizationDenied(message.into())
}
pub fn token_error(message: impl Into<String>) -> Self {
Self::TokenError(message.into())
}
pub fn session_error(message: impl Into<String>) -> Self {
Self::SessionError(message.into())
}
pub fn configuration_error(message: impl Into<String>) -> Self {
Self::ConfigurationError(message.into())
}
pub fn audit_error(message: impl Into<String>) -> Self {
Self::AuditError(message.into())
}
pub fn data_governance_violation(message: impl Into<String>) -> Self {
Self::DataGovernanceViolation(message.into())
}
pub fn is_authentication_error(&self) -> bool {
matches!(self, SecurityError::AuthenticationFailed(_))
}
pub fn is_authorization_error(&self) -> bool {
matches!(self, SecurityError::AuthorizationDenied(_))
}
pub fn is_token_error(&self) -> bool {
matches!(self, SecurityError::TokenError(_))
}
pub fn is_session_error(&self) -> bool {
matches!(self, SecurityError::SessionError(_))
}
pub fn is_configuration_error(&self) -> bool {
matches!(self, SecurityError::ConfigurationError(_))
}
pub fn is_audit_error(&self) -> bool {
matches!(self, SecurityError::AuditError(_))
}
pub fn is_data_governance_violation(&self) -> bool {
matches!(self, SecurityError::DataGovernanceViolation(_))
}
}