1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace Surfnet\Stepup\Identity\Event; |
4
|
|
|
|
5
|
|
|
use Surfnet\Stepup\Identity\AuditLog\Metadata; |
6
|
|
|
use Surfnet\Stepup\Identity\Value\CommonName; |
7
|
|
|
use Surfnet\Stepup\Identity\Value\Email; |
8
|
|
|
use Surfnet\Stepup\Identity\Value\IdentityId; |
9
|
|
|
use Surfnet\Stepup\Identity\Value\Institution; |
10
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable; |
11
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\RightToObtainDataInterface; |
12
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData; |
13
|
|
|
|
14
|
|
|
class IdentityRestoredEvent extends IdentityEvent implements Forgettable, RightToObtainDataInterface |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
private array $allowlist = [ |
17
|
|
|
'id', |
18
|
|
|
'common_name', |
19
|
|
|
'email', |
20
|
|
|
'institution', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
public function __construct( |
24
|
|
|
private readonly IdentityId $id, |
25
|
|
|
private readonly Institution $institution, |
26
|
|
|
public CommonName $commonName, |
27
|
|
|
public Email $email, |
28
|
|
|
) { |
29
|
|
|
parent::__construct($id, $institution); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function getAuditLogMetadata(): Metadata |
33
|
|
|
{ |
34
|
|
|
$metadata = new Metadata(); |
35
|
|
|
$metadata->identityId = $this->id; |
36
|
|
|
$metadata->identityInstitution = $this->institution; |
37
|
|
|
|
38
|
|
|
return $metadata; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public static function deserialize(array $data): self |
42
|
|
|
{ |
43
|
|
|
return new self( |
44
|
|
|
new IdentityId($data['id']), |
45
|
|
|
new Institution($data['institution']), |
46
|
|
|
new CommonName($data['common_name']), |
47
|
|
|
new Email($data['email']), |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function serialize(): array |
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
|
|
'id' => (string)$this->id, |
55
|
|
|
'institution' => (string)$this->institution, |
56
|
|
|
'common_name' => (string)$this->commonName, |
57
|
|
|
'email' => (string)$this->email, |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getSensitiveData(): SensitiveData |
62
|
|
|
{ |
63
|
|
|
return (new SensitiveData) |
64
|
|
|
->withCommonName($this->commonName) |
65
|
|
|
->withEmail($this->email); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function setSensitiveData(SensitiveData $sensitiveData): void |
69
|
|
|
{ |
70
|
|
|
$this->commonName = $sensitiveData->getCommonName(); |
71
|
|
|
$this->email = $sensitiveData->getEmail(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function obtainUserData(): array |
75
|
|
|
{ |
76
|
|
|
$serializedPublicUserData = $this->serialize(); |
77
|
|
|
$serializedSensitiveUserData = $this->getSensitiveData()->serialize(); |
78
|
|
|
return array_merge($serializedPublicUserData, $serializedSensitiveUserData); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getAllowlist(): array |
82
|
|
|
{ |
83
|
|
|
return $this->allowlist; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|