1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2020 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\MiddlewareBundle\Console\Command; |
20
|
|
|
|
21
|
|
|
use Broadway\EventHandling\EventBusInterface; |
22
|
|
|
use Rhumsaa\Uuid\Uuid; |
23
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution; |
24
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Repository\InstitutionConfigurationOptionsRepository; |
25
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\IdentityRepository; |
26
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\UnverifiedSecondFactorRepository; |
27
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\VerifiedSecondFactorRepository; |
28
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Command\VetSecondFactorCommand; |
29
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Pipeline\Pipeline; |
30
|
|
|
use Surfnet\StepupMiddleware\MiddlewareBundle\Service\DBALConnectionHelper; |
31
|
|
|
use Symfony\Component\Console\Command\Command; |
32
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
33
|
|
|
|
34
|
|
|
abstract class AbstractBootstrapCommand extends Command |
35
|
|
|
{ |
36
|
|
|
/** @var Pipeline */ |
37
|
|
|
protected $pipeline; |
38
|
|
|
/** @var EventBusInterface */ |
39
|
|
|
protected $eventBus; |
40
|
|
|
/** @var DBALConnectionHelper */ |
41
|
|
|
protected $connection; |
42
|
|
|
/** @var IdentityRepository */ |
43
|
|
|
protected $identityRepository; |
44
|
|
|
/** @var UnverifiedSecondFactorRepository */ |
45
|
|
|
protected $unverifiedSecondFactorRepository; |
46
|
|
|
/** @var VerifiedSecondFactorRepository */ |
47
|
|
|
protected $verifiedSecondFactorRepository; |
48
|
|
|
/** @var InstitutionConfigurationOptionsRepository */ |
49
|
|
|
private $institutionConfigurationRepository; |
50
|
|
|
/** @var TokenStorageInterface */ |
51
|
|
|
protected $tokenStorage; |
52
|
|
|
|
53
|
|
|
public function __construct( |
54
|
|
|
Pipeline $pipeline, |
55
|
|
|
EventBusInterface $eventBus, |
56
|
|
|
DBALConnectionHelper $connection, |
57
|
|
|
IdentityRepository $identityRepository, |
58
|
|
|
UnverifiedSecondFactorRepository $unverifiedSecondFactorRepository, |
59
|
|
|
VerifiedSecondFactorRepository $verifiedSecondFactorRepository, |
60
|
|
|
InstitutionConfigurationOptionsRepository $institutionConfigurationOptionsRepository, |
61
|
|
|
TokenStorageInterface $tokenStorage |
62
|
|
|
) { |
63
|
|
|
$this->pipeline = $pipeline; |
64
|
|
|
$this->eventBus = $eventBus; |
65
|
|
|
$this->connection = $connection; |
66
|
|
|
$this->identityRepository = $identityRepository; |
67
|
|
|
$this->unverifiedSecondFactorRepository = $unverifiedSecondFactorRepository; |
68
|
|
|
$this->verifiedSecondFactorRepository = $verifiedSecondFactorRepository; |
69
|
|
|
$this->institutionConfigurationRepository = $institutionConfigurationOptionsRepository; |
70
|
|
|
$this->tokenStorage = $tokenStorage; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function requiresMailVerification(Institution $institution) |
74
|
|
|
{ |
75
|
|
|
$configuration = $this->institutionConfigurationRepository->findConfigurationOptionsFor($institution); |
76
|
|
|
if ($configuration) { |
77
|
|
|
return $configuration->verifyEmailOption->isEnabled(); |
78
|
|
|
} |
79
|
|
|
return true; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
protected function vetSecondFactor($tokenType, $actorId, $identity, $secondFactorId, $verifiedSecondFactor, $phoneNumber) |
83
|
|
|
{ |
84
|
|
|
$command = new VetSecondFactorCommand(); |
85
|
|
|
$command->UUID = (string) Uuid::uuid4(); |
86
|
|
|
$command->authorityId = $actorId; |
87
|
|
|
$command->identityId = $identity->id; |
88
|
|
|
$command->secondFactorId = $secondFactorId; |
89
|
|
|
$command->registrationCode = $verifiedSecondFactor->registrationCode; |
90
|
|
|
$command->secondFactorType = $tokenType; |
91
|
|
|
$command->secondFactorIdentifier = $phoneNumber; |
92
|
|
|
$command->documentNumber = '123987'; |
93
|
|
|
$command->identityVerified = true; |
94
|
|
|
$this->pipeline->process($command); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|