1- <?php namespace App \libs \Auth \Models ;
1+ <?php
2+ namespace App \libs \Auth \Models ;
23/**
34 * Copyright 2026 OpenStack Foundation
45 * Licensed under the Apache License, Version 2.0 (the "License");
1314 **/
1415
1516use Auth \User ;
16- use Doctrine \ORM \Mapping AS ORM ;
17+ use Doctrine \ORM \Mapping as ORM ;
1718
1819#[ORM \Table(name: 'two_factor_audit_log ' )]
1920#[ORM \Entity(repositoryClass: \App \Repositories \DoctrineTwoFactorAuditLogRepository::class)]
2021class TwoFactorAuditLog
2122{
22- public const EventChallengeIssued = 'challenge_issued ' ;
23- public const EventChallengeSucceeded = 'challenge_succeeded ' ;
24- public const EventChallengeFailed = 'challenge_failed ' ;
25- public const EventEnrollmentChanged = 'enrollment_changed ' ;
26- public const EventDeviceTrusted = 'device_trusted ' ;
27- public const EventDeviceRevoked = 'device_revoked ' ;
28- public const EventRecoveryUsed = 'recovery_used ' ;
29- public const EventSettingsChanged = 'settings_changed ' ;
30-
31- public const MethodEmailOtp = 'email_otp ' ;
32- public const MethodSmsOtp = 'sms_otp ' ;
33- public const MethodTotp = 'totp ' ;
34- public const MethodPasskey = 'passkey ' ;
35- public const MethodRecovery = 'recovery ' ;
23+ public const EventChallengeIssued = 'challenge_issued ' ;
24+ public const EventChallengeSucceeded = 'challenge_succeeded ' ;
25+ public const EventChallengeFailed = 'challenge_failed ' ;
26+ public const EventEnrollmentChanged = 'enrollment_changed ' ;
27+ public const EventDeviceTrusted = 'device_trusted ' ;
28+ public const EventDeviceRevoked = 'device_revoked ' ;
29+ public const EventRecoveryUsed = 'recovery_used ' ;
30+ public const EventSettingsChanged = 'settings_changed ' ;
31+
32+ public const MethodEmailOtp = 'email_otp ' ;
33+ public const MethodSmsOtp = 'sms_otp ' ;
34+ public const MethodTotp = 'totp ' ;
35+ public const MethodPasskey = 'passkey ' ;
36+ public const MethodRecovery = 'recovery ' ;
37+
38+
39+ private const ALLOWED_EVENT_TYPES = [
40+ self ::EventChallengeIssued,
41+ self ::EventChallengeSucceeded,
42+ self ::EventChallengeFailed,
43+ self ::EventEnrollmentChanged,
44+ self ::EventDeviceTrusted,
45+ self ::EventDeviceRevoked,
46+ self ::EventRecoveryUsed,
47+ self ::EventSettingsChanged,
48+ ];
49+
50+ private const ALLOWED_METHODS = [
51+ self ::MethodEmailOtp,
52+ self ::MethodSmsOtp,
53+ self ::MethodTotp,
54+ self ::MethodPasskey,
55+ self ::MethodRecovery,
56+ ];
3657
3758 #[ORM \Id]
3859 #[ORM \GeneratedValue]
@@ -67,25 +88,73 @@ public function __construct()
6788 $ this ->metadata = null ;
6889 }
6990
70- public function getId (): int { return (int ) $ this ->id ; }
91+ public function getId (): int
92+ {
93+ return (int ) $ this ->id ;
94+ }
7195
72- public function getUser (): User { return $ this ->user ; }
73- public function setUser (User $ user ): void { $ this ->user = $ user ; }
96+ public function getUser (): User
97+ {
98+ return $ this ->user ;
99+ }
100+ public function setUser (User $ user ): void
101+ {
102+ $ this ->user = $ user ;
103+ }
74104
75- public function getEventType (): string { return $ this ->event_type ; }
76- public function setEventType (string $ value ): void { $ this ->event_type = $ value ; }
105+ public function getEventType (): string
106+ {
107+ return $ this ->event_type ;
108+ }
109+ public function setEventType (string $ value ): void
110+ {
111+ if (!in_array ($ value , self ::ALLOWED_EVENT_TYPES , true )) {
112+ throw new \InvalidArgumentException ('Unsupported 2FA audit event type. ' );
113+ }
114+ $ this ->event_type = $ value ;
115+ }
77116
78- public function getMethod (): string { return $ this ->method ; }
79- public function setMethod (string $ value ): void { $ this ->method = $ value ; }
117+ public function getMethod (): string
118+ {
119+ return $ this ->method ;
120+ }
121+ public function setMethod (string $ value ): void
122+ {
123+ if (!in_array ($ value , self ::ALLOWED_METHODS , true )) {
124+ throw new \InvalidArgumentException ('Unsupported 2FA audit method. ' );
125+ }
126+ $ this ->method = $ value ;
127+ }
80128
81- public function getIpAddress (): string { return $ this ->ip_address ; }
82- public function setIpAddress (string $ value ): void { $ this ->ip_address = $ value ; }
129+ public function getIpAddress (): string
130+ {
131+ return $ this ->ip_address ;
132+ }
133+ public function setIpAddress (string $ value ): void
134+ {
135+ $ this ->ip_address = $ value ;
136+ }
83137
84- public function getUserAgent (): string { return $ this ->user_agent ; }
85- public function setUserAgent (string $ value ): void { $ this ->user_agent = $ value ; }
138+ public function getUserAgent (): string
139+ {
140+ return $ this ->user_agent ;
141+ }
142+ public function setUserAgent (string $ value ): void
143+ {
144+ $ this ->user_agent = $ value ;
145+ }
86146
87- public function getMetadata (): ?array { return $ this ->metadata ; }
88- public function setMetadata (?array $ value ): void { $ this ->metadata = $ value ; }
147+ public function getMetadata (): ?array
148+ {
149+ return $ this ->metadata ;
150+ }
151+ public function setMetadata (?array $ value ): void
152+ {
153+ $ this ->metadata = $ value ;
154+ }
89155
90- public function getCreatedAt (): \DateTime { return $ this ->created_at ; }
91- }
156+ public function getCreatedAt (): \DateTime
157+ {
158+ return $ this ->created_at ;
159+ }
160+ }
0 commit comments