|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2014 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\StepupMiddleware\CommandHandlingBundle\Identity\CommandHandler; |
|
20
|
|
|
|
|
21
|
|
|
use Broadway\CommandHandling\CommandHandler; |
|
22
|
|
|
use Broadway\Repository\AggregateNotFoundException; |
|
23
|
|
|
use Broadway\Repository\RepositoryInterface; |
|
24
|
|
|
use Surfnet\Stepup\Configuration\EventSourcing\InstitutionConfigurationRepository; |
|
25
|
|
|
use Surfnet\Stepup\Configuration\InstitutionConfiguration; |
|
26
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution as ConfigurationInstitution; |
|
27
|
|
|
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId; |
|
28
|
|
|
use Surfnet\Stepup\Identity\Api\Identity as IdentityApi; |
|
29
|
|
|
use Surfnet\Stepup\Identity\Entity\ConfigurableSettings; |
|
30
|
|
|
use Surfnet\Stepup\Identity\Identity; |
|
31
|
|
|
use Surfnet\Stepup\Identity\Value\CommonName; |
|
32
|
|
|
use Surfnet\Stepup\Identity\Value\DocumentNumber; |
|
33
|
|
|
use Surfnet\Stepup\Identity\Value\Email; |
|
34
|
|
|
use Surfnet\Stepup\Identity\Value\GssfId; |
|
35
|
|
|
use Surfnet\Stepup\Identity\Value\IdentityId; |
|
36
|
|
|
use Surfnet\Stepup\Identity\Value\Institution; |
|
37
|
|
|
use Surfnet\Stepup\Identity\Value\Locale; |
|
38
|
|
|
use Surfnet\Stepup\Identity\Value\NameId; |
|
39
|
|
|
use Surfnet\Stepup\Identity\Value\PhoneNumber; |
|
40
|
|
|
use Surfnet\Stepup\Identity\Value\SecondFactorId; |
|
41
|
|
|
use Surfnet\Stepup\Identity\Value\SecondFactorIdentifierFactory; |
|
42
|
|
|
use Surfnet\Stepup\Identity\Value\StepupProvider; |
|
43
|
|
|
use Surfnet\Stepup\Identity\Value\U2fKeyHandle; |
|
44
|
|
|
use Surfnet\Stepup\Identity\Value\YubikeyPublicId; |
|
45
|
|
|
use Surfnet\StepupBundle\Service\SecondFactorTypeService; |
|
46
|
|
|
use Surfnet\StepupBundle\Value\SecondFactorType; |
|
47
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\AllowedSecondFactorListService; |
|
48
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\InstitutionConfigurationOptionsService; |
|
49
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\IdentityRepository; |
|
50
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Exception\SecondFactorNotAllowedException; |
|
51
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Exception\UnsupportedLocaleException; |
|
52
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\BootstrapIdentityWithYubikeySecondFactorCommand; |
|
53
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\CreateIdentityCommand; |
|
54
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\ExpressLocalePreferenceCommand; |
|
55
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\ProveGssfPossessionCommand; |
|
56
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\ProvePhonePossessionCommand; |
|
57
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\ProveU2fDevicePossessionCommand; |
|
58
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\ProveYubikeyPossessionCommand; |
|
59
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\RemoteVetSecondFactorCommand; |
|
60
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\RevokeOwnSecondFactorCommand; |
|
61
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\RevokeRegistrantsSecondFactorCommand; |
|
62
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\UpdateIdentityCommand; |
|
63
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\VerifyEmailCommand; |
|
64
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\VetSecondFactorCommand; |
|
65
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\CommandHandler\Exception\DuplicateIdentityException; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
|
69
|
|
|
* @SuppressWarnings(PHPMD.TooManyMethods) |
|
70
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) |
|
71
|
|
|
*/ |
|
72
|
|
|
class IdentityCommandHandler extends CommandHandler |
|
73
|
|
|
{ |
|
74
|
|
|
/** |
|
75
|
|
|
* @var \Surfnet\Stepup\Identity\EventSourcing\IdentityRepository |
|
76
|
|
|
*/ |
|
77
|
|
|
private $eventSourcedRepository; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @var IdentityRepository |
|
81
|
|
|
*/ |
|
82
|
|
|
private $identityProjectionRepository; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @var \Surfnet\Stepup\Identity\Entity\ConfigurableSettings |
|
86
|
|
|
*/ |
|
87
|
|
|
private $configurableSettings; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @var AllowedSecondFactorListService |
|
91
|
|
|
*/ |
|
92
|
|
|
private $allowedSecondFactorListService; |
|
93
|
|
|
|
|
94
|
|
|
/** @var SecondFactorTypeService */ |
|
95
|
|
|
private $secondFactorTypeService; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @var InstitutionConfigurationOptionsService |
|
99
|
|
|
*/ |
|
100
|
|
|
private $institutionConfigurationOptionsService; |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @var InstitutionConfigurationRepository |
|
104
|
|
|
*/ |
|
105
|
|
|
private $institutionConfigurationRepository; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param RepositoryInterface $eventSourcedRepository |
|
109
|
|
|
* @param IdentityRepository $identityProjectionRepository |
|
110
|
|
|
* @param ConfigurableSettings $configurableSettings |
|
111
|
|
|
* @param AllowedSecondFactorListService $allowedSecondFactorListService |
|
112
|
|
|
* @param SecondFactorTypeService $secondFactorTypeService |
|
113
|
|
|
* @param InstitutionConfigurationOptionsService $institutionConfigurationOptionsService |
|
114
|
|
|
* @param InstitutionConfigurationRepository $institutionConfigurationRepository |
|
115
|
|
|
*/ |
|
116
|
|
|
public function __construct( |
|
117
|
|
|
RepositoryInterface $eventSourcedRepository, |
|
118
|
|
|
IdentityRepository $identityProjectionRepository, |
|
119
|
|
|
ConfigurableSettings $configurableSettings, |
|
120
|
|
|
AllowedSecondFactorListService $allowedSecondFactorListService, |
|
121
|
|
|
SecondFactorTypeService $secondFactorTypeService, |
|
122
|
|
|
InstitutionConfigurationOptionsService $institutionConfigurationOptionsService, |
|
123
|
|
|
InstitutionConfigurationRepository $institutionConfigurationRepository |
|
124
|
|
|
) { |
|
125
|
|
|
$this->eventSourcedRepository = $eventSourcedRepository; |
|
|
|
|
|
|
126
|
|
|
$this->identityProjectionRepository = $identityProjectionRepository; |
|
127
|
|
|
$this->configurableSettings = $configurableSettings; |
|
128
|
|
|
$this->allowedSecondFactorListService = $allowedSecondFactorListService; |
|
129
|
|
|
$this->secondFactorTypeService = $secondFactorTypeService; |
|
130
|
|
|
$this->institutionConfigurationOptionsService = $institutionConfigurationOptionsService; |
|
131
|
|
|
$this->institutionConfigurationRepository = $institutionConfigurationRepository; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function handleCreateIdentityCommand(CreateIdentityCommand $command) |
|
135
|
|
|
{ |
|
136
|
|
|
$preferredLocale = new Locale($command->preferredLocale); |
|
137
|
|
|
$this->assertIsValidLocale($preferredLocale); |
|
138
|
|
|
|
|
139
|
|
|
$institution = new Institution($command->institution); |
|
140
|
|
|
|
|
141
|
|
|
$institutionConfiguration = $this->loadInstitutionConfigurationFor($institution); |
|
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
$identity = Identity::create( |
|
144
|
|
|
new IdentityId($command->id), |
|
145
|
|
|
new Institution($command->institution), |
|
146
|
|
|
new NameId($command->nameId), |
|
147
|
|
|
new CommonName($command->commonName), |
|
148
|
|
|
new Email($command->email), |
|
149
|
|
|
$preferredLocale, |
|
150
|
|
|
$institutionConfiguration |
|
|
|
|
|
|
151
|
|
|
); |
|
152
|
|
|
|
|
153
|
|
|
$this->eventSourcedRepository->save($identity); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function handleUpdateIdentityCommand(UpdateIdentityCommand $command) |
|
157
|
|
|
{ |
|
158
|
|
|
/** @var IdentityApi $identity */ |
|
159
|
|
|
$identity = $this->eventSourcedRepository->load(new IdentityId($command->id)); |
|
160
|
|
|
|
|
161
|
|
|
$identity->rename(new CommonName($command->commonName)); |
|
162
|
|
|
$identity->changeEmail(new Email($command->email)); |
|
163
|
|
|
|
|
164
|
|
|
$this->eventSourcedRepository->save($identity); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function handleBootstrapIdentityWithYubikeySecondFactorCommand( |
|
168
|
|
|
BootstrapIdentityWithYubikeySecondFactorCommand $command |
|
169
|
|
|
) { |
|
170
|
|
|
$preferredLocale = new Locale($command->preferredLocale); |
|
171
|
|
|
$this->assertIsValidLocale($preferredLocale); |
|
172
|
|
|
|
|
173
|
|
|
$institution = new Institution($command->institution); |
|
174
|
|
|
$nameId = new NameId($command->nameId); |
|
175
|
|
|
|
|
176
|
|
|
if ($this->identityProjectionRepository->hasIdentityWithNameIdAndInstitution($nameId, $institution)) { |
|
177
|
|
|
throw DuplicateIdentityException::forBootstrappingWithYubikeySecondFactor($nameId, $institution); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
$institutionConfiguration = $this->loadInstitutionConfigurationFor($institution); |
|
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
$identity = Identity::create( |
|
183
|
|
|
new IdentityId($command->identityId), |
|
184
|
|
|
$institution, |
|
185
|
|
|
$nameId, |
|
186
|
|
|
new CommonName($command->commonName), |
|
187
|
|
|
new Email($command->email), |
|
188
|
|
|
$preferredLocale, |
|
189
|
|
|
$institutionConfiguration |
|
|
|
|
|
|
190
|
|
|
); |
|
191
|
|
|
|
|
192
|
|
|
$configurationInstitution = new ConfigurationInstitution( |
|
193
|
|
|
(string) $identity->getInstitution() |
|
194
|
|
|
); |
|
195
|
|
|
|
|
196
|
|
|
$tokenCount = $this->institutionConfigurationOptionsService->getMaxNumberOfTokensFor($configurationInstitution); |
|
197
|
|
|
$identity->setMaxNumberOfTokens($tokenCount); |
|
198
|
|
|
|
|
199
|
|
|
$identity->bootstrapYubikeySecondFactor( |
|
200
|
|
|
new SecondFactorId($command->secondFactorId), |
|
201
|
|
|
new YubikeyPublicId($command->yubikeyPublicId) |
|
202
|
|
|
); |
|
203
|
|
|
|
|
204
|
|
|
$this->eventSourcedRepository->save($identity); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
View Code Duplication |
public function handleProveYubikeyPossessionCommand(ProveYubikeyPossessionCommand $command) |
|
|
|
|
|
|
208
|
|
|
{ |
|
209
|
|
|
/** @var IdentityApi $identity */ |
|
210
|
|
|
$identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId)); |
|
211
|
|
|
|
|
212
|
|
|
$this->assertSecondFactorIsAllowedFor(new SecondFactorType('yubikey'), $identity->getInstitution()); |
|
213
|
|
|
|
|
214
|
|
|
$configurationInstitution = new ConfigurationInstitution( |
|
215
|
|
|
(string) $identity->getInstitution() |
|
216
|
|
|
); |
|
217
|
|
|
$tokenCount = $this->institutionConfigurationOptionsService->getMaxNumberOfTokensFor($configurationInstitution); |
|
218
|
|
|
$identity->setMaxNumberOfTokens($tokenCount); |
|
219
|
|
|
|
|
220
|
|
|
$identity->provePossessionOfYubikey( |
|
221
|
|
|
new SecondFactorId($command->secondFactorId), |
|
222
|
|
|
new YubikeyPublicId($command->yubikeyPublicId), |
|
223
|
|
|
$this->emailVerificationIsRequired($identity), |
|
224
|
|
|
$this->configurableSettings->createNewEmailVerificationWindow() |
|
225
|
|
|
); |
|
226
|
|
|
|
|
227
|
|
|
$this->eventSourcedRepository->save($identity); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* @param ProvePhonePossessionCommand $command |
|
232
|
|
|
*/ |
|
233
|
|
View Code Duplication |
public function handleProvePhonePossessionCommand(ProvePhonePossessionCommand $command) |
|
|
|
|
|
|
234
|
|
|
{ |
|
235
|
|
|
/** @var IdentityApi $identity */ |
|
236
|
|
|
$identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId)); |
|
237
|
|
|
|
|
238
|
|
|
$this->assertSecondFactorIsAllowedFor(new SecondFactorType('sms'), $identity->getInstitution()); |
|
239
|
|
|
|
|
240
|
|
|
$configurationInstitution = new ConfigurationInstitution( |
|
241
|
|
|
(string) $identity->getInstitution() |
|
242
|
|
|
); |
|
243
|
|
|
|
|
244
|
|
|
$tokenCount = $this->institutionConfigurationOptionsService->getMaxNumberOfTokensFor($configurationInstitution); |
|
245
|
|
|
$identity->setMaxNumberOfTokens($tokenCount); |
|
246
|
|
|
|
|
247
|
|
|
$identity->provePossessionOfPhone( |
|
248
|
|
|
new SecondFactorId($command->secondFactorId), |
|
249
|
|
|
new PhoneNumber($command->phoneNumber), |
|
250
|
|
|
$this->emailVerificationIsRequired($identity), |
|
251
|
|
|
$this->configurableSettings->createNewEmailVerificationWindow() |
|
252
|
|
|
); |
|
253
|
|
|
|
|
254
|
|
|
$this->eventSourcedRepository->save($identity); |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* @param ProveGssfPossessionCommand $command |
|
259
|
|
|
*/ |
|
260
|
|
|
public function handleProveGssfPossessionCommand(ProveGssfPossessionCommand $command) |
|
261
|
|
|
{ |
|
262
|
|
|
/** @var IdentityApi $identity */ |
|
263
|
|
|
$identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId)); |
|
264
|
|
|
$secondFactorType = $command->stepupProvider; |
|
265
|
|
|
|
|
266
|
|
|
// Validate that the chosen second factor type (stepupProvider) is allowed for the users instituti |
|
267
|
|
|
$this->assertSecondFactorIsAllowedFor(new SecondFactorType($secondFactorType), $identity->getInstitution()); |
|
268
|
|
|
|
|
269
|
|
|
$configurationInstitution = new ConfigurationInstitution( |
|
270
|
|
|
(string) $identity->getInstitution() |
|
271
|
|
|
); |
|
272
|
|
|
|
|
273
|
|
|
$tokenCount = $this->institutionConfigurationOptionsService->getMaxNumberOfTokensFor($configurationInstitution); |
|
274
|
|
|
$identity->setMaxNumberOfTokens($tokenCount); |
|
275
|
|
|
|
|
276
|
|
|
$identity->provePossessionOfGssf( |
|
277
|
|
|
new SecondFactorId($command->secondFactorId), |
|
278
|
|
|
new StepupProvider($secondFactorType), |
|
279
|
|
|
new GssfId($command->gssfId), |
|
280
|
|
|
$this->emailVerificationIsRequired($identity), |
|
281
|
|
|
$this->configurableSettings->createNewEmailVerificationWindow() |
|
282
|
|
|
); |
|
283
|
|
|
|
|
284
|
|
|
$this->eventSourcedRepository->save($identity); |
|
285
|
|
|
} |
|
286
|
|
|
|
|
287
|
|
View Code Duplication |
public function handleProveU2fDevicePossessionCommand(ProveU2fDevicePossessionCommand $command) |
|
|
|
|
|
|
288
|
|
|
{ |
|
289
|
|
|
/** @var IdentityApi $identity */ |
|
290
|
|
|
$identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId)); |
|
291
|
|
|
|
|
292
|
|
|
$this->assertSecondFactorIsAllowedFor(new SecondFactorType('u2f'), $identity->getInstitution()); |
|
293
|
|
|
|
|
294
|
|
|
$configurationInstitution = new ConfigurationInstitution( |
|
295
|
|
|
(string) $identity->getInstitution() |
|
296
|
|
|
); |
|
297
|
|
|
|
|
298
|
|
|
$tokenCount = $this->institutionConfigurationOptionsService->getMaxNumberOfTokensFor($configurationInstitution); |
|
299
|
|
|
$identity->setMaxNumberOfTokens($tokenCount); |
|
300
|
|
|
|
|
301
|
|
|
$identity->provePossessionOfU2fDevice( |
|
302
|
|
|
new SecondFactorId($command->secondFactorId), |
|
303
|
|
|
new U2fKeyHandle($command->keyHandle), |
|
304
|
|
|
$this->emailVerificationIsRequired($identity), |
|
305
|
|
|
$this->configurableSettings->createNewEmailVerificationWindow() |
|
306
|
|
|
); |
|
307
|
|
|
|
|
308
|
|
|
$this->eventSourcedRepository->save($identity); |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* @param VerifyEmailCommand $command |
|
313
|
|
|
*/ |
|
314
|
|
|
public function handleVerifyEmailCommand(VerifyEmailCommand $command) |
|
315
|
|
|
{ |
|
316
|
|
|
/** @var IdentityApi $identity */ |
|
317
|
|
|
$identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId)); |
|
318
|
|
|
|
|
319
|
|
|
$identity->verifyEmail($command->verificationNonce); |
|
320
|
|
|
|
|
321
|
|
|
$this->eventSourcedRepository->save($identity); |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
public function handleVetSecondFactorCommand(VetSecondFactorCommand $command) |
|
325
|
|
|
{ |
|
326
|
|
|
/** @var IdentityApi $authority */ |
|
327
|
|
|
$authority = $this->eventSourcedRepository->load(new IdentityId($command->authorityId)); |
|
328
|
|
|
/** @var IdentityApi $registrant */ |
|
329
|
|
|
$registrant = $this->eventSourcedRepository->load(new IdentityId($command->identityId)); |
|
330
|
|
|
|
|
331
|
|
|
$secondFactorType = new SecondFactorType($command->secondFactorType); |
|
332
|
|
|
$secondFactorIdentifier = SecondFactorIdentifierFactory::forType( |
|
333
|
|
|
$secondFactorType, |
|
334
|
|
|
$command->secondFactorIdentifier |
|
335
|
|
|
); |
|
336
|
|
|
|
|
337
|
|
|
$authority->vetSecondFactor( |
|
338
|
|
|
$registrant, |
|
339
|
|
|
new SecondFactorId($command->secondFactorId), |
|
340
|
|
|
$secondFactorType, |
|
341
|
|
|
$secondFactorIdentifier, |
|
342
|
|
|
$command->registrationCode, |
|
343
|
|
|
new DocumentNumber($command->documentNumber), |
|
344
|
|
|
$command->identityVerified, |
|
345
|
|
|
$this->secondFactorTypeService |
|
346
|
|
|
); |
|
347
|
|
|
|
|
348
|
|
|
$this->eventSourcedRepository->save($authority); |
|
349
|
|
|
$this->eventSourcedRepository->save($registrant); |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
public function handleRemoteVetSecondFactorCommand(RemoteVetSecondFactorCommand $command) |
|
353
|
|
|
{ |
|
354
|
|
|
/** @var IdentityApi $identity */ |
|
355
|
|
|
$identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId)); |
|
356
|
|
|
|
|
357
|
|
|
$identity->remoteVetSecondFactor( |
|
|
|
|
|
|
358
|
|
|
new SecondFactorId($command->secondFactorId) |
|
359
|
|
|
); |
|
360
|
|
|
|
|
361
|
|
|
$this->eventSourcedRepository->save($identity); |
|
362
|
|
|
} |
|
363
|
|
|
|
|
364
|
|
|
public function handleRevokeOwnSecondFactorCommand(RevokeOwnSecondFactorCommand $command) |
|
365
|
|
|
{ |
|
366
|
|
|
/** @var IdentityApi $identity */ |
|
367
|
|
|
$identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId)); |
|
368
|
|
|
$identity->revokeSecondFactor(new SecondFactorId($command->secondFactorId)); |
|
369
|
|
|
|
|
370
|
|
|
$this->eventSourcedRepository->save($identity); |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
public function handleRevokeRegistrantsSecondFactorCommand(RevokeRegistrantsSecondFactorCommand $command) |
|
374
|
|
|
{ |
|
375
|
|
|
/** @var IdentityApi $identity */ |
|
376
|
|
|
$identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId)); |
|
377
|
|
|
$identity->complyWithSecondFactorRevocation( |
|
378
|
|
|
new SecondFactorId($command->secondFactorId), |
|
379
|
|
|
new IdentityId($command->authorityId) |
|
380
|
|
|
); |
|
381
|
|
|
|
|
382
|
|
|
$this->eventSourcedRepository->save($identity); |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
|
public function handleExpressLocalePreferenceCommand(ExpressLocalePreferenceCommand $command) |
|
386
|
|
|
{ |
|
387
|
|
|
$preferredLocale = new Locale($command->preferredLocale); |
|
388
|
|
|
$this->assertIsValidLocale($preferredLocale); |
|
389
|
|
|
|
|
390
|
|
|
/** @var IdentityApi $identity */ |
|
391
|
|
|
$identity = $this->eventSourcedRepository->load(new IdentityId($command->identityId)); |
|
392
|
|
|
$identity->expressPreferredLocale($preferredLocale); |
|
393
|
|
|
|
|
394
|
|
|
$this->eventSourcedRepository->save($identity); |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
/** |
|
398
|
|
|
* @param Locale $locale |
|
399
|
|
|
*/ |
|
400
|
|
|
private function assertIsValidLocale(Locale $locale) |
|
401
|
|
|
{ |
|
402
|
|
|
if (!$this->configurableSettings->isSupportedLocale($locale)) { |
|
403
|
|
|
throw new UnsupportedLocaleException( |
|
404
|
|
|
sprintf('Given locale "%s" is not a supported locale', (string) $locale) |
|
405
|
|
|
); |
|
406
|
|
|
} |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
private function assertSecondFactorIsAllowedFor(SecondFactorType $secondFactor, Institution $institution) |
|
410
|
|
|
{ |
|
411
|
|
|
$allowedSecondFactorList = $this->allowedSecondFactorListService->getAllowedSecondFactorListFor( |
|
412
|
|
|
new ConfigurationInstitution($institution->getInstitution()) |
|
413
|
|
|
); |
|
414
|
|
|
|
|
415
|
|
|
if (!$allowedSecondFactorList->allows($secondFactor)) { |
|
416
|
|
|
throw new SecondFactorNotAllowedException(sprintf( |
|
417
|
|
|
'Institution "%s" does not support second factor "%s"', |
|
418
|
|
|
$institution->getInstitution(), |
|
419
|
|
|
$secondFactor->getSecondFactorType() |
|
420
|
|
|
)); |
|
421
|
|
|
} |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
/** |
|
425
|
|
|
* @param IdentityApi $identity |
|
426
|
|
|
* @return bool |
|
427
|
|
|
*/ |
|
428
|
|
|
private function emailVerificationIsRequired(IdentityApi $identity) |
|
429
|
|
|
{ |
|
430
|
|
|
$institution = new ConfigurationInstitution( |
|
431
|
|
|
(string) $identity->getInstitution() |
|
432
|
|
|
); |
|
433
|
|
|
|
|
434
|
|
|
$configuration = $this->institutionConfigurationOptionsService |
|
435
|
|
|
->findInstitutionConfigurationOptionsFor($institution); |
|
436
|
|
|
|
|
437
|
|
|
if ($configuration === null) { |
|
438
|
|
|
return true; |
|
439
|
|
|
} |
|
440
|
|
|
|
|
441
|
|
|
return $configuration->verifyEmailOption->isEnabled(); |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
/** |
|
445
|
|
|
* @deprecated Should be used until existing institution configurations have been migrated to using normalized ids |
|
446
|
|
|
* |
|
447
|
|
|
* @param Institution $institution |
|
448
|
|
|
* @return InstitutionConfiguration |
|
449
|
|
|
*/ |
|
450
|
|
View Code Duplication |
private function loadInstitutionConfigurationFor(Institution $institution) |
|
|
|
|
|
|
451
|
|
|
{ |
|
452
|
|
|
$institution = new ConfigurationInstitution($institution->getInstitution()); |
|
453
|
|
|
try { |
|
454
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::normalizedFrom($institution); |
|
455
|
|
|
$institutionConfiguration = $this->institutionConfigurationRepository->load( |
|
456
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
|
457
|
|
|
); |
|
458
|
|
|
} catch (AggregateNotFoundException $exception) { |
|
459
|
|
|
$institutionConfigurationId = InstitutionConfigurationId::from($institution); |
|
|
|
|
|
|
460
|
|
|
$institutionConfiguration = $this->institutionConfigurationRepository->load( |
|
461
|
|
|
$institutionConfigurationId->getInstitutionConfigurationId() |
|
462
|
|
|
); |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
return $institutionConfiguration; |
|
466
|
|
|
} |
|
467
|
|
|
} |
|
468
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.