inferno-ai 0.10.3

Enterprise AI/ML model runner with automatic updates, real-time monitoring, and multi-interface support
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
#![allow(clippy::clone_on_copy)]

use chrono::{DateTime, Utc};
use rand::Rng;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use uuid::Uuid;

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ApiKey {
    pub id: String,
    pub name: String,
    pub key_hash: String,
    pub key_prefix: String, // First 8 characters for display
    pub permissions: Vec<String>,
    pub created_at: DateTime<Utc>,
    pub last_used: Option<DateTime<Utc>>,
    pub expires_at: Option<DateTime<Utc>>,
    pub is_active: bool,
    pub usage_count: u64,
    pub created_by: String,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SecurityEvent {
    pub id: String,
    pub event_type: SecurityEventType,
    pub severity: SecuritySeverity,
    pub timestamp: DateTime<Utc>,
    pub source_ip: Option<String>,
    pub user_agent: Option<String>,
    pub api_key_id: Option<String>,
    pub description: String,
    pub metadata: HashMap<String, serde_json::Value>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "lowercase")]
pub enum SecurityEventType {
    ApiKeyCreated,
    ApiKeyRevoked,
    ApiKeyUsed,
    UnauthorizedAccess,
    AuthenticationFailed,
    PermissionDenied,
    SuspiciousActivity,
    ConfigurationChanged,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "lowercase")]
