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