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