1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2016 SURFnet B.V. |
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\CommandHandlingBundle\Processor; |
20
|
|
|
|
21
|
|
|
use Broadway\Processor\Processor; |
22
|
|
|
use DateInterval; |
23
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution; |
24
|
|
|
use Surfnet\Stepup\DateTime\DateTime; |
25
|
|
|
use Surfnet\Stepup\Identity\Event\EmailVerifiedEvent; |
26
|
|
|
use Surfnet\Stepup\Identity\Event\GssfPossessionProvenAndVerifiedEvent; |
27
|
|
|
use Surfnet\Stepup\Identity\Event\PhonePossessionProvenAndVerifiedEvent; |
28
|
|
|
use Surfnet\Stepup\Identity\Event\PossessionProvenAndVerified; |
29
|
|
|
use Surfnet\Stepup\Identity\Event\U2fDevicePossessionProvenAndVerifiedEvent; |
30
|
|
|
use Surfnet\Stepup\Identity\Event\YubikeyPossessionProvenAndVerifiedEvent; |
31
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\InstitutionConfigurationOptionsService; |
32
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\RaLocationService; |
33
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\RaListingService; |
34
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Value\RegistrationAuthorityCredentials; |
35
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Service\RegistrationMailService; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
39
|
|
|
*/ |
40
|
|
|
final class RegistrationEmailProcessor extends Processor |
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* @var RaLocationService |
44
|
|
|
*/ |
45
|
|
|
private $raLocationsService; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var RegistrationMailService |
49
|
|
|
*/ |
50
|
|
|
private $registrationMailService; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var InstitutionConfigurationOptionsService |
54
|
|
|
*/ |
55
|
|
|
private $institutionConfigurationOptionsService; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var RaListingService |
59
|
|
|
*/ |
60
|
|
|
private $raListingService; |
61
|
|
|
|
62
|
|
|
public function __construct( |
63
|
|
|
RegistrationMailService $registrationMailService, |
64
|
|
|
RaListingService $raListingService, |
65
|
|
|
InstitutionConfigurationOptionsService $institutionConfigurationOptionsService, |
|
|
|
|
66
|
|
|
RaLocationService $raLocationsService |
67
|
|
|
) { |
68
|
|
|
$this->registrationMailService = $registrationMailService; |
69
|
|
|
$this->raListingService = $raListingService; |
70
|
|
|
$this->institutionConfigurationOptionsService = $institutionConfigurationOptionsService; |
71
|
|
|
$this->raLocationsService = $raLocationsService; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function handlePhonePossessionProvenAndVerifiedEvent(PhonePossessionProvenAndVerifiedEvent $event) |
75
|
|
|
{ |
76
|
|
|
$this->handlePossessionProvenAndVerifiedEvent($event); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function handleYubikeyPossessionProvenAndVerifiedEvent(YubikeyPossessionProvenAndVerifiedEvent $event) |
80
|
|
|
{ |
81
|
|
|
$this->handlePossessionProvenAndVerifiedEvent($event); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function handleU2fDevicePossessionProvenAndVerifiedEvent(U2fDevicePossessionProvenAndVerifiedEvent $event) |
85
|
|
|
{ |
86
|
|
|
$this->handlePossessionProvenAndVerifiedEvent($event); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function handleGssfPossessionProvenAndVerifiedEvent(GssfPossessionProvenAndVerifiedEvent $event) |
90
|
|
|
{ |
91
|
|
|
$this->handlePossessionProvenAndVerifiedEvent($event); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function handleEmailVerifiedEvent(EmailVerifiedEvent $event) |
95
|
|
|
{ |
96
|
|
|
$this->handlePossessionProvenAndVerifiedEvent($event); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
private function handlePossessionProvenAndVerifiedEvent(PossessionProvenAndVerified $event) |
100
|
|
|
{ |
101
|
|
|
$institution = new Institution($event->identityInstitution->getInstitution()); |
|
|
|
|
102
|
|
|
$institutionConfigurationOptions = $this->institutionConfigurationOptionsService |
|
|
|
|
103
|
|
|
->findInstitutionConfigurationOptionsFor($institution); |
104
|
|
|
|
105
|
|
|
if ($institutionConfigurationOptions->useRaLocationsOption->isEnabled()) { |
106
|
|
|
$this->sendRegistrationEmailWithRaLocations($event, $institution); |
107
|
|
|
|
108
|
|
|
return; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$ras = $this->raListingService->listRegistrationAuthoritiesFor($event->identityInstitution); |
|
|
|
|
112
|
|
|
|
113
|
|
|
if ($institutionConfigurationOptions->showRaaContactInformationOption->isEnabled()) { |
114
|
|
|
$this->sendRegistrationEmailWithRas($event, $ras); |
115
|
|
|
|
116
|
|
|
return; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$rasWithoutRaas = array_filter($ras, function (RegistrationAuthorityCredentials $ra) { |
120
|
|
|
return !$ra->isRaa(); |
121
|
|
|
}); |
122
|
|
|
|
123
|
|
|
$this->sendRegistrationEmailWithRas($event, $rasWithoutRaas); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @param EmailVerifiedEvent $event |
|
|
|
|
128
|
|
|
* @param Institution $institution |
129
|
|
|
*/ |
130
|
|
|
private function sendRegistrationEmailWithRaLocations(PossessionProvenAndVerified $event, Institution $institution) |
131
|
|
|
{ |
132
|
|
|
$this->registrationMailService->sendRegistrationEmailWithRaLocations( |
133
|
|
|
(string)$event->preferredLocale, |
|
|
|
|
134
|
|
|
(string)$event->commonName, |
|
|
|
|
135
|
|
|
(string)$event->email, |
|
|
|
|
136
|
|
|
$event->registrationCode, |
|
|
|
|
137
|
|
|
$this->getExpirationDateOfRegistration($event), |
138
|
|
|
$this->raLocationsService->listRaLocationsFor($institution) |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param PossessionProvenAndVerified $event |
144
|
|
|
* @param RegistrationAuthorityCredentials[] $ras |
145
|
|
|
*/ |
146
|
|
|
private function sendRegistrationEmailWithRas(PossessionProvenAndVerified $event, array $ras) |
147
|
|
|
{ |
148
|
|
|
$this->registrationMailService->sendRegistrationEmailWithRas( |
149
|
|
|
(string)$event->preferredLocale, |
|
|
|
|
150
|
|
|
(string)$event->commonName, |
|
|
|
|
151
|
|
|
(string)$event->email, |
|
|
|
|
152
|
|
|
$event->registrationCode, |
|
|
|
|
153
|
|
|
$this->getExpirationDateOfRegistration($event), |
154
|
|
|
$ras |
155
|
|
|
); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param EmailVerifiedEvent $event |
|
|
|
|
160
|
|
|
* @return DateTime |
161
|
|
|
*/ |
162
|
|
|
private function getExpirationDateOfRegistration(PossessionProvenAndVerified $event) |
163
|
|
|
{ |
164
|
|
|
return $event->registrationRequestedAt->add( |
|
|
|
|
165
|
|
|
new DateInterval('P14D') |
166
|
|
|
)->endOfDay(); |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.