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