1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2020 SURFnet bv |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
|
|
|
|
18
|
|
|
|
19
|
|
|
namespace Surfnet\Stepup\Identity\Event; |
20
|
|
|
|
21
|
|
|
use Surfnet\Stepup\Identity\AuditLog\Metadata; |
22
|
|
|
use Surfnet\Stepup\Identity\Value\CommonName; |
23
|
|
|
use Surfnet\Stepup\Identity\Value\DocumentNumber; |
24
|
|
|
use Surfnet\Stepup\Identity\Value\Email; |
25
|
|
|
use Surfnet\Stepup\Identity\Value\IdentityId; |
26
|
|
|
use Surfnet\Stepup\Identity\Value\Institution; |
27
|
|
|
use Surfnet\Stepup\Identity\Value\Locale; |
|
|
|
|
28
|
|
|
use Surfnet\Stepup\Identity\Value\NameId; |
29
|
|
|
use Surfnet\Stepup\Identity\Value\SecondFactorId; |
30
|
|
|
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifier; |
31
|
|
|
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifierFactory; |
32
|
|
|
use Surfnet\Stepup\Identity\Value\UnknownVettingType; |
33
|
|
|
use Surfnet\Stepup\Identity\Value\VettingType; |
34
|
|
|
use Surfnet\StepupBundle\Value\SecondFactorType; |
35
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\Forgettable; |
36
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\RightToObtainDataInterface; |
37
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\SensitiveData\SensitiveData; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
41
|
|
|
*/ |
|
|
|
|
42
|
|
|
class SecondFactorVettedWithoutTokenProofOfPossession extends IdentityEvent implements |
43
|
|
|
Forgettable, |
44
|
|
|
RightToObtainDataInterface |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* @var string[] |
48
|
|
|
*/ |
49
|
|
|
private array $allowlist = [ |
50
|
|
|
'identity_id', |
51
|
|
|
'name_id', |
52
|
|
|
'identity_institution', |
53
|
|
|
'second_factor_id', |
54
|
|
|
'second_factor_type', |
55
|
|
|
'preferred_locale', |
56
|
|
|
'email', |
57
|
|
|
'common_name', |
58
|
|
|
'second_factor_identifier', |
59
|
|
|
'vetting_type', |
60
|
|
|
]; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var DocumentNumber |
64
|
|
|
*/ |
65
|
|
|
public DocumentNumber $documentNumber; |
66
|
|
|
|
67
|
|
|
/** |
|
|
|
|
68
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList) |
69
|
|
|
*/ |
70
|
|
|
public function __construct( |
71
|
|
|
IdentityId $identityId, |
72
|
|
|
public NameId $nameId, |
73
|
|
|
Institution $institution, |
74
|
|
|
public SecondFactorId $secondFactorId, |
75
|
|
|
public SecondFactorType $secondFactorType, |
76
|
|
|
public SecondFactorIdentifier $secondFactorIdentifier, |
77
|
|
|
public CommonName $commonName, |
78
|
|
|
public Email $email, |
79
|
|
|
/** |
80
|
|
|
* @var Locale Eg. "en_GB" |
81
|
|
|
*/ |
82
|
|
|
public Locale $preferredLocale, |
83
|
|
|
public ?VettingType $vettingType, |
84
|
|
|
) { |
85
|
|
|
parent::__construct($identityId, $institution); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function getAuditLogMetadata(): Metadata |
89
|
|
|
{ |
90
|
|
|
$metadata = new Metadata(); |
91
|
|
|
$metadata->identityId = $this->identityId; |
92
|
|
|
$metadata->identityInstitution = $this->identityInstitution; |
93
|
|
|
$metadata->secondFactorId = $this->secondFactorId; |
94
|
|
|
$metadata->secondFactorType = $this->secondFactorType; |
95
|
|
|
$metadata->secondFactorIdentifier = $this->secondFactorIdentifier; |
96
|
|
|
$metadata->vettingType = $this->vettingType; |
97
|
|
|
|
98
|
|
|
return $metadata; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public static function deserialize(array $data): self |
102
|
|
|
{ |
103
|
|
|
$secondFactorType = new SecondFactorType($data['second_factor_type']); |
104
|
|
|
return new self( |
105
|
|
|
new IdentityId($data['identity_id']), |
106
|
|
|
new NameId($data['name_id']), |
107
|
|
|
new Institution($data['identity_institution']), |
108
|
|
|
new SecondFactorId($data['second_factor_id']), |
109
|
|
|
$secondFactorType, |
110
|
|
|
SecondFactorIdentifierFactory::unknownForType($secondFactorType), |
111
|
|
|
CommonName::unknown(), |
112
|
|
|
Email::unknown(), |
113
|
|
|
new Locale($data['preferred_locale']), |
114
|
|
|
new UnknownVettingType(), |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* The data ending up in the event_stream, be careful not to include sensitive data here! |
120
|
|
|
* |
121
|
|
|
* @return array<string, mixed> |
122
|
|
|
*/ |
123
|
|
|
public function serialize(): array |
124
|
|
|
{ |
125
|
|
|
return [ |
126
|
|
|
'identity_id' => (string)$this->identityId, |
127
|
|
|
'name_id' => (string)$this->nameId, |
128
|
|
|
'identity_institution' => (string)$this->identityInstitution, |
129
|
|
|
'second_factor_id' => (string)$this->secondFactorId, |
130
|
|
|
'second_factor_type' => (string)$this->secondFactorType, |
131
|
|
|
'preferred_locale' => (string)$this->preferredLocale, |
132
|
|
|
]; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function getSensitiveData(): SensitiveData |
136
|
|
|
{ |
137
|
|
|
return (new SensitiveData) |
138
|
|
|
->withCommonName($this->commonName) |
139
|
|
|
->withEmail($this->email) |
140
|
|
|
->withSecondFactorIdentifier($this->secondFactorIdentifier, $this->secondFactorType) |
141
|
|
|
->withVettingType($this->vettingType); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function setSensitiveData(SensitiveData $sensitiveData): void |
145
|
|
|
{ |
146
|
|
|
$this->email = $sensitiveData->getEmail(); |
147
|
|
|
$this->commonName = $sensitiveData->getCommonName(); |
148
|
|
|
$this->secondFactorIdentifier = $sensitiveData->getSecondFactorIdentifier(); |
149
|
|
|
$this->vettingType = $sensitiveData->getVettingType(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function obtainUserData(): array |
153
|
|
|
{ |
154
|
|
|
$serializedPublicUserData = $this->serialize(); |
155
|
|
|
$serializedSensitiveUserData = $this->getSensitiveData()->serialize(); |
156
|
|
|
return array_merge($serializedPublicUserData, $serializedSensitiveUserData); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return string[] |
161
|
|
|
*/ |
162
|
|
|
public function getAllowlist(): array |
163
|
|
|
{ |
164
|
|
|
return $this->allowlist; |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|