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\ApiBundle\Identity\Projector; |
20
|
|
|
|
21
|
|
|
use Surfnet\Stepup\Projector\Projector; |
22
|
|
|
use Surfnet\Stepup\Identity\Event\IdentityCreatedEvent; |
23
|
|
|
use Surfnet\Stepup\Identity\Event\IdentityEmailChangedEvent; |
24
|
|
|
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent; |
25
|
|
|
use Surfnet\Stepup\Identity\Event\IdentityRenamedEvent; |
26
|
|
|
use Surfnet\Stepup\Identity\Event\LocalePreferenceExpressedEvent; |
27
|
|
|
use Surfnet\Stepup\Identity\Event\SecondFactorVettedEvent; |
28
|
|
|
use Surfnet\Stepup\Identity\Event\SecondFactorVettedWithoutTokenProofOfPossession; |
29
|
|
|
use Surfnet\Stepup\Identity\Value\VettingType; |
30
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\Identity; |
31
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\IdentityRepository; |
32
|
|
|
|
33
|
|
|
class IdentityProjector extends Projector |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
public function __construct( |
36
|
|
|
private readonly IdentityRepository $identityRepository, |
37
|
|
|
) { |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function applyIdentityCreatedEvent(IdentityCreatedEvent $event): void |
41
|
|
|
{ |
42
|
|
|
$this->identityRepository->save( |
43
|
|
|
Identity::create( |
44
|
|
|
(string)$event->identityId, |
45
|
|
|
$event->identityInstitution, |
46
|
|
|
$event->nameId, |
47
|
|
|
$event->email, |
48
|
|
|
$event->commonName, |
49
|
|
|
$event->preferredLocale, |
50
|
|
|
), |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function applyIdentityRenamedEvent(IdentityRenamedEvent $event): void |
55
|
|
|
{ |
56
|
|
|
$identity = $this->identityRepository->find((string)$event->identityId); |
57
|
|
|
$identity->commonName = $event->commonName; |
58
|
|
|
|
59
|
|
|
$this->identityRepository->save($identity); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function applyIdentityEmailChangedEvent(IdentityEmailChangedEvent $event): void |
63
|
|
|
{ |
64
|
|
|
$identity = $this->identityRepository->find((string)$event->identityId); |
65
|
|
|
$identity->email = $event->email; |
66
|
|
|
|
67
|
|
|
$this->identityRepository->save($identity); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function applyLocalePreferenceExpressedEvent(LocalePreferenceExpressedEvent $event): void |
71
|
|
|
{ |
72
|
|
|
$identity = $this->identityRepository->find((string)$event->identityId); |
73
|
|
|
$identity->preferredLocale = $event->preferredLocale; |
74
|
|
|
|
75
|
|
|
$this->identityRepository->save($identity); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function applySecondFactorVettedEvent(SecondFactorVettedEvent $event): void |
79
|
|
|
{ |
80
|
|
|
$this->determinePossessionOfSelfAssertedToken($event->vettingType, (string)$event->identityId); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function applySecondFactorVettedWithoutTokenProofOfPossession( |
84
|
|
|
SecondFactorVettedWithoutTokenProofOfPossession $event, |
85
|
|
|
): void { |
86
|
|
|
$this->determinePossessionOfSelfAssertedToken($event->vettingType, (string)$event->identityId); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
private function determinePossessionOfSelfAssertedToken(VettingType $vettingType, string $identityId): void |
|
|
|
|
90
|
|
|
{ |
91
|
|
|
if ($vettingType->type() === VettingType::TYPE_SELF_ASSERTED_REGISTRATION) { |
92
|
|
|
$identity = $this->identityRepository->find($identityId); |
93
|
|
|
if ($identity instanceof Identity) { |
94
|
|
|
$identity->possessedSelfAssertedToken = true; |
95
|
|
|
$this->identityRepository->save($identity); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void |
101
|
|
|
{ |
102
|
|
|
$this->identityRepository->updateStatusByIdentityIdToForgotten($event->identityId); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|