1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2022 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\IdentityForgottenEvent; |
22
|
|
|
use Surfnet\Stepup\Projector\Projector; |
23
|
|
|
use Surfnet\Stepup\Identity\Event\IdentityCreatedEvent; |
24
|
|
|
use Surfnet\Stepup\Identity\Event\SecondFactorVettedEvent; |
25
|
|
|
use Surfnet\Stepup\Identity\Event\SecondFactorVettedWithoutTokenProofOfPossession; |
26
|
|
|
use Surfnet\Stepup\Identity\Value\IdentityId; |
27
|
|
|
use Surfnet\Stepup\Identity\Value\VettingType; |
28
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\IdentitySelfAssertedTokenOptions; |
29
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\IdentitySelfAssertedTokenOptionsRepository; |
30
|
|
|
|
31
|
|
|
class IdentitySelfAssertedTokenOptionsProjector extends Projector |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
public function __construct( |
34
|
|
|
private readonly IdentitySelfAssertedTokenOptionsRepository $repository, |
35
|
|
|
) { |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
|
|
|
|
39
|
|
|
* Identity is created, we also create a set of |
40
|
|
|
* IdentitySelfAssertedTokenOptions. |
41
|
|
|
*/ |
|
|
|
|
42
|
|
|
public function applyIdentityCreatedEvent(IdentityCreatedEvent $event): void |
43
|
|
|
{ |
44
|
|
|
$identitySelfAssertedTokenOptions = IdentitySelfAssertedTokenOptions::create( |
45
|
|
|
$event->identityId, |
46
|
|
|
false, |
47
|
|
|
false, |
48
|
|
|
); |
49
|
|
|
$this->repository->save($identitySelfAssertedTokenOptions); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function applySecondFactorVettedEvent(SecondFactorVettedEvent $event): void |
53
|
|
|
{ |
54
|
|
|
$this->determinePossessionOfToken($event->vettingType, $event->identityId); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function applySecondFactorVettedWithoutTokenProofOfPossession( |
58
|
|
|
SecondFactorVettedWithoutTokenProofOfPossession $event, |
59
|
|
|
): void { |
60
|
|
|
$this->determinePossessionOfToken($event->vettingType, $event->identityId); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private function determinePossessionOfToken(VettingType $vettingType, IdentityId $identityId): void |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$isSelfAssertedToken = $vettingType->type() === VettingType::TYPE_SELF_ASSERTED_REGISTRATION; |
66
|
|
|
$identitySelfAssertedTokenOptions = $this->repository->find($identityId); |
67
|
|
|
// Scenario 1: A new token is registered, we have no sat options yet, |
68
|
|
|
// create them. These are identities from the pre SAT era. |
69
|
|
|
if (!$identitySelfAssertedTokenOptions instanceof IdentitySelfAssertedTokenOptions) { |
70
|
|
|
$identitySelfAssertedTokenOptions = IdentitySelfAssertedTokenOptions::create( |
71
|
|
|
$identityId, |
72
|
|
|
true, |
73
|
|
|
$isSelfAssertedToken, |
74
|
|
|
); |
75
|
|
|
$this->repository->save($identitySelfAssertedTokenOptions); |
76
|
|
|
return; |
77
|
|
|
} |
78
|
|
|
// Scenario 2: handle vetting of an Identity with IdentitySelfAssertedTokenOptions |
79
|
|
|
if ($vettingType->type() === VettingType::TYPE_SELF_ASSERTED_REGISTRATION) { |
80
|
|
|
$identitySelfAssertedTokenOptions->possessedSelfAssertedToken = true; |
81
|
|
|
} |
82
|
|
|
$identitySelfAssertedTokenOptions->possessedToken = true; |
83
|
|
|
$this->repository->save($identitySelfAssertedTokenOptions); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void |
87
|
|
|
{ |
88
|
|
|
// do nothing, no sensitive data in this projection |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|