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\Configuration\Event\SsoRegistrationBypassOptionChangedEvent; |
24
|
|
|
use Surfnet\Stepup\Configuration\Value\SsoOn2faOption; |
|
|
|
|
25
|
|
|
use Surfnet\Stepup\Configuration\Value\SsoRegistrationBypassOption; |
|
|
|
|
26
|
|
|
use Surfnet\Stepup\Identity\Event\IdentityForgottenEvent; |
27
|
|
|
use Surfnet\Stepup\Projector\Projector; |
28
|
|
|
use Surfnet\Stepup\Configuration\Event\InstitutionConfigurationRemovedEvent; |
29
|
|
|
use Surfnet\Stepup\Configuration\Event\NewInstitutionConfigurationCreatedEvent; |
30
|
|
|
use Surfnet\Stepup\Configuration\Event\SsoOn2faOptionChangedEvent; |
31
|
|
|
use Surfnet\StepupMiddleware\GatewayBundle\Entity\InstitutionConfiguration; |
32
|
|
|
use Surfnet\StepupMiddleware\GatewayBundle\Repository\InstitutionConfigurationRepository; |
33
|
|
|
|
34
|
|
|
class InstitutionConfigurationProjector extends Projector |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
public function __construct(private readonly InstitutionConfigurationRepository $repository) |
37
|
|
|
{ |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function applyNewInstitutionConfigurationCreatedEvent(NewInstitutionConfigurationCreatedEvent $event): void |
41
|
|
|
{ |
42
|
|
|
$institutionConfiguration = new InstitutionConfiguration( |
43
|
|
|
(string)$event->institution, |
44
|
|
|
$event->ssoOn2faOption->isEnabled(), |
45
|
|
|
$event->ssoRegistrationBypassOption->isEnabled(), |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$this->repository->save($institutionConfiguration); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function applySsoOn2faOptionChangedEvent(SsoOn2faOptionChangedEvent $event): void |
52
|
|
|
{ |
53
|
|
|
$institutionConfiguration = $this->repository->findByInstitution((string)$event->institution); |
54
|
|
|
if ($institutionConfiguration instanceof InstitutionConfiguration) { |
55
|
|
|
$institutionConfiguration->ssoOn2faEnabled = $event->ssoOn2faOption->isEnabled(); |
56
|
|
|
$this->repository->save($institutionConfiguration); |
57
|
|
|
return; |
58
|
|
|
} |
59
|
|
|
// It can happen that the event changed for an institution that already exists, but is not yet projected to |
60
|
|
|
// this projection. In that case we can create it. |
61
|
|
|
$institutionConfiguration = new InstitutionConfiguration( |
62
|
|
|
(string)$event->institution, |
63
|
|
|
$event->ssoOn2faOption->isEnabled(), |
64
|
|
|
SsoRegistrationBypassOption::getDefault()->isEnabled(), |
65
|
|
|
); |
66
|
|
|
$this->repository->save($institutionConfiguration); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function applySsoRegistrationBypassOptionChangedEvent(SsoRegistrationBypassOptionChangedEvent $event): void |
70
|
|
|
{ |
71
|
|
|
$institutionConfiguration = $this->repository->findByInstitution((string)$event->institution); |
72
|
|
|
if ($institutionConfiguration instanceof InstitutionConfiguration) { |
73
|
|
|
$institutionConfiguration->ssoRegistrationBypass = $event->ssoRegistrationBypassOption->isEnabled(); |
74
|
|
|
$this->repository->save($institutionConfiguration); |
75
|
|
|
return; |
76
|
|
|
} |
77
|
|
|
// It can happen that the event changed for an institution that already exists, but is not yet projected to |
78
|
|
|
// this projection. In that case we can create it. |
79
|
|
|
$institutionConfiguration = new InstitutionConfiguration( |
80
|
|
|
(string)$event->institution, |
81
|
|
|
SsoOn2faOption::getDefault()->isEnabled(), |
82
|
|
|
$event->ssoRegistrationBypassOption->isEnabled(), |
83
|
|
|
); |
84
|
|
|
$this->repository->save($institutionConfiguration); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function applyInstitutionConfigurationRemovedEvent(InstitutionConfigurationRemovedEvent $event): void |
88
|
|
|
{ |
89
|
|
|
$this->repository->removeFor((string)$event->institution); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
protected function applyIdentityForgottenEvent(IdentityForgottenEvent $event): void |
93
|
|
|
{ |
94
|
|
|
// do nothing, no sensitive data in this projection |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|