pub struct SecurityEvent {
pub id: String,
pub timestamp: u64,
pub event_type: SecurityEventType,
pub severity: SecurityEventSeverity,
pub username: Option<String>,
pub ip_address: Option<String>,
pub user_agent: Option<String>,
pub path: Option<String>,
pub method: Option<String>,
pub session_id: Option<String>,
pub details: HashMap<String, String>,
pub error: Option<String>,
}Expand description
A security audit event.
Fields§
§id: StringUnique event ID
timestamp: u64Event timestamp (Unix epoch milliseconds)
event_type: SecurityEventTypeEvent type
severity: SecurityEventSeverityEvent severity
username: Option<String>Username (if applicable)
ip_address: Option<String>Source IP address
user_agent: Option<String>User agent
path: Option<String>Request path
method: Option<String>HTTP method
session_id: Option<String>Session ID (if applicable)
details: HashMap<String, String>Additional details
error: Option<String>Error message (for failure events)
Implementations§
Source§impl SecurityEvent
impl SecurityEvent
Sourcepub fn new(event_type: SecurityEventType) -> SecurityEvent
pub fn new(event_type: SecurityEventType) -> SecurityEvent
Create a new security event.
Sourcepub fn username(self, username: impl Into<String>) -> SecurityEvent
pub fn username(self, username: impl Into<String>) -> SecurityEvent
Set the username.
Sourcepub fn ip_address(self, ip: impl Into<String>) -> SecurityEvent
pub fn ip_address(self, ip: impl Into<String>) -> SecurityEvent
Set the IP address.
Sourcepub fn user_agent(self, ua: impl Into<String>) -> SecurityEvent
pub fn user_agent(self, ua: impl Into<String>) -> SecurityEvent
Set the user agent.
Sourcepub fn path(self, path: impl Into<String>) -> SecurityEvent
pub fn path(self, path: impl Into<String>) -> SecurityEvent
Set the request path.
Sourcepub fn method(self, method: impl Into<String>) -> SecurityEvent
pub fn method(self, method: impl Into<String>) -> SecurityEvent
Set the HTTP method.
Sourcepub fn session_id(self, id: impl Into<String>) -> SecurityEvent
pub fn session_id(self, id: impl Into<String>) -> SecurityEvent
Set the session ID.
Sourcepub fn severity(self, severity: SecurityEventSeverity) -> SecurityEvent
pub fn severity(self, severity: SecurityEventSeverity) -> SecurityEvent
Set the severity (overrides default).
Sourcepub fn detail(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> SecurityEvent
pub fn detail( self, key: impl Into<String>, value: impl Into<String>, ) -> SecurityEvent
Add a detail.
Sourcepub fn error(self, error: impl Into<String>) -> SecurityEvent
pub fn error(self, error: impl Into<String>) -> SecurityEvent
Set the error message.
Sourcepub fn login_success(username: &str, ip: &str) -> SecurityEvent
pub fn login_success(username: &str, ip: &str) -> SecurityEvent
Create a login success event.
Sourcepub fn login_failure(username: &str, ip: &str, reason: &str) -> SecurityEvent
pub fn login_failure(username: &str, ip: &str, reason: &str) -> SecurityEvent
Create a login failure event.
Sourcepub fn access_denied(username: &str, path: &str, ip: &str) -> SecurityEvent
pub fn access_denied(username: &str, path: &str, ip: &str) -> SecurityEvent
Create an access denied event.
Sourcepub fn rate_limit_exceeded(ip: &str, path: &str) -> SecurityEvent
pub fn rate_limit_exceeded(ip: &str, path: &str) -> SecurityEvent
Create a rate limit exceeded event.
Sourcepub fn account_locked(username: &str, ip: &str, reason: &str) -> SecurityEvent
pub fn account_locked(username: &str, ip: &str, reason: &str) -> SecurityEvent
Create an account locked event.
Sourcepub fn brute_force_detected(ip: &str, attempts: u32) -> SecurityEvent
pub fn brute_force_detected(ip: &str, attempts: u32) -> SecurityEvent
Create a brute force detected event.
Sourcepub fn to_log_line(&self) -> String
pub fn to_log_line(&self) -> String
Format the event as a log line.
Trait Implementations§
Source§impl Clone for SecurityEvent
impl Clone for SecurityEvent
Source§fn clone(&self) -> SecurityEvent
fn clone(&self) -> SecurityEvent
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SecurityEvent
impl Debug for SecurityEvent
Source§impl Serialize for SecurityEvent
impl Serialize for SecurityEvent
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for SecurityEvent
impl RefUnwindSafe for SecurityEvent
impl Send for SecurityEvent
impl Sync for SecurityEvent
impl Unpin for SecurityEvent
impl UnwindSafe for SecurityEvent
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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