feat: complete Phase 2.6 - Security Hardening
- Implement session management with device tracking - Implement audit logging system - Implement account lockout for brute-force protection - Add security headers middleware - Add rate limiting middleware (stub) - Integrate security services into main application Build Status: Compiles successfully Phase: 2.6 of 8 (75% complete)
This commit is contained in:
parent
be49d9d674
commit
4627903999
17 changed files with 910 additions and 61 deletions
34
backend/src/security/audit_logger.rs
Normal file
34
backend/src/security/audit_logger.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use anyhow::Result;
|
||||
use mongodb::bson::oid::ObjectId;
|
||||
use crate::models::audit_log::{AuditLog, AuditLogRepository, AuditEventType};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AuditLogger {
|
||||
repository: AuditLogRepository,
|
||||
}
|
||||
|
||||
impl AuditLogger {
|
||||
pub fn new(db: &mongodb::Database) -> Self {
|
||||
Self {
|
||||
repository: AuditLogRepository::new(db),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn log_event(
|
||||
&self,
|
||||
event_type: AuditEventType,
|
||||
user_id: Option<ObjectId>,
|
||||
email: Option<String>,
|
||||
ip_address: String,
|
||||
resource_type: Option<String>,
|
||||
resource_id: Option<String>,
|
||||
) -> Result<ObjectId> {
|
||||
self.repository
|
||||
.log(event_type, user_id, email, ip_address, resource_type, resource_id)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_user_audit_logs(&self, user_id: &ObjectId) -> Result<Vec<AuditLog>> {
|
||||
self.repository.find_by_user(user_id).await
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue