1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2022 SURFnet bv |
7
|
|
|
* |
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
9
|
|
|
* you may not use this file except in compliance with the License. |
10
|
|
|
* You may obtain a copy of the License at |
11
|
|
|
* |
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
13
|
|
|
* |
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17
|
|
|
* See the License for the specific language governing permissions and |
18
|
|
|
* limitations under the License. |
19
|
|
|
*/ |
|
|
|
|
20
|
|
|
|
21
|
|
|
namespace Surfnet\StepupMiddleware\GatewayBundle\Projector; |
22
|
|
|
|
23
|
|
|
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent; |
24
|
|
|
use Surfnet\Stepup\Projector\Projector; |
25
|
|
|
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent; |
26
|
|
|
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent; |
27
|
|
|
use Surfnet\Stepup\Configuration\Event\SsoOn2faOptionChangedEvent; |
28
|
|
|
use Surfnet\StepupMiddleware\GatewayBundle\Entity\InstitutionConfiguration; |
29
|
|
|
use Surfnet\StepupMiddleware\GatewayBundle\Repository\InstitutionConfigurationRepository; |
30
|
|
|
|
31
|
|
|
class InstitutionConfigurationProjector extends Projector |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
public function __construct(private readonly InstitutionConfigurationRepository $repository) |
34
|
|
|
{ |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function applyNewInstitutionConfigurationCreatedEvent(NewInstitutionConfigurationCreatedEvent $event): void |
38
|
|
|
{ |
39
|
|
|
$institutionConfiguration = new InstitutionConfiguration( |
40
|
|
|
(string)$event->institution, |
41
|
|
|
$event->ssoOn2faOption->isEnabled(), |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$this->repository->save($institutionConfiguration); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function applySsoOn2faOptionChangedEvent(SsoOn2faOptionChangedEvent $event): void |
48
|
|
|
{ |
49
|
|
|
$institutionConfiguration = $this->repository->findByInstitution((string)$event->institution); |
50
|
|
|
if ($institutionConfiguration instanceof InstitutionConfiguration) { |
51
|
|
|
$institutionConfiguration->ssoOn2faEnabled = $event->ssoOn2faOption->isEnabled(); |
52
|
|
|
$this->repository->save($institutionConfiguration); |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
// It can happen that the event changed for an institution that already exists, but is not yet projected to |
56
|
|
|
// this projection. In that case we can create it. |
57
|
|
|
$institutionConfiguration = new InstitutionConfiguration( |
58
|
|
|
(string)$event->institution, |
59
|
|
|
$event->ssoOn2faOption->isEnabled(), |
60
|
|
|
); |
61
|
|
|
$this->repository->save($institutionConfiguration); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurationRemovedEvent $event): void |
65
|
|
|
{ |
66
|
|
|
$this->repository->removeFor((string)$event->institution); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void |
70
|
|
|
{ |
71
|
|
|
// do nothing, no sensitive data in this projection |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|