| """ |
| ATOM Enterprise Security Service |
| Advanced enterprise-grade security with AI-powered threat detection and compliance automation |
| """ |
|
|
| import asyncio |
| import base64 |
| from collections import Counter, defaultdict |
| from dataclasses import asdict, dataclass |
| from datetime import datetime, timedelta, timezone |
| from enum import Enum |
| import hashlib |
| from ipaddress import ip_address, ip_network |
| import json |
| import logging |
| import os |
| import re |
| import time |
| from typing import Any, Callable, Dict, List, Optional, Tuple, Union |
| import aiohttp |
| from cryptography.fernet import Fernet |
| from cryptography.hazmat.primitives import hashes |
| from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC |
| import geoip2.database |
| import httpx |
| import jwt |
| import numpy as np |
| import pandas as pd |
| from core.circuit_breaker import circuit_breaker |
| from core.rate_limiter import rate_limiter, should_retry, calculate_backoff |
| from core.audit_logger import log_integration_call, log_integration_error, log_integration_attempt, log_integration_complete |
| from fastapi import HTTPException |
|
|
|
|
| |
| try: |
| from ai_enhanced_service import ( |
| AIModelType, |
| AIRequest, |
| AIResponse, |
| AIServiceType, |
| AITaskType, |
| ai_enhanced_service, |
| ) |
| from atom_ai_integration import atom_ai_integration |
| from atom_ingestion_pipeline import AtomIngestionPipeline |
| from atom_memory_service import AtomMemoryService |
| from atom_search_service import AtomSearchService |
| from atom_workflow_service import AtomWorkflowService |
| except ImportError as e: |
| logging.warning(f"Enterprise security services not available: {e}") |
|
|
| |
| logger = logging.getLogger(__name__) |
|
|
| class SecurityLevel(Enum): |
| """Security levels for enterprise""" |
| BASIC = "basic" |
| STANDARD = "standard" |
| ADVANCED = "advanced" |
| ENTERPRISE = "enterprise" |
| GOVERNMENT = "government" |
|
|
| class ComplianceStandard(Enum): |
| """Compliance standards""" |
| GDPR = "gdpr" |
| CCPA = "ccpa" |
| HIPAA = "hipaa" |
| SOX = "sox" |
| SOC2 = "soc2" |
| ISO27001 = "iso27001" |
| PCI_DSS = "pci_dss" |
| NIST = "nist" |
| FEDRAMP = "fedramp" |
|
|
| class ThreatType(Enum): |
| """Threat types for detection""" |
| SQL_INJECTION = "sql_injection" |
| XSS = "xss" |
| CSRF = "csrf" |
| AUTH_BYPASS = "auth_bypass" |
| PRIVILEGE_ESCALATION = "privilege_escalation" |
| DATA_EXFILTRATION = "data_exfiltration" |
| DDoS = "ddos" |
| MALWARE = "malware" |
| PHISHING = "phishing" |
| INSIDER_THREAT = "insider_threat" |
| ANOMALOUS_BEHAVIOR = "anomalous_behavior" |
| COMPROMISED_ACCOUNT = "compromised_account" |
|
|
| class AuditEventType(Enum): |
| """Audit event types""" |
| USER_LOGIN = "user_login" |
| USER_LOGOUT = "user_logout" |
| ACCESS_GRANTED = "access_granted" |
| ACCESS_DENIED = "access_denied" |
| DATA_ACCESS = "data_access" |
| DATA_MODIFICATION = "data_modification" |
| FILE_UPLOAD = "file_upload" |
| FILE_DOWNLOAD = "file_download" |
| MESSAGE_SENT = "message_sent" |
| WORKFLOW_EXECUTED = "workflow_executed" |
| CONFIG_CHANGED = "config_changed" |
| SECURITY_ALERT = "security_alert" |
| COMPLIANCE_CHECK = "compliance_check" |
|
|
| @dataclass |
| class SecurityPolicy: |
| """Security policy data model""" |
| policy_id: str |
| name: str |
| description: str |
| security_level: SecurityLevel |
| compliance_standards: List[ComplianceStandard] |
| rules: List[Dict[str, Any]] |
| enforcement_actions: List[str] |
| exceptions: List[str] |
| created_at: datetime |
| updated_at: datetime |
| created_by: str |
| is_active: bool = True |
| version: int = 1 |
|
|
| @dataclass |
| class ThreatDetection: |
| """Threat detection data model""" |
| detection_id: str |
| threat_type: ThreatType |
| severity: str |
| confidence: float |
| source_ip: str |
| user_id: str |
| session_id: str |
| timestamp: datetime |
| description: str |
| indicators: List[str] |
| mitigated: bool = False |
| mitigation_actions: List[str] = None |
| metadata: Dict[str, Any] = None |
|
|
| @dataclass |
| class ComplianceReport: |
| """Compliance report data model""" |
| report_id: str |
| standard: ComplianceStandard |
| period: str |
| overall_score: float |
| findings: List[Dict[str, Any]] |
| recommendations: List[str] |
| artifacts: List[str] |
| generated_at: datetime |
| generated_by: str |
|
|
| @dataclass |
| class SecurityAudit: |
| """Security audit data model""" |
| audit_id: str |
| event_type: AuditEventType |
| user_id: str |
| resource: str |
| action: str |
| result: str |
| ip_address: str |
| user_agent: str |
| timestamp: datetime |
| metadata: Dict[str, Any] = None |
|
|
| class AtomEnterpriseSecurityService: |
| """Enterprise-grade security service with AI-powered threat detection""" |
| |
| def __init__(self, tenant_id: str = "default", config: Dict[str, Any] = None): |
| if config is None: |
| config = {} |
| self.config = config |
| self.db = config.get('database') |
| self.cache = config.get('cache') |
| self.ai_service = config.get('ai_service') |
| |
| |
| self.security_config = { |
| 'encryption_key': config.get('encryption_key') or self._generate_encryption_key(), |
| 'session_timeout': config.get('session_timeout', 3600), |
| 'max_login_attempts': config.get('max_login_attempts', 5), |
| 'lockout_duration': config.get('lockout_duration', 900), |
| 'password_policy': config.get('password_policy', { |
| 'min_length': 12, |
| 'require_upper': True, |
| 'require_lower': True, |
| 'require_numbers': True, |
| 'require_special': True, |
| 'prevent_reuse': 5 |
| }), |
| 'geoip_database': config.get('geoip_database', 'GeoLite2-City.mmdb'), |
| 'threat_intelligence_apis': config.get('threat_intelligence_apis', []), |
| 'ai_threat_detection': config.get('ai_threat_detection', True), |
| 'compliance_standards': config.get('compliance_standards', [ |
| ComplianceStandard.GDPR, |
| ComplianceStandard.CCPA, |
| ComplianceStandard.SOC2, |
| ComplianceStandard.ISO27001 |
| ]) |
| } |
| |
| |
| self.cipher_suite = Fernet(self.security_config['encryption_key']) |
| |
| |
| self.active_policies: Dict[str, SecurityPolicy] = {} |
| self.threat_detections: List[ThreatDetection] = [] |
| self.audit_logs: List[SecurityAudit] = [] |
| self.compliance_reports: Dict[str, ComplianceReport] = {} |
| |
| |
| self.blocked_ips: Dict[str, datetime] = {} |
| self.active_sessions: Dict[str, Dict[str, Any]] = {} |
| self.user_security_contexts: Dict[str, Dict[str, Any]] = {} |
| |
| |
| self.malicious_patterns = self._load_malicious_patterns() |
| self.anomaly_baselines = {} |
| self.threat_intelligence_cache = {} |
| |
| |
| self.http_session = aiohttp.ClientSession( |
| timeout=aiohttp.ClientTimeout(total=30) |
| ) |
| |
| |
| self.security_metrics = { |
| 'total_threats_detected': 0, |
| 'threats_mitigated': 0, |
| 'audit_events_logged': 0, |
| 'compliance_checks_passed': 0, |
| 'security_policies_enforced': 0, |
| 'false_positives': 0, |
| 'average_threat_detection_time': 0.0 |
| } |
| |
| logger.info("Enterprise Security Service initialized") |
| |
| async def initialize(self) -> bool: |
| """Initialize enterprise security service""" |
| try: |
| |
| await self._initialize_encryption() |
| |
| |
| await self._load_security_policies() |
| |
| |
| await self._initialize_threat_detection() |
| |
| |
| await self._start_security_monitoring() |
| |
| |
| await self._initialize_compliance_monitoring() |
| |
| logger.info("Enterprise Security Service initialized successfully") |
| return True |
| |
| except Exception as e: |
| logger.error(f"Error initializing enterprise security service: {e}") |
| return False |
| |
| async def create_security_policy(self, policy_data: Dict[str, Any], user_id: str) -> Dict[str, Any]: |
| """Create enterprise security policy""" |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "initialize", locals()) |
| try: |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
|
|
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |
|
|
| policy_id = f"policy_{int(time.time())}_{hashlib.md5(policy_data['name'].encode()).hexdigest()[:8]}" |
| security_policy = SecurityPolicy( |
| policy_id=policy_id, |
| name=policy_data['name'], |
| description=policy_data['description'], |
| security_level=SecurityLevel(policy_data['security_level']), |
| compliance_standards=[ComplianceStandard(standard) for standard in policy_data['compliance_standards']], |
| rules=policy_data['rules'], |
| enforcement_actions=policy_data['enforcement_actions'], |
| exceptions=policy_data.get('exceptions', []), |
| created_at=datetime.utcnow(), |
| updated_at=datetime.utcnow(), |
| created_by=user_id |
| ) |
| |
| validation_result = await self._validate_security_policy(security_policy) |
| if not validation_result['valid']: |
| return { |
| 'ok': False, |
| 'error': f"Policy validation failed: {validation_result['errors']}" |
| } |
| |
| self.active_policies[policy_id] = security_policy |
| |
| if self.db: |
| await self.db.store_security_policy(asdict(security_policy)) |
| |
| await self._log_security_audit( |
| event_type=AuditEventType.CONFIG_CHANGED, |
| user_id=user_id, |
| resource='security_policy', |
| action='create', |
| result='success', |
| metadata={'policy_id': policy_id, 'policy_name': policy_data['name']} |
| ) |
| return { |
| 'ok': True, |
| 'policy_id': policy_id, |
| 'policy': asdict(security_policy), |
| 'message': "Security policy created successfully" |
| } |
| except Exception as e: |
| logger.error(f"Operation failed: {e}") |
| log_integration_complete(audit_ctx, error=e) |
| logger.error(f"Error creating security policy: {e}") |
| return {'ok': False, 'error': str(e)} |
| |
| async def detect_threat(self, event_data: Dict[str, Any]) -> ThreatDetection: |
| """Detect security threats using AI and pattern matching""" |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "create_security_policy", locals()) |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |
| try: |
| start_time = time.time() |
| |
| |
| source_ip = event_data.get('source_ip') |
| user_id = event_data.get('user_id') |
| session_id = event_data.get('session_id') |
| event_type = event_data.get('event_type') |
| |
| |
| pattern_threats = await self._pattern_based_detection(event_data) |
| |
| |
| anomaly_threats = await self._behavioral_anomaly_detection(event_data) |
| |
| |
| ai_threats = [] |
| if self.security_config['ai_threat_detection'] and self.ai_service: |
| ai_threats = await self._ai_threat_detection(event_data) |
| |
| |
| all_threats = pattern_threats + anomaly_threats + ai_threats |
| |
| |
| threat_detections = [] |
| for threat_info in all_threats: |
| detection_id = f"threat_{int(time.time())}_{hashlib.md5(str(threat_info).encode()).hexdigest()[:8]}" |
| |
| threat_detection = ThreatDetection( |
| detection_id=detection_id, |
| threat_type=ThreatType(threat_info['type']), |
| severity=threat_info['severity'], |
| confidence=threat_info['confidence'], |
| source_ip=source_ip, |
| user_id=user_id, |
| session_id=session_id, |
| timestamp=datetime.utcnow(), |
| description=threat_info['description'], |
| indicators=threat_info.get('indicators', []), |
| metadata=threat_info.get('metadata', {}) |
| ) |
| |
| threat_detections.append(threat_detection) |
| self.threat_detections.append(threat_detection) |
| |
| |
| for threat in threat_detections: |
| if threat.severity in ['critical', 'high']: |
| await self._mitigate_threat(threat) |
| |
| |
| detection_time = time.time() - start_time |
| self.security_metrics['total_threats_detected'] += len(threat_detections) |
| self.security_metrics['average_threat_detection_time'] = ( |
| (self.security_metrics['average_threat_detection_time'] * (self.security_metrics['total_threats_detected'] - len(threat_detections)) + detection_time) |
| / self.security_metrics['total_threats_detected'] |
| ) |
| |
| return threat_detections[0] if threat_detections else None |
| |
| except Exception as e: |
| logger.error(f"Error detecting threat: {e}") |
| return None |
| |
| async def audit_event(self, event_data: Dict[str, Any]) -> SecurityAudit: |
| """Audit security events""" |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "detect_threat", locals()) |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |
| try: |
| audit_id = f"audit_{int(time.time())}_{hashlib.md5(str(event_data).encode()).hexdigest()[:8]}" |
| |
| security_audit = SecurityAudit( |
| audit_id=audit_id, |
| event_type=AuditEventType(event_data['event_type']), |
| user_id=event_data['user_id'], |
| resource=event_data['resource'], |
| action=event_data['action'], |
| result=event_data['result'], |
| ip_address=event_data['ip_address'], |
| user_agent=event_data.get('user_agent', ''), |
| timestamp=datetime.utcnow(), |
| metadata=event_data.get('metadata', {}) |
| ) |
| |
| |
| self.audit_logs.append(security_audit) |
| |
| |
| if self.db: |
| await self.db.store_security_audit(asdict(security_audit)) |
| |
| |
| self.security_metrics['audit_events_logged'] += 1 |
| |
| |
| await self._check_compliance_for_event(security_audit) |
| |
| return security_audit |
| |
| except Exception as e: |
| logger.error(f"Error auditing event: {e}") |
| return None |
| |
| async def check_compliance(self, standard: ComplianceStandard, period: str = 'monthly') -> ComplianceReport: |
| """Generate compliance report""" |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "audit_event", locals()) |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |
| try: |
| report_id = f"compliance_{standard.value}_{period}_{int(time.time())}" |
| |
| |
| compliance_data = await self._get_compliance_data(standard, period) |
| |
| |
| compliance_analysis = await self._ai_compliance_analysis(standard, compliance_data) |
| |
| |
| overall_score = self._calculate_compliance_score(compliance_analysis) |
| |
| |
| findings = compliance_analysis.get('findings', []) |
| recommendations = compliance_analysis.get('recommendations', []) |
| |
| compliance_report = ComplianceReport( |
| report_id=report_id, |
| standard=standard, |
| period=period, |
| overall_score=overall_score, |
| findings=findings, |
| recommendations=recommendations, |
| artifacts=compliance_analysis.get('artifacts', []), |
| generated_at=datetime.utcnow(), |
| generated_by='enterprise_security_service' |
| ) |
| |
| |
| self.compliance_reports[report_id] = compliance_report |
| |
| |
| if overall_score >= 80: |
| self.security_metrics['compliance_checks_passed'] += 1 |
| |
| return compliance_report |
| |
| except Exception as e: |
| logger.error(f"Error checking compliance: {e}") |
| return None |
| |
| async def encrypt_data(self, data: str, context: Dict[str, Any] = None) -> str: |
| """Encrypt sensitive data""" |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "check_compliance", locals()) |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |
| try: |
| |
| if context: |
| context_data = json.dumps(context) |
| data_with_context = f"{data}|{context_data}" |
| else: |
| data_with_context = data |
| |
| |
| encrypted_data = self.cipher_suite.encrypt(data_with_context.encode()) |
| return base64.b64encode(encrypted_data).decode() |
| |
| except Exception as e: |
| logger.error(f"Error encrypting data: {e}") |
| raise |
| |
| async def decrypt_data(self, encrypted_data: str) -> Tuple[str, Optional[Dict[str, Any]]]: |
| """Decrypt sensitive data""" |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "encrypt_data", locals()) |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |
| try: |
| |
| encrypted_bytes = base64.b64decode(encrypted_data.encode()) |
| decrypted_data = self.cipher_suite.decrypt(encrypted_bytes).decode() |
| |
| |
| if '|' in decrypted_data: |
| data, context_json = decrypted_data.split('|', 1) |
| context = json.loads(context_json) if context_json else None |
| return data, context |
| else: |
| return decrypted_data, None |
| |
| except Exception as e: |
| logger.error(f"Error decrypting data: {e}") |
| raise |
| |
| async def validate_password(self, password: str, user_context: Dict[str, Any] = None) -> Dict[str, Any]: |
| """Validate password against security policy""" |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "decrypt_data", locals()) |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |
| try: |
| password_policy = self.security_config['password_policy'] |
| validation_result = { |
| 'valid': True, |
| 'score': 0, |
| 'issues': [], |
| 'suggestions': [] |
| } |
| |
| |
| if len(password) < password_policy['min_length']: |
| validation_result['valid'] = False |
| validation_result['issues'].append(f"Password must be at least {password_policy['min_length']} characters") |
| else: |
| validation_result['score'] += 20 |
| |
| |
| if password_policy['require_upper'] and not re.search(r'[A-Z]', password): |
| validation_result['valid'] = False |
| validation_result['issues'].append("Password must contain at least one uppercase letter") |
| elif re.search(r'[A-Z]', password): |
| validation_result['score'] += 20 |
| |
| |
| if password_policy['require_lower'] and not re.search(r'[a-z]', password): |
| validation_result['valid'] = False |
| validation_result['issues'].append("Password must contain at least one lowercase letter") |
| elif re.search(r'[a-z]', password): |
| validation_result['score'] += 20 |
| |
| |
| if password_policy['require_numbers'] and not re.search(r'\d', password): |
| validation_result['valid'] = False |
| validation_result['issues'].append("Password must contain at least one number") |
| elif re.search(r'\d', password): |
| validation_result['score'] += 20 |
| |
| |
| if password_policy['require_special'] and not re.search(r'[!@#$%^&*(),.?":{}|<>]', password): |
| validation_result['valid'] = False |
| validation_result['issues'].append("Password must contain at least one special character") |
| elif re.search(r'[!@#$%^&*(),.?":{}|<>]', password): |
| validation_result['score'] += 20 |
| |
| |
| common_patterns = ['password', '123456', 'qwerty', 'admin', 'user'] |
| for pattern in common_patterns: |
| if pattern.lower() in password.lower(): |
| validation_result['valid'] = False |
| validation_result['issues'].append(f"Password contains common pattern: {pattern}") |
| break |
| |
| |
| if validation_result['score'] < 80: |
| validation_result['suggestions'].append("Consider using a longer password") |
| validation_result['suggestions'].append("Use a mix of different character types") |
| validation_result['suggestions'].append("Avoid common words and patterns") |
| |
| return validation_result |
| |
| except Exception as e: |
| logger.error(f"Error validating password: {e}") |
| return {'valid': False, 'error': str(e)} |
| |
| async def analyze_user_behavior(self, user_id: str, timeframe: str = '24h') -> Dict[str, Any]: |
| """Analyze user behavior for security threats""" |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "validate_password", locals()) |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |
| try: |
| |
| user_activities = await self._get_user_activities(user_id, timeframe) |
| |
| |
| behavior_metrics = { |
| 'login_frequency': self._calculate_login_frequency(user_activities), |
| 'access_patterns': self._analyze_access_patterns(user_activities), |
| 'data_access_volume': self._calculate_data_access_volume(user_activities), |
| 'unusual_activities': self._detect_unusual_activities(user_activities), |
| 'risk_score': 0.0, |
| 'anomalies': [] |
| } |
| |
| |
| if self.ai_service: |
| behavior_analysis = await self._ai_behavior_analysis(user_id, user_activities) |
| behavior_metrics['risk_score'] = behavior_analysis.get('risk_score', 0.0) |
| behavior_metrics['anomalies'] = behavior_analysis.get('anomalies', []) |
| |
| return behavior_metrics |
| |
| except Exception as e: |
| logger.error(f"Error analyzing user behavior: {e}") |
| return {'error': str(e)} |
| |
| |
| async def _pattern_based_detection(self, event_data: Dict[str, Any]) -> List[Dict[str, Any]]: |
| """Pattern-based threat detection""" |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "analyze_user_behavior", locals()) |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |
| threats = [] |
| |
| |
| for pattern_name, pattern_info in self.malicious_patterns.items(): |
| if self._matches_pattern(event_data, pattern_info): |
| threats.append({ |
| 'type': pattern_info['threat_type'], |
| 'severity': pattern_info['severity'], |
| 'confidence': pattern_info['confidence'], |
| 'description': f"Pattern match detected: {pattern_name}", |
| 'indicators': [pattern_name] |
| }) |
| |
| return threats |
| |
| async def _behavioral_anomaly_detection(self, event_data: Dict[str, Any]) -> List[Dict[str, Any]]: |
| """Behavioral anomaly detection""" |
| threats = [] |
| |
| user_id = event_data.get('user_id') |
| if not user_id: |
| return threats |
| |
| |
| baseline = self.anomaly_baselines.get(user_id, {}) |
| |
| |
| anomalies = self._detect_anomalies(event_data, baseline) |
| |
| for anomaly in anomalies: |
| threats.append({ |
| 'type': ThreatType.ANOMALOUS_BEHAVIOR.value, |
| 'severity': anomaly['severity'], |
| 'confidence': anomaly['confidence'], |
| 'description': anomaly['description'], |
| 'indicators': anomaly['indicators'] |
| }) |
| |
| return threats |
| |
| async def _ai_threat_detection(self, event_data: Dict[str, Any]) -> List[Dict[str, Any]]: |
| """AI-powered threat detection""" |
| threats = [] |
| |
| if not self.ai_service: |
| return threats |
| |
| |
| ai_request = AIRequest( |
| request_id=f"threat_ai_{int(time.time())}", |
| task_type=AITaskType.CONVERSATION_ANALYSIS, |
| model_type=AIModelType.GPT_4, |
| service_type=AIServiceType.OPENAI, |
| input_data=event_data, |
| context={ |
| 'task': 'threat_detection', |
| 'event_type': event_data.get('event_type'), |
| 'security_level': 'enterprise' |
| }, |
| platform='security' |
| ) |
| |
| ai_response = await self.ai_service.process_ai_request(ai_request) |
| if ai_response.ok and ai_response.confidence > 0.7: |
| |
| ai_threats = self._parse_ai_threat_results(ai_response.output_data) |
| threats.extend(ai_threats) |
| except Exception as e: |
| logger.error(f"Operation failed: {e}") |
| log_integration_complete(audit_ctx, error=e) |
| return {'ok': False, 'error': str(e)} |
| logger.error(f"Error in AI threat detection: {e}") |
| |
| return threats |
| |
| async def _mitigate_threat(self, threat: ThreatDetection): |
| """Mitigate detected threat""" |
| mitigation_actions = [] |
| |
| if threat.severity in ['critical', 'high'] and threat.source_ip: |
| await self._block_ip(threat.source_ip, duration=3600) |
| mitigation_actions.append(f"Blocked IP: {threat.source_ip}") |
| |
| if threat.threat_type == ThreatType.COMPROMISED_ACCOUNT and threat.session_id: |
| await self._terminate_session(threat.session_id) |
| mitigation_actions.append(f"Terminated session: {threat.session_id}") |
| |
| if threat.threat_type == ThreatType.INSIDER_THREAT and threat.user_id: |
| await self._lock_user_account(threat.user_id) |
| mitigation_actions.append(f"Locked user account: {threat.user_id}") |
| |
| threat.mitigated = True |
| threat.mitigation_actions = mitigation_actions |
| |
| self.security_metrics['threats_mitigated'] += 1 |
| |
| await self._log_security_audit( |
| event_type=AuditEventType.SECURITY_ALERT, |
| user_id='security_system', |
| resource='threat_mitigation', |
| action='mitigate', |
| result='success', |
| metadata={ |
| 'threat_id': threat.detection_id, |
| 'threat_type': threat.threat_type.value, |
| 'mitigation_actions': mitigation_actions |
| } |
| ) |
| except Exception as e: |
| logger.error(f"Operation failed: {e}") |
| log_integration_complete(audit_ctx, error=e) |
| return {'ok': False, 'error': str(e)} |
| logger.error(f"Error mitigating threat: {e}") |
| |
| |
| async def _get_compliance_data(self, standard: ComplianceStandard, period: str) -> Dict[str, Any]: |
| """Get compliance data for analysis""" |
| |
| return { |
| 'standard': standard.value, |
| 'period': period, |
| 'audit_logs': self.audit_logs[-100:], |
| 'security_policies': list(self.active_policies.values()), |
| 'threat_detections': self.threat_detections[-50], |
| 'user_activities': [] |
| } |
| |
| async def _ai_compliance_analysis(self, standard: ComplianceStandard, compliance_data: Dict[str, Any]) -> Dict[str, Any]: |
| """AI-powered compliance analysis""" |
| if not self.ai_service: |
| return { |
| 'findings': [], |
| 'recommendations': [], |
| 'score': 0.0 |
| } |
| |
| |
| ai_request = AIRequest( |
| request_id=f"compliance_ai_{int(time.time())}", |
| task_type=AITaskType.CONTENT_GENERATION, |
| model_type=AIModelType.GPT_4, |
| service_type=AIServiceType.OPENAI, |
| input_data=compliance_data, |
| context={ |
| 'task': 'compliance_analysis', |
| 'standard': standard.value, |
| 'requirements': self._get_compliance_requirements(standard) |
| }, |
| platform='compliance' |
| ) |
| |
| ai_response = await self.ai_service.process_ai_request(ai_request) |
| if ai_response.ok: |
| return self._parse_ai_compliance_results(ai_response.output_data, standard) |
| else: |
| return { |
| 'findings': [], |
| 'recommendations': [], |
| 'score': 0.0 |
| } |
| except Exception as e: |
| logger.error(f"Operation failed: {e}") |
| log_integration_complete(audit_ctx, error=e) |
| return {'ok': False, 'error': str(e)} |
| logger.error(f"Error in AI compliance analysis: {e}") |
| return { |
| 'findings': [], |
| 'recommendations': [], |
| 'score': 0.0 |
| } |
| |
| def _calculate_compliance_score(self, compliance_analysis: Dict[str, Any]) -> float: |
| """Calculate overall compliance score""" |
| findings = compliance_analysis.get('findings', []) |
| |
| score = 100.0 |
| |
| for finding in findings: |
| severity = finding.get('severity', 'medium') |
| if severity == 'critical': |
| score -= 20 |
| elif severity == 'high': |
| score -= 15 |
| elif severity == 'medium': |
| score -= 10 |
| elif severity == 'low': |
| score -= 5 |
| return max(0.0, score) |
| except Exception as e: |
| logger.error(f"Operation failed: {e}") |
| log_integration_complete(audit_ctx, error=e) |
| return {'ok': False, 'error': str(e)} |
| logger.error(f"Error calculating compliance score: {e}") |
| return 0.0 |
| |
| |
| def _generate_encryption_key(self) -> bytes: |
| """Generate encryption key""" |
| password = os.urandom(32) |
| salt = os.urandom(16) |
| kdf = PBKDF2HMAC( |
| algorithm=hashes.SHA256(), |
| length=32, |
| salt=salt, |
| iterations=100000, |
| ) |
| key = base64.urlsafe_b64encode(kdf.derive(password)) |
| return key |
| |
| def _load_malicious_patterns(self) -> Dict[str, Any]: |
| """Load malicious patterns for detection""" |
| |
| return { |
| 'sql_injection': { |
| 'threat_type': ThreatType.SQL_INJECTION.value, |
| 'severity': 'high', |
| 'confidence': 0.9, |
| 'patterns': [r"('|(.*--)|(;)|(\b(ALTER|CREATE|DELETE|DROP|EXEC(UTE)?|INSERT( +INTO)?|MERGE|SELECT|UPDATE)\b)"] |
| }, |
| 'xss': { |
| 'threat_type': ThreatType.XSS.value, |
| 'severity': 'medium', |
| 'confidence': 0.8, |
| 'patterns': [r"<script[^>]*>.*?</script>", r"javascript:", r"on\w+\s*="] |
| }, |
| 'path_traversal': { |
| 'threat_type': ThreatType.AUTH_BYPASS.value, |
| 'severity': 'high', |
| 'confidence': 0.85, |
| 'patterns': [r"\.\.[/\\]", r"%2e%2e[/%5c]", r"\.\./"] |
| } |
| } |
| |
| def _matches_pattern(self, event_data: Dict[str, Any], pattern_info: Dict[str, Any]) -> bool: |
| """Check if event data matches malicious pattern""" |
| for pattern in pattern_info.get('patterns', []): |
| |
| for field in ['content', 'user_input', 'url', 'headers']: |
| field_value = str(event_data.get(field, '')) |
| if re.search(pattern, field_value, re.IGNORECASE): |
| return True |
| return False |
| |
| async def _block_ip(self, ip_address: str, duration: int): |
| """Block IP address""" |
| self.blocked_ips[ip_address] = datetime.utcnow() + timedelta(seconds=duration) |
| |
| |
| await self._log_security_audit( |
| event_type=AuditEventType.SECURITY_ALERT, |
| user_id='security_system', |
| resource='ip_blocking', |
| action='block', |
| result='success', |
| metadata={'ip_address': ip_address, 'duration': duration} |
| ) |
| |
| async def _terminate_session(self, session_id: str): |
| """Terminate user session""" |
| if session_id in self.active_sessions: |
| del self.active_sessions[session_id] |
| |
| |
| await self._log_security_audit( |
| event_type=AuditEventType.SECURITY_ALERT, |
| user_id='security_system', |
| resource='session_termination', |
| action='terminate', |
| result='success', |
| metadata={'session_id': session_id} |
| ) |
| |
| async def _lock_user_account(self, user_id: str): |
| """Lock user account""" |
| |
| if user_id in self.user_security_contexts: |
| self.user_security_contexts[user_id]['locked'] = True |
| self.user_security_contexts[user_id]['locked_at'] = datetime.utcnow() |
| |
| |
| await self._log_security_audit( |
| event_type=AuditEventType.SECURITY_ALERT, |
| user_id='security_system', |
| resource='user_account', |
| action='lock', |
| result='success', |
| metadata={'user_id': user_id} |
| ) |
| |
| async def _log_security_audit(self, event_type: AuditEventType, user_id: str, |
| resource: str, action: str, result: str, |
| metadata: Dict[str, Any] = None): |
| """Log security audit event""" |
| audit_data = { |
| 'event_type': event_type.value, |
| 'user_id': user_id, |
| 'resource': resource, |
| 'action': action, |
| 'result': result, |
| 'ip_address': 'security_system', |
| 'user_agent': 'enterprise_security_service', |
| 'metadata': metadata or {} |
| } |
| |
| audit = await self.audit_event(audit_data) |
| return audit |
| |
| |
| async def _initialize_encryption(self): |
| """Initialize encryption system""" |
| logger.info("Initializing encryption system") |
| |
| self.encryption_config = { |
| "algorithm": "AES-256-GCM", |
| "key_rotation_days": 90, |
| "enabled": True |
| } |
| logger.info("Encryption system initialized successfully") |
| except Exception as e: |
| logger.error(f"Operation failed: {e}") |
| log_integration_complete(audit_ctx, error=e) |
| return {'ok': False, 'error': str(e)} |
| logger.error(f"Error initializing encryption system: {e}") |
|
|
| async def _load_security_policies(self): |
| """Load security policies""" |
| logger.info("Loading security policies") |
| |
| self.security_policies = { |
| "password_policy": { |
| "min_length": 12, |
| "require_uppercase": True, |
| "require_lowercase": True, |
| "require_numbers": True, |
| "require_special_chars": True |
| }, |
| "access_policy": { |
| "max_failed_attempts": 5, |
| "lockout_duration_minutes": 30, |
| "session_timeout_minutes": 60 |
| }, |
| "data_policy": { |
| "encryption_at_rest": True, |
| "encryption_in_transit": True, |
| "audit_data_access": True |
| } |
| } |
| logger.info("Security policies loaded successfully") |
| except Exception as e: |
| logger.error(f"Operation failed: {e}") |
| log_integration_complete(audit_ctx, error=e) |
| return {'ok': False, 'error': str(e)} |
| logger.error(f"Error loading security policies: {e}") |
|
|
| async def _initialize_threat_detection(self): |
| """Initialize threat detection system""" |
| logger.info("Initializing threat detection system") |
| |
| self.threat_detection_config = { |
| "ai_enabled": True, |
| "rule_based_detection": True, |
| "anomaly_detection": True, |
| "real_time_monitoring": True |
| } |
| logger.info("Threat detection system initialized successfully") |
| except Exception as e: |
| logger.error(f"Operation failed: {e}") |
| log_integration_complete(audit_ctx, error=e) |
| return {'ok': False, 'error': str(e)} |
| logger.error(f"Error initializing threat detection system: {e}") |
|
|
| async def _start_security_monitoring(self): |
| """Start security monitoring""" |
| logger.info("Starting security monitoring") |
| |
| self.monitoring_active = True |
| logger.info("Security monitoring started successfully") |
| except Exception as e: |
| logger.error(f"Operation failed: {e}") |
| log_integration_complete(audit_ctx, error=e) |
| return {'ok': False, 'error': str(e)} |
| logger.error(f"Error starting security monitoring: {e}") |
|
|
| async def _initialize_compliance_monitoring(self): |
| """Initialize compliance monitoring""" |
| logger.info("Initializing compliance monitoring") |
| |
| self.compliance_monitoring = { |
| "gdpr": {"enabled": True, "last_check": None}, |
| "hipaa": {"enabled": True, "last_check": None}, |
| "soc2": {"enabled": True, "last_check": None}, |
| "iso27001": {"enabled": True, "last_check": None} |
| } |
| logger.info("Compliance monitoring initialized successfully") |
| except Exception as e: |
| logger.error(f"Operation failed: {e}") |
| log_integration_complete(audit_ctx, error=e) |
| logger.error(f"Error initializing compliance monitoring: {e}") |
| |
| async def _validate_security_policy(self, policy: SecurityPolicy) -> Dict[str, Any]: |
| """Validate security policy""" |
| return {'valid': True, 'errors': []} |
| |
| async def _get_user_activities(self, user_id: str, timeframe: str) -> List[Dict[str, Any]]: |
| """Get user activities""" |
| return [] |
| |
| def _calculate_login_frequency(self, activities: List[Dict[str, Any]]) -> float: |
| """Calculate login frequency""" |
| return 0.0 |
| |
| def _analyze_access_patterns(self, activities: List[Dict[str, Any]]) -> Dict[str, Any]: |
| """Analyze access patterns""" |
| return {} |
| |
| def _calculate_data_access_volume(self, activities: List[Dict[str, Any]]) -> int: |
| """Calculate data access volume""" |
| return 0 |
| |
| def _detect_unusual_activities(self, activities: List[Dict[str, Any]]) -> List[Dict[str, Any]]: |
| """Detect unusual activities""" |
| return [] |
| |
| async def _ai_behavior_analysis(self, user_id: str, activities: List[Dict[str, Any]]) -> Dict[str, Any]: |
| """AI-powered behavior analysis""" |
| return {} |
| |
| def _detect_anomalies(self, event_data: Dict[str, Any], baseline: Dict[str, Any]) -> List[Dict[str, Any]]: |
| """Detect anomalies in event data""" |
| return [] |
| |
| def _parse_ai_threat_results(self, ai_output: str) -> List[Dict[str, Any]]: |
| """Parse AI threat detection results""" |
| return [] |
| |
| def _get_compliance_requirements(self, standard: ComplianceStandard) -> List[str]: |
| """Get compliance requirements for standard""" |
| requirements = { |
| ComplianceStandard.GDPR: ['data_protection', 'privacy', 'consent'], |
| ComplianceStandard.HIPAA: ['phi_protection', 'access_control', 'audit_trail'], |
| ComplianceStandard.SOC2: ['security', 'availability', 'confidentiality'], |
| ComplianceStandard.ISO27001: ['information_security', 'risk_management', 'continuous_improvement'] |
| } |
| return requirements.get(standard, []) |
| |
| def _parse_ai_compliance_results(self, ai_output: str, standard: ComplianceStandard) -> Dict[str, Any]: |
| """Parse AI compliance analysis results""" |
| return { |
| 'findings': [], |
| 'recommendations': [], |
| 'score': 0.0 |
| } |
| |
| def _check_compliance_for_event(self, audit_event: SecurityAudit): |
| """Check compliance for audit event""" |
| |
| compliance_issues = [] |
| |
| if audit_event.action == "data_access" and not audit_event.metadata.get("logged"): |
| compliance_issues.append({ |
| "standard": "SOC2", |
| "requirement": "audit_trail", |
| "issue": "Data access not properly logged" |
| }) |
| |
| if audit_event.action == "data_export" and not audit_event.metadata.get("encrypted"): |
| compliance_issues.append({ |
| "standard": "GDPR", |
| "requirement": "data_protection", |
| "issue": "Data export not encrypted" |
| }) |
| return compliance_issues |
| except Exception as e: |
| logger.error(f"Operation failed: {e}") |
| log_integration_complete(audit_ctx, error=e) |
| return {'ok': False, 'error': str(e)} |
| logger.error(f"Error checking compliance for event: {e}") |
| return [] |
| |
| async def get_service_info(self) -> Dict[str, Any]: |
| """Get enterprise security service information""" |
| return { |
| "name": "Enterprise Security Service", |
| "version": "6.0.0", |
| "description": "Advanced enterprise-grade security with AI-powered threat detection", |
| "features": [ |
| "multi_platform_integration", |
| "threat_detection", |
| "compliance_automation", |
| "ai_powered_security", |
| "advanced_encryption", |
| "audit_logging", |
| "access_control" |
| ], |
| "supported_platforms": ["slack", "teams", "google_chat", "discord"], |
| "security_level": "enterprise", |
| "status": "ACTIVE" |
| } |
| |
| async def get_security_metrics(self) -> Dict[str, Any]: |
| """Get security service metrics""" |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "get_service_info", locals()) |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |
| return { |
| "total_threats_detected": self.security_metrics['total_threats_detected'], |
| "threats_mitigated": self.security_metrics['threats_mitigated'], |
| "audit_events_logged": self.security_metrics['audit_events_logged'], |
| "compliance_checks_passed": self.security_metrics['compliance_checks_passed'], |
| "security_policies_enforced": self.security_metrics['security_policies_enforced'], |
| "false_positives": self.security_metrics['false_positives'], |
| "average_threat_detection_time": self.security_metrics['average_threat_detection_time'], |
| "active_policies": len(self.active_policies), |
| "blocked_ips": len(self.blocked_ips), |
| "active_sessions": len(self.active_sessions) |
| } |
| |
| async def close(self): |
| """Close enterprise security service""" |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "get_security_metrics", locals()) |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |
| |
| await self.http_session.close() |
| |
| logger.info("Enterprise Security Service closed") |
|
|
| |
| atom_enterprise_security_service = AtomEnterpriseSecurityService({ |
| 'database': None, |
| 'cache': None, |
| 'ai_service': ai_enhanced_service, |
| 'encryption_key': None, |
| 'session_timeout': 3600, |
| 'max_login_attempts': 5, |
| 'lockout_duration': 900, |
| 'password_policy': { |
| 'min_length': 12, |
| 'require_upper': True, |
| 'require_lower': True, |
| 'require_numbers': True, |
| 'require_special': True, |
| 'prevent_reuse': 5 |
| }, |
| 'geoip_database': 'GeoLite2-City.mmdb', |
| 'threat_intelligence_apis': [], |
| 'ai_threat_detection': True, |
| 'compliance_standards': [ |
| ComplianceStandard.GDPR, |
| ComplianceStandard.CCPA, |
| ComplianceStandard.SOC2, |
| ComplianceStandard.ISO27001 |
| ] |
| }) |
| |
| audit_ctx = log_integration_attempt("atom_enterprise_security", "close", locals()) |
| |
| if not await circuit_breaker.is_enabled("atom_enterprise_security"): |
| logger.warning(f"Circuit breaker is open for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Circuit breaker open")) |
| raise HTTPException( |
| status_code=503, |
| detail=f"Atom_enterprise_security integration temporarily disabled" |
| ) |
| |
| is_limited, remaining = await rate_limiter.is_rate_limited("atom_enterprise_security") |
| if is_limited: |
| logger.warning(f"Rate limit exceeded for atom_enterprise_security") |
| log_integration_complete(audit_ctx, error=Exception("Rate limit exceeded")) |
| raise HTTPException( |
| status_code=429, |
| detail=f"Rate limit exceeded for atom_enterprise_security" |
| ) |