pub enum SecuritySeverity {
    Low,
    Medium,
    High,
    Critical,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SecurityMetrics {
    pub total_api_keys: u32,
    pub active_api_keys: u32,
    pub expired_api_keys: u32,
    pub security_events_24h: u32,
    pub failed_auth_attempts_24h: u32,
    pub suspicious_activities_24h: u32,
    pub last_security_scan: Option<DateTime<Utc>>,
}

/// Result of a security scan
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SecurityScanResult {
    pub scan_id: String,
    pub timestamp: DateTime<Utc>,
    pub status: String, // "passed" | "warnings" | "failed"
    pub checks_passed: u32,
    pub checks_failed: u32,
    pub checks_warning: u32,
    pub findings: Vec<SecurityFinding>,
    pub recommendations: Vec<String>,
    pub scan_duration_ms: u64,
}

/// Individual security finding from a scan
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct SecurityFinding {
    pub id: String,
    pub category: String,
    pub severity: SecuritySeverity,
    pub title: String,
    pub description: String,
    pub remediation: Option<String>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CreateApiKeyRequest {
    pub name: String,
    pub permissions: Vec<String>,
    pub expires_in_days: Option<u32>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CreateApiKeyResponse {
    pub api_key: ApiKey,
    pub raw_key: String, // Only returned once during creation
}

pub struct SecurityManager {
    api_keys: Arc<Mutex<Vec<ApiKey>>>,
    security_events: Arc<Mutex<Vec<SecurityEvent>>>,
    last_security_scan: Arc<Mutex<Option<DateTime<Utc>>>>,
}

impl SecurityManager {
    pub fn new<T>(_database_manager: T) -> Self
    where
        T: Send + Sync + 'static,
    {
        Self {
            api_keys: Arc::new(Mutex::new(Vec::new())),
            security_events: Arc::new(Mutex::new(Vec::new())),
            last_security_scan: Arc::new(Mutex::new(None)),
        }
    }

    pub async fn generate_api_key(
        &self,
        request: CreateApiKeyRequest,
    ) -> Result<CreateApiKeyResponse, String> {
        // Generate a secure random API key
        let raw_key = self.generate_secure_key();
        let key_hash = self.hash_key(&raw_key);
        let key_prefix = raw_key.chars().take(8).collect::<String>();

        let expires_at = request
            .expires_in_days
            .map(|days| Utc::now() + chrono::Duration::days(days as i64));

        let api_key = ApiKey {
            id: Uuid::new_v4().to_string(),
            name: request.name.clone(),
            key_hash,
            key_prefix,
            permissions: request.permissions,
            created_at: Utc::now(),
            last_used: None,
            expires_at,
            is_active: true,
            usage_count: 0,
            created_by: "system".to_string(), // TODO: Replace with actual user when auth is implemented
        };

        // Store the API key
        let mut keys = self.api_keys.lock().map_err(|e| e.to_string())?;
        keys.push(api_key.clone());

        // Log security event
        self.log_security_event(SecurityEvent {
            id: Uuid::new_v4().to_string(),
            event_type: SecurityEventType::ApiKeyCreated,
            severity: SecuritySeverity::Medium,
            timestamp: Utc::now(),
            source_ip: None,
            user_agent: None,
            api_key_id: Some(api_key.id.clone()),
            description: format!("API key '{}' created", request.name),
            metadata: HashMap::new(),
        });

        Ok(CreateApiKeyResponse { api_key, raw_key })
    }

    pub async fn get_api_keys(&self) -> Result<Vec<ApiKey>, String> {
        let keys = self.api_keys.lock().map_err(|e| e.to_string())?;
        Ok(keys.clone())
    }

    pub async fn revoke_api_key(&self, key_id: String) -> Result<(), String> {
        let mut keys = self.api_keys.lock().map_err(|e| e.to_string())?;

        if let Some(key) = keys.iter_mut().find(|k| k.id == key_id) {
            key.is_active = false;

            // Log security event
            self.log_security_event(SecurityEvent {
                id: Uuid::new_v4().to_string(),
                event_type: SecurityEventType::ApiKeyRevoked,
                severity: SecuritySeverity::Medium,
                timestamp: Utc::now(),
                source_ip: None,
                user_agent: None,
                api_key_id: Some(key_id),
                description: format!("API key '{}' revoked", key.name),
                metadata: HashMap::new(),
            });

            Ok(())
        } else {
            Err("API key not found".to_string())
        }
    }

    pub async fn delete_api_key(&self, key_id: String) -> Result<(), String> {
        let mut keys = self.api_keys.lock().map_err(|e| e.to_string())?;
        let initial_len = keys.len();
        keys.retain(|k| k.id != key_id);

        if keys.len() < initial_len {
            // Log security event
            self.log_security_event(SecurityEvent {
                id: Uuid::new_v4().to_string(),
                event_type: SecurityEventType::ApiKeyRevoked,
                severity: SecuritySeverity::High,
                timestamp: Utc::now(),
                source_ip: None,
                user_agent: None,
                api_key_id: Some(key_id),
                description: "API key permanently deleted".to_string(),
                metadata: HashMap::new(),
            });

            Ok(())
        } else {
            Err("API key not found".to_string())
        }
    }

    pub async fn validate_api_key(&self, raw_key: String) -> Result<Option<ApiKey>, String> {
        let key_hash = self.hash_key(&raw_key);
        let mut keys = self.api_keys.lock().map_err(|e| e.to_string())?;

        if let Some(key) = keys
            .iter_mut()
            .find(|k| k.key_hash == key_hash && k.is_active)
        {
            // Check if key is expired
            if let Some(expires_at) = key.expires_at {
                if Utc::now() > expires_at {
                    key.is_active = false;
                    return Ok(None);
                }
            }

            // Update usage statistics
            key.last_used = Some(Utc::now());
            key.usage_count += 1;

            // Log usage event
            self.log_security_event(SecurityEvent {
                id: Uuid::new_v4().to_string(),
                event_type: SecurityEventType::ApiKeyUsed,
                severity: SecuritySeverity::Low,
                timestamp: Utc::now(),
                source_ip: None,
                user_agent: None,
                api_key_id: Some(key.id.clone()),
                description: "API key used successfully".to_string(),
                metadata: HashMap::new(),
            });

            Ok(Some(key.clone()))
        } else {
            // Log failed authentication
            self.log_security_event(SecurityEvent {
                id: Uuid::new_v4().to_string(),
                event_type: SecurityEventType::AuthenticationFailed,
                severity: SecuritySeverity::High,
                timestamp: Utc::now(),
                source_ip: None,
                user_agent: None,
                api_key_id: None,
                description: "Invalid API key used".to_string(),
                metadata: HashMap::new(),
            });

            Ok(None)
        }
    }

    pub async fn get_security_events(
        &self,
        limit: Option<usize>,
    ) -> Result<Vec<SecurityEvent>, String> {
        let events = self.security_events.lock().map_err(|e| e.to_string())?;
        let limit = limit.unwrap_or(100);

        // Return most recent events first
        let mut sorted_events = events.clone();
        sorted_events.sort_by(|a, b| b.timestamp.cmp(&a.timestamp));
        sorted_events.truncate(limit);

        Ok(sorted_events)
    }

    pub async fn get_security_metrics(&self) -> Result<SecurityMetrics, String> {
        let keys = self.api_keys.lock().map_err(|e| e.to_string())?;
        let events = self.security_events.lock().map_err(|e| e.to_string())?;

        let total_api_keys = keys.len() as u32;
        let active_api_keys = keys.iter().filter(|k| k.is_active).count() as u32;
        let expired_api_keys = keys
            .iter()
            .filter(|k| {
                if let Some(expires_at) = k.expires_at {
                    Utc::now() > expires_at
                } else {
                    false
                }
            })
            .count() as u32;

        let twenty_four_hours_ago = Utc::now() - chrono::Duration::hours(24);
        let security_events_24h = events
            .iter()
            .filter(|e| e.timestamp > twenty_four_hours_ago)
            .count() as u32;

        let failed_auth_attempts_24h = events
            .iter()
            .filter(|e| {
                e.timestamp > twenty_four_hours_ago
                    && matches!(e.event_type, SecurityEventType::AuthenticationFailed)
            })
            .count() as u32;

        let suspicious_activities_24h = events
            .iter()
            .filter(|e| {
                e.timestamp > twenty_four_hours_ago
                    && matches!(e.event_type, SecurityEventType::SuspiciousActivity)
            })
            .count() as u32;

        // Get actual last scan time
        let last_scan = self
            .last_security_scan
            .lock()
            .map_err(|e| e.to_string())?
            .clone();

        Ok(SecurityMetrics {
            total_api_keys,
            active_api_keys,
            expired_api_keys,
            security_events_24h,
            failed_auth_attempts_24h,
            suspicious_activities_24h,
            last_security_scan: last_scan,
        })
    }

    pub async fn clear_security_events(&self) -> Result<(), String> {
        let mut events = self.security_events.lock().map_err(|e| e.to_string())?;
        events.clear();
        Ok(())
    }

    /// Run a comprehensive security scan
    ///
    /// This performs multiple security checks:
    /// - API key expiration warnings
    /// - Failed authentication attempt analysis
    /// - Suspicious activity detection
    /// - Configuration security assessment
    pub async fn run_security_scan(&self) -> Result<SecurityScanResult, String> {
        let start = std::time::Instant::now();
        let mut findings = Vec::new();
        let mut recommendations = Vec::new();
        let mut checks_passed = 0u32;
        let mut checks_failed = 0u32;
        let mut checks_warning = 0u32;

        let now = Utc::now();
        let seven_days = chrono::Duration::days(7);
        let twenty_four_hours = chrono::Duration::hours(24);

        // Check 1: API Key Expiration
        {
            let keys = self.api_keys.lock().map_err(|e| e.to_string())?;
            let mut expiring_soon = 0;
            let mut expired = 0;

            for key in keys.iter() {
                if let Some(expires_at) = key.expires_at {
                    if expires_at < now {
                        expired += 1;
                        findings.push(SecurityFinding {
                            id: Uuid::new_v4().to_string(),
                            category: "API Keys".to_string(),
                            severity: SecuritySeverity::Medium,
                            title: format!("API key '{}' has expired", key.name),
                            description: format!(
                                "The API key '{}' expired on {}",
                                key.name,
                                expires_at.format("%Y-%m-%d")
                            ),
                            remediation: Some(
                                "Revoke the expired key and create a new one if still needed."
                                    .to_string(),
                            ),
                        });
                    } else if expires_at < now + seven_days {
                        expiring_soon += 1;
                        findings.push(SecurityFinding {
                            id: Uuid::new_v4().to_string(),
                            category: "API Keys".to_string(),
                            severity: SecuritySeverity::Low,
                            title: format!("API key '{}' expires soon", key.name),
                            description: format!(
                                "The API key '{}' will expire on {}",
                                key.name,
                                expires_at.format("%Y-%m-%d")
                            ),
                            remediation: Some(
                                "Consider renewing the API key before it expires.".to_string(),
                            ),
                        });
                    }
                }
            }

            if expired > 0 {
                checks_warning += 1;
                recommendations.push(format!("Revoke {} expired API key(s)", expired));
            } else {
                checks_passed += 1;
            }

            if expiring_soon > 0 {
                recommendations.push(format!(
                    "Renew {} API key(s) expiring within 7 days",
                    expiring_soon
                ));
            }
        }

        // Check 2: Failed Authentication Attempts
        {
            let events = self.security_events.lock().map_err(|e| e.to_string())?;
            let failed_auth_count = events
                .iter()
                .filter(|e| e.timestamp > now - twenty_four_hours)
                .filter(|e| matches!(e.event_type, SecurityEventType::AuthenticationFailed))
                .count();

            if failed_auth_count > 10 {
                checks_failed += 1;
                findings.push(SecurityFinding {
                    id: Uuid::new_v4().to_string(),
                    category: "Authentication".to_string(),
                    severity: SecuritySeverity::High,
                    title: "High number of failed authentication attempts".to_string(),
                    description: format!("{} failed authentication attempts in the last 24 hours", failed_auth_count),
                    remediation: Some("Review failed authentication logs and consider implementing rate limiting.".to_string()),
                });
                recommendations
                    .push("Investigate the source of failed authentication attempts".to_string());
            } else if failed_auth_count > 5 {
                checks_warning += 1;
                findings.push(SecurityFinding {
                    id: Uuid::new_v4().to_string(),
                    category: "Authentication".to_string(),
                    severity: SecuritySeverity::Medium,
                    title: "Elevated failed authentication attempts".to_string(),
                    description: format!(
                        "{} failed authentication attempts in the last 24 hours",
                        failed_auth_count
                    ),
                    remediation: Some("Monitor authentication logs for patterns.".to_string()),
                });
            } else {
                checks_passed += 1;
            }
        }

        // Check 3: Suspicious Activity
        {
            let events = self.security_events.lock().map_err(|e| e.to_string())?;
            let suspicious_count = events
                .iter()
                .filter(|e| e.timestamp > now - twenty_four_hours)
                .filter(|e| matches!(e.event_type, SecurityEventType::SuspiciousActivity))
                .count();

            if suspicious_count > 0 {
                checks_warning += 1;
                findings.push(SecurityFinding {
                    id: Uuid::new_v4().to_string(),
                    category: "Activity".to_string(),
                    severity: SecuritySeverity::High,
                    title: "Suspicious activity detected".to_string(),
                    description: format!(
                        "{} suspicious activity event(s) in the last 24 hours",
                        suspicious_count
                    ),
                    remediation: Some(
                        "Review the suspicious activity events and take appropriate action."
                            .to_string(),
                    ),
                });
                recommendations.push("Review and address suspicious activity alerts".to_string());
            } else {
                checks_passed += 1;
            }
        }

        // Check 4: Unauthorized Access Attempts
        {
            let events = self.security_events.lock().map_err(|e| e.to_string())?;
            let unauthorized_count = events
                .iter()
                .filter(|e| e.timestamp > now - twenty_four_hours)
                .filter(|e| matches!(e.event_type, SecurityEventType::UnauthorizedAccess))
                .count();

            if unauthorized_count > 0 {
                checks_failed += 1;
                findings.push(SecurityFinding {
                    id: Uuid::new_v4().to_string(),
                    category: "Access Control".to_string(),
                    severity: SecuritySeverity::Critical,
                    title: "Unauthorized access attempts detected".to_string(),
                    description: format!(
                        "{} unauthorized access attempt(s) in the last 24 hours",
                        unauthorized_count
                    ),
                    remediation: Some(
                        "Investigate the source of unauthorized access attempts immediately."
                            .to_string(),
                    ),
                });
                recommendations
                    .push("Investigate unauthorized access attempts immediately".to_string());
            } else {
                checks_passed += 1;
            }
        }

        // Check 5: API Key Usage
        {
            let keys = self.api_keys.lock().map_err(|e| e.to_string())?;
            let unused_keys: Vec<_> = keys
                .iter()
                .filter(|k| k.is_active && k.last_used.is_none())
                .filter(|k| (now - k.created_at) > chrono::Duration::days(30))
                .collect();

            if !unused_keys.is_empty() {
                checks_warning += 1;
                for key in unused_keys {
                    findings.push(SecurityFinding {
                        id: Uuid::new_v4().to_string(),
                        category: "API Keys".to_string(),
                        severity: SecuritySeverity::Low,
                        title: format!("API key '{}' has never been used", key.name),
                        description: format!(
                            "The API key '{}' was created over 30 days ago but has never been used",
                            key.name
                        ),
                        remediation: Some(
                            "Consider revoking unused API keys to reduce security risk."
                                .to_string(),
                        ),
                    });
                }
                recommendations.push("Review and revoke unused API keys".to_string());
            } else {
                checks_passed += 1;
            }
        }

        let duration_ms = start.elapsed().as_millis() as u64;
        let status = if checks_failed > 0 {
            "failed"
        } else if checks_warning > 0 {
            "warnings"
        } else {
            "passed"
        };

        // Update last scan time
        if let Ok(mut last_scan) = self.last_security_scan.lock() {
            *last_scan = Some(now);
        }

        // Log the scan as a security event
        self.log_security_event(SecurityEvent {
            id: Uuid::new_v4().to_string(),
            event_type: SecurityEventType::ConfigurationChanged,
            severity: if checks_failed > 0 {
                SecuritySeverity::High
            } else {
                SecuritySeverity::Low
            },
            timestamp: now,
            source_ip: None,
            user_agent: None,
            api_key_id: None,
            description: format!(
                "Security scan completed: {} passed, {} warnings, {} failed",
                checks_passed, checks_warning, checks_failed
            ),
            metadata: HashMap::new(),
        });

        Ok(SecurityScanResult {
            scan_id: Uuid::new_v4().to_string(),
            timestamp: now,
            status: status.to_string(),
            checks_passed,
            checks_failed,
            checks_warning,
            findings,
            recommendations,
            scan_duration_ms: duration_ms,
        })
    }

    fn generate_secure_key(&self) -> String {
        const CHARSET: &[u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        let mut rng = rand::thread_rng();

        // Generate a 32-character key with prefix
        let prefix = "inf_";
        let key_part: String = (0..28)
            .map(|_| {
                let idx = rng.gen_range(0..CHARSET.len());
                CHARSET[idx] as char
            })
            .collect();

        format!("{}{}", prefix, key_part)
    }

    fn hash_key(&self, key: &str) -> String {
        let mut hasher = Sha256::new();
        hasher.update(key.as_bytes());
        format!("{:x}", hasher.finalize())
    }

    fn log_security_event(&self, event: SecurityEvent) {
        if let Ok(mut events) = self.security_events.lock() {
            events.push(event);

            // Keep only last 1000 events to prevent memory issues
            if events.len() > 1000 {
                let len = events.len();
                events.drain(0..len - 1000);
            }
        }
    }

    // Initialize with some sample data for testing
    pub async fn initialize_with_sample_data(&self) -> Result<(), String> {
        // Create a sample API key
        let sample_request = CreateApiKeyRequest {
            name: "Dashboard Access".to_string(),
            permissions: vec!["read".to_string(), "write".to_string()],
            expires_in_days: Some(30),
        };

        self.generate_api_key(sample_request).await?;

        // Add some sample security events
        let sample_events = vec![
            SecurityEvent {
                id: Uuid::new_v4().to_string(),
                event_type: SecurityEventType::UnauthorizedAccess,
                severity: SecuritySeverity::High,
                timestamp: Utc::now() - chrono::Duration::hours(2),
                source_ip: Some("192.168.1.100".to_string()),
                user_agent: Some("Mozilla/5.0".to_string()),
                api_key_id: None,
                description: "Unauthorized access attempt detected".to_string(),
                metadata: HashMap::new(),
            },
            SecurityEvent {
                id: Uuid::new_v4().to_string(),
                event_type: SecurityEventType::SuspiciousActivity,
                severity: SecuritySeverity::Medium,
                timestamp: Utc::now() - chrono::Duration::hours(1),
                source_ip: Some("10.0.0.5".to_string()),
                user_agent: None,
                api_key_id: None,
                description: "Multiple failed authentication attempts".to_string(),
                metadata: HashMap::new(),
            },
        ];

        if let Ok(mut events) = self.security_events.lock() {
            events.extend(sample_events);
        }

        Ok(())
    }
}

impl Default for SecurityManager {
    fn default() -> Self {
        Self::new(())
    }
}