1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2016 SURFnet B.V. |
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\Configuration; |
20
|
|
|
|
21
|
|
|
use Broadway\EventSourcing\EventSourcedAggregateRoot; |
22
|
|
|
use Surfnet\Stepup\Configuration\Api\InstitutionConfiguration as InstitutionConfigurationInterface; |
23
|
|
|
use Surfnet\Stepup\Configuration\Entity\RaLocation; |
24
|
|
|
use Surfnet\Stepup\Configuration\Event\AllowedSecondFactorListUpdatedEvent; |
25
|
|
|
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent; |
26
|
|
|
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent; |
27
|
|
|
use Surfnet\Stepup\Configuration\Event\NumberOfTokensPerIdentityOptionChangedEvent; |
28
|
|
|
use Surfnet\Stepup\Configuration\Event\RaLocationAddedEvent; |
29
|
|
|
use Surfnet\Stepup\Configuration\Event\RaLocationContactInformationChangedEvent; |
30
|
|
|
use Surfnet\Stepup\Configuration\Event\RaLocationRelocatedEvent; |
31
|
|
|
use Surfnet\Stepup\Configuration\Event\RaLocationRemovedEvent; |
32
|
|
|
use Surfnet\Stepup\Configuration\Event\RaLocationRenamedEvent; |
33
|
|
|
use Surfnet\Stepup\Configuration\Event\SelectRaaOptionChangedEvent; |
34
|
|
|
use Surfnet\Stepup\Configuration\Event\ShowRaaContactInformationOptionChangedEvent; |
35
|
|
|
use Surfnet\Stepup\Configuration\Event\UseRaaOptionChangedEvent; |
36
|
|
|
use Surfnet\Stepup\Configuration\Event\UseRaLocationsOptionChangedEvent; |
37
|
|
|
use Surfnet\Stepup\Configuration\Event\UseRaOptionChangedEvent; |
38
|
|
|
use Surfnet\Stepup\Configuration\Event\VerifyEmailOptionChangedEvent; |
39
|
|
|
use Surfnet\Stepup\Configuration\Value\AllowedSecondFactorList; |
40
|
|
|
use Surfnet\Stepup\Configuration\Value\ContactInformation; |
41
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution; |
42
|
|
|
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId; |
43
|
|
|
use Surfnet\Stepup\Configuration\Value\InstitutionRole; |
44
|
|
|
use Surfnet\Stepup\Configuration\Value\Location; |
45
|
|
|
use Surfnet\Stepup\Configuration\Value\NumberOfTokensPerIdentityOption; |
46
|
|
|
use Surfnet\Stepup\Configuration\Value\RaLocationId; |
47
|
|
|
use Surfnet\Stepup\Configuration\Value\RaLocationList; |
48
|
|
|
use Surfnet\Stepup\Configuration\Value\RaLocationName; |
49
|
|
|
use Surfnet\Stepup\Configuration\Value\ShowRaaContactInformationOption; |
50
|
|
|
use Surfnet\Stepup\Configuration\Value\UseRaLocationsOption; |
51
|
|
|
use Surfnet\Stepup\Configuration\Value\InstitutionAuthorizationOption; |
52
|
|
|
use Surfnet\Stepup\Configuration\Value\VerifyEmailOption; |
53
|
|
|
use Surfnet\Stepup\Exception\DomainException; |
54
|
|
|
use Surfnet\Stepup\Identity\Value\RegistrationAuthorityRole; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* InstitutionConfiguration aggregate root |
58
|
|
|
* |
59
|
|
|
* Some things to know about this aggregate: |
60
|
|
|
* |
61
|
|
|
* 1. The aggregate is instantiated by InstitutionConfigurationCommandHandler by calling the |
62
|
|
|
* handleReconfigureInstitutionConfigurationOptionsCommand method. It does so, not by using the projections to build |
63
|
|
|
* the aggregate but by playing the events onto the aggregate. |
64
|
|
|
* 2. If one of the configuration options should be nullable, take a look at the applyUseRaOptionChangedEvent doc block |
65
|
|
|
* |
66
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) Events and value objects |
67
|
|
|
* @SuppressWarnings(PHPMD.TooManyMethods) AggregateRoot |
68
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods) AggregateRoot |
69
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity) AggregateRoot |
70
|
|
|
*/ |
71
|
|
|
class InstitutionConfiguration extends EventSourcedAggregateRoot implements InstitutionConfigurationInterface |
72
|
|
|
{ |
73
|
|
|
/** |
74
|
|
|
* @var InstitutionConfigurationId |
75
|
|
|
*/ |
76
|
|
|
private $institutionConfigurationId; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var Institution |
80
|
|
|
*/ |
81
|
|
|
private $institution; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var RaLocationList |
85
|
|
|
*/ |
86
|
|
|
private $raLocations; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @var UseRaLocationsOption |
90
|
|
|
*/ |
91
|
|
|
private $useRaLocationsOption; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var ShowRaaContactInformationOption |
95
|
|
|
*/ |
96
|
|
|
private $showRaaContactInformationOption; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @var VerifyEmailOption |
100
|
|
|
*/ |
101
|
|
|
private $verifyEmailOption; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @var NumberOfTokensPerIdentityOption |
105
|
|
|
*/ |
106
|
|
|
private $numberOfTokensPerIdentityOption; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @var InstitutionAuthorizationOption |
110
|
|
|
*/ |
111
|
|
|
private $useRaOption; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @var InstitutionAuthorizationOption |
115
|
|
|
*/ |
116
|
|
|
|
117
|
|
|
private $useRaaOption; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var InstitutionAuthorizationOption |
121
|
|
|
*/ |
122
|
|
|
private $selectRaaOption; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @var AllowedSecondFactorList |
126
|
|
|
*/ |
127
|
|
|
private $allowedSecondFactorList; |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @var boolean |
131
|
|
|
*/ |
132
|
|
|
private $isMarkedAsDestroyed; |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param InstitutionConfigurationId $institutionConfigurationId |
136
|
|
|
* @param Institution $institution |
137
|
|
|
* @return InstitutionConfiguration |
138
|
|
|
*/ |
139
|
|
|
public static function create(InstitutionConfigurationId $institutionConfigurationId, Institution $institution) |
140
|
|
|
{ |
141
|
|
|
$institutionConfiguration = new self; |
142
|
|
|
$institutionConfiguration->apply( |
143
|
|
|
new NewInstitutionConfigurationCreatedEvent( |
144
|
|
|
$institutionConfigurationId, |
145
|
|
|
$institution, |
146
|
|
|
UseRaLocationsOption::getDefault(), |
147
|
|
|
ShowRaaContactInformationOption::getDefault(), |
148
|
|
|
VerifyEmailOption::getDefault(), |
149
|
|
|
NumberOfTokensPerIdentityOption::getDefault() |
150
|
|
|
) |
151
|
|
|
); |
152
|
|
|
$institutionConfiguration->apply(new AllowedSecondFactorListUpdatedEvent( |
153
|
|
|
$institutionConfigurationId, |
154
|
|
|
$institution, |
155
|
|
|
AllowedSecondFactorList::blank() |
156
|
|
|
)); |
157
|
|
|
$institutionConfiguration->apply( |
158
|
|
|
new UseRaOptionChangedEvent( |
159
|
|
|
$institutionConfigurationId, |
160
|
|
|
$institution, |
161
|
|
|
InstitutionAuthorizationOption::getDefault(InstitutionRole::useRa()) |
162
|
|
|
) |
163
|
|
|
); |
164
|
|
|
$institutionConfiguration->apply( |
165
|
|
|
new UseRaaOptionChangedEvent( |
166
|
|
|
$institutionConfigurationId, |
167
|
|
|
$institution, |
168
|
|
|
InstitutionAuthorizationOption::getDefault(InstitutionRole::useRaa()) |
169
|
|
|
) |
170
|
|
|
); |
171
|
|
|
$institutionConfiguration->apply( |
172
|
|
|
new SelectRaaOptionChangedEvent( |
173
|
|
|
$institutionConfigurationId, |
174
|
|
|
$institution, |
175
|
|
|
InstitutionAuthorizationOption::getDefault(InstitutionRole::selectRaa()) |
176
|
|
|
) |
177
|
|
|
); |
178
|
|
|
|
179
|
|
|
return $institutionConfiguration; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @return InstitutionConfiguration |
184
|
|
|
*/ |
185
|
|
|
public function rebuild() |
186
|
|
|
{ |
187
|
|
|
// We can only rebuild a destroyed InstitutionConfiguration, all other cases are not valid |
188
|
|
|
if ($this->isMarkedAsDestroyed !== true) { |
189
|
|
|
throw new DomainException('Cannot rebuild InstitutionConfiguration as it has not been destroyed'); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
$this->apply( |
193
|
|
|
new NewInstitutionConfigurationCreatedEvent( |
194
|
|
|
$this->institutionConfigurationId, |
195
|
|
|
$this->institution, |
196
|
|
|
UseRaLocationsOption::getDefault(), |
197
|
|
|
ShowRaaContactInformationOption::getDefault(), |
198
|
|
|
VerifyEmailOption::getDefault(), |
199
|
|
|
NumberOfTokensPerIdentityOption::getDefault() |
200
|
|
|
) |
201
|
|
|
); |
202
|
|
|
$this->apply(new AllowedSecondFactorListUpdatedEvent( |
203
|
|
|
$this->institutionConfigurationId, |
204
|
|
|
$this->institution, |
205
|
|
|
AllowedSecondFactorList::blank() |
206
|
|
|
)); |
207
|
|
|
$this->apply( |
208
|
|
|
new UseRaOptionChangedEvent( |
209
|
|
|
$this->institutionConfigurationId, |
210
|
|
|
$this->institution, |
211
|
|
|
InstitutionAuthorizationOption::getDefault(InstitutionRole::useRa()) |
212
|
|
|
) |
213
|
|
|
); |
214
|
|
|
$this->apply( |
215
|
|
|
new UseRaaOptionChangedEvent( |
216
|
|
|
$this->institutionConfigurationId, |
217
|
|
|
$this->institution, |
218
|
|
|
InstitutionAuthorizationOption::getDefault(InstitutionRole::useRaa()) |
219
|
|
|
) |
220
|
|
|
); |
221
|
|
|
$this->apply( |
222
|
|
|
new SelectRaaOptionChangedEvent( |
223
|
|
|
$this->institutionConfigurationId, |
224
|
|
|
$this->institution, |
225
|
|
|
InstitutionAuthorizationOption::getDefault(InstitutionRole::selectRaa()) |
226
|
|
|
) |
227
|
|
|
); |
228
|
|
|
|
229
|
|
|
return $this; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
final public function __construct() |
233
|
|
|
{ |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
public function configureUseRaLocationsOption(UseRaLocationsOption $useRaLocationsOption) |
237
|
|
|
{ |
238
|
|
|
if ($this->useRaLocationsOption->equals($useRaLocationsOption)) { |
239
|
|
|
return; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
$this->apply( |
243
|
|
|
new UseRaLocationsOptionChangedEvent( |
244
|
|
|
$this->institutionConfigurationId, |
245
|
|
|
$this->institution, |
246
|
|
|
$useRaLocationsOption |
247
|
|
|
) |
248
|
|
|
); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
public function configureShowRaaContactInformationOption(ShowRaaContactInformationOption $showRaaContactInformationOption) |
252
|
|
|
{ |
253
|
|
|
if ($this->showRaaContactInformationOption->equals($showRaaContactInformationOption)) { |
254
|
|
|
return; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
$this->apply( |
258
|
|
|
new ShowRaaContactInformationOptionChangedEvent( |
259
|
|
|
$this->institutionConfigurationId, |
260
|
|
|
$this->institution, |
261
|
|
|
$showRaaContactInformationOption |
262
|
|
|
) |
263
|
|
|
); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
public function configureVerifyEmailOption(VerifyEmailOption $verifyEmailOption) |
267
|
|
|
{ |
268
|
|
|
if ($this->verifyEmailOption->equals($verifyEmailOption)) { |
269
|
|
|
return; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
$this->apply( |
273
|
|
|
new VerifyEmailOptionChangedEvent( |
274
|
|
|
$this->institutionConfigurationId, |
275
|
|
|
$this->institution, |
276
|
|
|
$verifyEmailOption |
277
|
|
|
) |
278
|
|
|
); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
public function configureNumberOfTokensPerIdentityOption( |
282
|
|
|
NumberOfTokensPerIdentityOption $numberOfTokensPerIdentityOption |
283
|
|
|
) { |
284
|
|
|
if ($this->numberOfTokensPerIdentityOption->equals($numberOfTokensPerIdentityOption)) { |
285
|
|
|
return; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
$this->apply( |
289
|
|
|
new NumberOfTokensPerIdentityOptionChangedEvent( |
290
|
|
|
$this->institutionConfigurationId, |
291
|
|
|
$this->institution, |
292
|
|
|
$numberOfTokensPerIdentityOption |
293
|
|
|
) |
294
|
|
|
); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
View Code Duplication |
public function updateUseRaOption(InstitutionAuthorizationOption $useRaOption) |
|
|
|
|
298
|
|
|
{ |
299
|
|
|
if ($this->useRaOption !== null |
300
|
|
|
&& $this->useRaOption->equals($useRaOption) |
301
|
|
|
) { |
302
|
|
|
return; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
$this->apply( |
306
|
|
|
new UseRaOptionChangedEvent( |
307
|
|
|
$this->institutionConfigurationId, |
308
|
|
|
$this->institution, |
309
|
|
|
$useRaOption |
310
|
|
|
) |
311
|
|
|
); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
View Code Duplication |
public function updateUseRaaOption(InstitutionAuthorizationOption $useRaaOption) |
|
|
|
|
315
|
|
|
{ |
316
|
|
|
if ($this->useRaaOption !== null |
317
|
|
|
&& $this->useRaaOption->equals($useRaaOption) |
318
|
|
|
) { |
319
|
|
|
return; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
$this->apply( |
323
|
|
|
new UseRaaOptionChangedEvent( |
324
|
|
|
$this->institutionConfigurationId, |
325
|
|
|
$this->institution, |
326
|
|
|
$useRaaOption |
327
|
|
|
) |
328
|
|
|
); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
View Code Duplication |
public function updateSelectRaaOption(InstitutionAuthorizationOption $selectRaaOption) |
|
|
|
|
332
|
|
|
{ |
333
|
|
|
if ($this->selectRaaOption !== null |
334
|
|
|
&& $this->selectRaaOption->equals($selectRaaOption) |
335
|
|
|
) { |
336
|
|
|
return; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
$this->apply( |
340
|
|
|
new SelectRaaOptionChangedEvent( |
341
|
|
|
$this->institutionConfigurationId, |
342
|
|
|
$this->institution, |
343
|
|
|
$selectRaaOption |
344
|
|
|
) |
345
|
|
|
); |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
public function updateAllowedSecondFactorList(AllowedSecondFactorList $allowedSecondFactorList) |
349
|
|
|
{ |
350
|
|
|
// AllowedSecondFactorList can be null for InstitutionConfigurations for which this functionality did not exist |
351
|
|
|
if ($this->allowedSecondFactorList !== null |
352
|
|
|
&& $this->allowedSecondFactorList->equals($allowedSecondFactorList) |
353
|
|
|
) { |
354
|
|
|
return; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
$this->apply( |
358
|
|
|
new AllowedSecondFactorListUpdatedEvent( |
359
|
|
|
$this->institutionConfigurationId, |
360
|
|
|
$this->institution, |
361
|
|
|
$allowedSecondFactorList |
362
|
|
|
) |
363
|
|
|
); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
/** |
367
|
|
|
* @param RaLocationId $raLocationId |
368
|
|
|
* @param RaLocationName $raLocationName |
369
|
|
|
* @param Location $location |
370
|
|
|
* @param ContactInformation $contactInformation |
371
|
|
|
*/ |
372
|
|
|
public function addRaLocation( |
373
|
|
|
RaLocationId $raLocationId, |
374
|
|
|
RaLocationName $raLocationName, |
375
|
|
|
Location $location, |
376
|
|
|
ContactInformation $contactInformation |
377
|
|
|
) { |
378
|
|
View Code Duplication |
if ($this->raLocations->containsWithId($raLocationId)) { |
|
|
|
|
379
|
|
|
throw new DomainException(sprintf( |
380
|
|
|
'Cannot add RaLocation with RaLocationId "%s" to RaLocations of InstitutionConfiguration "%s":' |
381
|
|
|
. ' it is already present', |
382
|
|
|
$raLocationId, |
383
|
|
|
$this->getAggregateRootId() |
384
|
|
|
)); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
$this->apply(new RaLocationAddedEvent( |
388
|
|
|
$this->institutionConfigurationId, |
389
|
|
|
$this->institution, |
390
|
|
|
$raLocationId, |
391
|
|
|
$raLocationName, |
392
|
|
|
$location, |
393
|
|
|
$contactInformation |
394
|
|
|
)); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @param RaLocationId $raLocationId |
399
|
|
|
* @param RaLocationName $raLocationName |
400
|
|
|
* @param Location $location |
401
|
|
|
* @param ContactInformation $contactInformation |
402
|
|
|
*/ |
403
|
|
|
public function changeRaLocation( |
404
|
|
|
RaLocationId $raLocationId, |
405
|
|
|
RaLocationName $raLocationName, |
406
|
|
|
Location $location, |
407
|
|
|
ContactInformation $contactInformation |
408
|
|
|
) { |
409
|
|
View Code Duplication |
if (!$this->raLocations->containsWithId($raLocationId)) { |
|
|
|
|
410
|
|
|
throw new DomainException(sprintf( |
411
|
|
|
'Cannot change RaLocation with RaLocationId "%s" in RaLocations of InstitutionConfiguration "%s":' |
412
|
|
|
. ' it is not present', |
413
|
|
|
$raLocationId, |
414
|
|
|
$this->getAggregateRootId() |
415
|
|
|
)); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
$raLocation = $this->raLocations->getById($raLocationId); |
419
|
|
|
|
420
|
|
|
if (!$raLocation->getName()->equals($raLocationName)) { |
421
|
|
|
$this->apply( |
422
|
|
|
new RaLocationRenamedEvent($this->institutionConfigurationId, $raLocationId, $raLocationName) |
423
|
|
|
); |
424
|
|
|
} |
425
|
|
|
if (!$raLocation->getLocation()->equals($location)) { |
426
|
|
|
$this->apply( |
427
|
|
|
new RaLocationRelocatedEvent($this->institutionConfigurationId, $raLocationId, $location) |
428
|
|
|
); |
429
|
|
|
} |
430
|
|
|
if (!$raLocation->getContactInformation()->equals($contactInformation)) { |
431
|
|
|
$this->apply( |
432
|
|
|
new RaLocationContactInformationChangedEvent( |
433
|
|
|
$this->institutionConfigurationId, |
434
|
|
|
$raLocationId, |
435
|
|
|
$contactInformation |
436
|
|
|
) |
437
|
|
|
); |
438
|
|
|
} |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
/** |
442
|
|
|
* @param RaLocationId $raLocationId |
443
|
|
|
*/ |
444
|
|
|
public function removeRaLocation(RaLocationId $raLocationId) |
445
|
|
|
{ |
446
|
|
View Code Duplication |
if (!$this->raLocations->containsWithId($raLocationId)) { |
|
|
|
|
447
|
|
|
throw new DomainException(sprintf( |
448
|
|
|
'Cannot remove RaLocation with RaLocationId "%s" in RaLocations of InstitutionConfiguration "%s":' |
449
|
|
|
. ' it is not present', |
450
|
|
|
$raLocationId, |
451
|
|
|
$this->getAggregateRootId() |
452
|
|
|
)); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
$this->apply(new RaLocationRemovedEvent($this->institutionConfigurationId, $raLocationId)); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* @return void |
460
|
|
|
*/ |
461
|
|
|
public function destroy() |
462
|
|
|
{ |
463
|
|
|
$this->apply(new InstitutionConfigurationRemovedEvent($this->institutionConfigurationId, $this->institution)); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
public function getAggregateRootId() |
467
|
|
|
{ |
468
|
|
|
return $this->institutionConfigurationId; |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* Check if role from institution is allowed to accredit roles |
473
|
|
|
* |
474
|
|
|
* @param Institution $institution |
475
|
|
|
* @return bool |
476
|
|
|
*/ |
477
|
|
|
public function isInstitutionAllowedToAccreditRoles(Institution $institution) |
478
|
|
|
{ |
479
|
|
|
// This method is needed to support the situation pre FGA. In that situation the SelectRaaOptionChanged wasn't |
480
|
|
|
// fired and that would result in a situation were $this->selectRaaOption is null. If that occurs we should check |
481
|
|
|
// if the institution of the identity is the institution to validate. |
482
|
|
|
if ($this->selectRaaOption == null) { |
483
|
|
|
return $this->institution->equals($institution); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
if ($this->selectRaaOption->hasInstitution($institution, $this->institution)) { |
|
|
|
|
487
|
|
|
return true; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
return false; |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
protected function applyNewInstitutionConfigurationCreatedEvent(NewInstitutionConfigurationCreatedEvent $event) |
494
|
|
|
{ |
495
|
|
|
$this->institutionConfigurationId = $event->institutionConfigurationId; |
496
|
|
|
$this->institution = $event->institution; |
497
|
|
|
$this->useRaLocationsOption = $event->useRaLocationsOption; |
498
|
|
|
$this->showRaaContactInformationOption = $event->showRaaContactInformationOption; |
499
|
|
|
$this->verifyEmailOption = $event->verifyEmailOption; |
500
|
|
|
$this->numberOfTokensPerIdentityOption = $event->numberOfTokensPerIdentityOption; |
501
|
|
|
$this->raLocations = new RaLocationList([]); |
502
|
|
|
$this->isMarkedAsDestroyed = false; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* Apply the UseRaOptionChangedEvent |
507
|
|
|
* |
508
|
|
|
* To ensure the aggregate is correctly populated with the FGA options we ensure the UseRaOptionChangedEvent |
509
|
|
|
* can be applied on the aggregate. Refraining from doing this would result in the $this->useRaOption field only |
510
|
|
|
* being applied when applyNewInstitutionConfigurationCreatedEvent is called. And this might not be the case if |
511
|
|
|
* the fields where null'ed (removed from configuration). |
512
|
|
|
* |
513
|
|
|
* This also applies for applyUseRaaOptionChangedEvent & applySelectRaaOptionChangedEvent |
514
|
|
|
* |
515
|
|
|
* @param UseRaOptionChangedEvent $event |
516
|
|
|
*/ |
517
|
|
|
protected function applyUseRaOptionChangedEvent(UseRaOptionChangedEvent $event) |
518
|
|
|
{ |
519
|
|
|
$this->useRaOption = $event->useRaOption; |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
protected function applyUseRaaOptionChangedEvent(UseRaaOptionChangedEvent $event) |
523
|
|
|
{ |
524
|
|
|
$this->useRaaOption = $event->useRaaOption; |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
protected function applySelectRaaOptionChangedEvent(SelectRaaOptionChangedEvent $event) |
528
|
|
|
{ |
529
|
|
|
$this->selectRaaOption = $event->selectRaaOption; |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
protected function applyUseRaLocationsOptionChangedEvent(UseRaLocationsOptionChangedEvent $event) |
533
|
|
|
{ |
534
|
|
|
$this->useRaLocationsOption = $event->useRaLocationsOption; |
535
|
|
|
} |
536
|
|
|
|
537
|
|
|
protected function applyShowRaaContactInformationOptionChangedEvent( |
538
|
|
|
ShowRaaContactInformationOptionChangedEvent $event |
539
|
|
|
) { |
540
|
|
|
$this->showRaaContactInformationOption = $event->showRaaContactInformationOption; |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
protected function applyVerifyEmailOptionChangedEvent( |
544
|
|
|
VerifyEmailOptionChangedEvent $event |
545
|
|
|
) { |
546
|
|
|
$this->verifyEmailOption = $event->verifyEmailOption; |
547
|
|
|
} |
548
|
|
|
|
549
|
|
|
protected function applyNumberOfTokensPerIdentityOptionChangedEvent( |
550
|
|
|
NumberOfTokensPerIdentityOptionChangedEvent $event |
551
|
|
|
) { |
552
|
|
|
$this->numberOfTokensPerIdentityOption = $event->numberOfTokensPerIdentityOption; |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
protected function applyAllowedSecondFactorListUpdatedEvent(AllowedSecondFactorListUpdatedEvent $event) |
556
|
|
|
{ |
557
|
|
|
$this->allowedSecondFactorList = $event->allowedSecondFactorList; |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
protected function applyRaLocationAddedEvent(RaLocationAddedEvent $event) |
561
|
|
|
{ |
562
|
|
|
$this->raLocations->add( |
563
|
|
|
RaLocation::create( |
564
|
|
|
$event->raLocationId, |
565
|
|
|
$event->raLocationName, |
566
|
|
|
$event->location, |
567
|
|
|
$event->contactInformation |
568
|
|
|
) |
569
|
|
|
); |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
protected function applyRaLocationRenamedEvent(RaLocationRenamedEvent $event) |
573
|
|
|
{ |
574
|
|
|
$raLocation = $this->raLocations->getById($event->raLocationId); |
575
|
|
|
$raLocation->rename($event->raLocationName); |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
protected function applyRaLocationRelocatedEvent(RaLocationRelocatedEvent $event) |
579
|
|
|
{ |
580
|
|
|
$raLocation = $this->raLocations->getById($event->raLocationId); |
581
|
|
|
$raLocation->relocate($event->location); |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
protected function applyRaLocationContactInformationChangedEvent(RaLocationContactInformationChangedEvent $event) |
585
|
|
|
{ |
586
|
|
|
$raLocation = $this->raLocations->getById($event->raLocationId); |
587
|
|
|
$raLocation->changeContactInformation($event->contactInformation); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
protected function applyRaLocationRemovedEvent(RaLocationRemovedEvent $event) |
591
|
|
|
{ |
592
|
|
|
$this->raLocations->removeWithId($event->raLocationId); |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
/** |
596
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
597
|
|
|
* @param InstitutionConfigurationRemovedEvent $event |
598
|
|
|
*/ |
599
|
|
|
protected function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurationRemovedEvent $event) |
|
|
|
|
600
|
|
|
{ |
601
|
|
|
// reset all configuration to defaults. This way, should it be rebuild, it seems like it is new again |
602
|
|
|
$this->raLocations = new RaLocationList([]); |
603
|
|
|
$this->useRaLocationsOption = UseRaLocationsOption::getDefault(); |
604
|
|
|
$this->showRaaContactInformationOption = ShowRaaContactInformationOption::getDefault(); |
605
|
|
|
$this->verifyEmailOption = VerifyEmailOption::getDefault(); |
606
|
|
|
$this->numberOfTokensPerIdentityOption = NumberOfTokensPerIdentityOption::getDefault(); |
607
|
|
|
$this->allowedSecondFactorList = AllowedSecondFactorList::blank(); |
608
|
|
|
$this->useRaOption = InstitutionAuthorizationOption::getDefault(InstitutionRole::useRa()); |
609
|
|
|
$this->useRaaOption = InstitutionAuthorizationOption::getDefault(InstitutionRole::useRaa()); |
610
|
|
|
$this->selectRaaOption = InstitutionAuthorizationOption::getDefault(InstitutionRole::selectRaa()); |
611
|
|
|
|
612
|
|
|
$this->isMarkedAsDestroyed = true; |
613
|
|
|
} |
614
|
|
|
} |
615
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.