Spaces:
Sleeping
Sleeping
File size: 1,957 Bytes
990c0e8 | 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 | import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
ManyToOne,
JoinColumn,
} from 'typeorm';
import { User } from '../../auth/entities/user.entity';
export enum SecurityEventType {
LOGIN = 'login',
LOGOUT = 'logout',
FAILED_LOGIN = 'failed_login',
PASSWORD_CHANGE = 'password_change',
PERMISSION_CHANGE = 'permission_change',
SUSPICIOUS_ACTIVITY = 'suspicious_activity',
LOGIN_SUCCESS = 'login_success',
LOGIN_FAILURE = 'login_failure',
ROLE_CHANGE = 'role_change',
ACCOUNT_LOCKED = 'account_locked',
IP_BLOCKED = 'ip_blocked',
SESSION_HIJACK = 'session_hijack',
BRUTE_FORCE = 'brute_force',
}
export enum SecuritySeverity {
LOW = 'low',
MEDIUM = 'medium',
HIGH = 'high',
CRITICAL = 'critical',
}
@Entity('security_logs')
export class SecurityLog {
@PrimaryGeneratedColumn({ name: 'log_id', type: 'bigint', unsigned: true })
logId: number;
@Column({ name: 'user_id', type: 'bigint', unsigned: true, nullable: true })
userId: number;
@Column({
name: 'event_type',
type: 'enum',
enum: SecurityEventType,
})
eventType: SecurityEventType;
@Column({
name: 'severity',
type: 'enum',
enum: SecuritySeverity,
default: SecuritySeverity.MEDIUM,
})
severity: SecuritySeverity;
@Column({ name: 'ip_address', type: 'varchar', length: 45, nullable: true })
ipAddress: string;
@Column({ name: 'location', type: 'varchar', length: 255, nullable: true })
location: string;
@Column({ name: 'user_agent', type: 'text', nullable: true })
userAgent: string;
@Column({ name: 'details', type: 'text', nullable: true })
details: string;
@Column({ name: 'metadata', type: 'json', nullable: true })
metadata: any;
@Column({ name: 'is_resolved', type: 'tinyint', default: 0 })
isResolved: boolean;
@CreateDateColumn({ name: 'created_at' })
createdAt: Date;
@ManyToOne(() => User)
@JoinColumn({ name: 'user_id' })
user: User;
}
|