1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2014 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\StepupSelfService\SelfServiceBundle\Service; |
22
|
|
|
|
23
|
|
|
use Psr\Log\LoggerInterface; |
24
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Exception\NotFoundException; |
25
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity; |
26
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Service\VettingTypeHintService; |
27
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Value\VettingType\OnPremise; |
28
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Value\VettingType\SelfAssertedToken; |
29
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Value\VettingType\SelfVet; |
30
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Value\VettingType\VettingTypeCollection; |
31
|
|
|
|
32
|
|
|
readonly class VettingTypeService |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
public function __construct( |
|
|
|
|
35
|
|
|
private SelfVetMarshaller $selfVetMarshaller, |
36
|
|
|
private SelfAssertedTokensMarshaller $selfAssertedTokensMarshaller, |
37
|
|
|
private ActivationFlowService $activationFlowService, |
38
|
|
|
private VettingTypeHintService $vettingTypeHintService, |
39
|
|
|
private LoggerInterface $logger |
40
|
|
|
) { |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function vettingTypes(Identity $identity, string $secondFactorId): VettingTypeCollection |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$collection = new VettingTypeCollection(); |
46
|
|
|
$this->logger->info('Adding "OnPremise" vetting type to VettingTypeCollection'); |
47
|
|
|
$collection->add(new OnPremise()); |
48
|
|
|
if ($this->selfAssertedTokensMarshaller->isAllowed($identity, $secondFactorId)) { |
49
|
|
|
$this->logger->info('Adding "SelfAssertedToken" vetting type to VettingTypeCollection'); |
50
|
|
|
$collection->add(new SelfAssertedToken()); |
51
|
|
|
} |
52
|
|
|
if ($this->selfVetMarshaller->isAllowed($identity, $secondFactorId)) { |
53
|
|
|
$this->logger->info('Adding "SelfVet" vetting type to VettingTypeCollection'); |
54
|
|
|
$collection->add(new SelfVet()); |
55
|
|
|
} |
56
|
|
|
$preference = $this->activationFlowService->getPreference(); |
57
|
|
|
$this->logger->info(sprintf('Expressing "%s" vetting type as preferred activation flow', $preference)); |
58
|
|
|
$collection->expressVettingPreference($preference); |
59
|
|
|
|
60
|
|
|
return $collection; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function vettingTypeHint(string $institution, string $locale): ?string |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
try { |
66
|
|
|
$hint = $this->vettingTypeHintService->findOne($institution); |
67
|
|
|
if ($hint->hints !== []) { |
68
|
|
|
$hintText = array_filter($hint->hints, fn($hintEntry): bool => $hintEntry['locale'] === $locale); |
69
|
|
|
if ($hintText !== []) { |
70
|
|
|
return reset($hintText)['hint']; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} catch (NotFoundException) { |
74
|
|
|
// Do nothing for now |
75
|
|
|
} |
76
|
|
|
return null; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|