|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Copyright 2023 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\Controller\SecondFactor; |
|
22
|
|
|
|
|
23
|
|
|
use Surfnet\StepupBundle\DateTime\RegistrationExpirationHelper; |
|
24
|
|
|
use Surfnet\StepupBundle\Service\SecondFactorTypeService; |
|
25
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\AuthorizationService; |
|
26
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\InstitutionConfigurationOptionsService; |
|
27
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SecondFactorService; |
|
28
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens\RecoveryTokenService; |
|
29
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
30
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
31
|
|
|
use Symfony\Component\Routing\Attribute\Route; |
|
32
|
|
|
|
|
33
|
|
|
class SecondFactorListController extends AbstractController |
|
|
|
|
|
|
34
|
|
|
{ |
|
35
|
|
|
public function __construct( |
|
|
|
|
|
|
36
|
|
|
private readonly InstitutionConfigurationOptionsService $configurationOptionsService, |
|
37
|
|
|
private readonly RecoveryTokenService $recoveryTokenService, |
|
38
|
|
|
private readonly AuthorizationService $authorizationService, |
|
39
|
|
|
private readonly SecondFactorTypeService $secondFactorTypeService, |
|
40
|
|
|
private readonly SecondFactorService $secondFactorService, |
|
41
|
|
|
private readonly RegistrationExpirationHelper $registrationExpirationHelper, |
|
42
|
|
|
) { |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
#[Route(path: '/overview', name: 'ss_second_factor_list', methods: ['GET'])] |
|
46
|
|
|
public function __invoke(): Response |
|
|
|
|
|
|
47
|
|
|
{ |
|
48
|
|
|
$identity = $this->getUser()->getIdentity(); |
|
|
|
|
|
|
49
|
|
|
$institution = $identity->institution; |
|
50
|
|
|
$options = $this->configurationOptionsService |
|
51
|
|
|
->getInstitutionConfigurationOptionsFor($institution); |
|
52
|
|
|
|
|
53
|
|
|
// Get all available second factors from the config. |
|
54
|
|
|
$allSecondFactors = $this->getParameter('ss.enabled_second_factors'); |
|
55
|
|
|
|
|
56
|
|
|
$secondFactors = $this->secondFactorService->getSecondFactorsForIdentity( |
|
57
|
|
|
$identity, |
|
58
|
|
|
$allSecondFactors, |
|
59
|
|
|
$options->allowedSecondFactors, |
|
60
|
|
|
$options->numberOfTokensPerIdentity |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
$recoveryTokensAllowed = $this->authorizationService->mayRegisterRecoveryTokens($identity); |
|
64
|
|
|
$selfAssertedTokenRegistration = $options->allowSelfAssertedTokens === true && $recoveryTokensAllowed; |
|
65
|
|
|
$hasRemainingTokenTypes = $this->recoveryTokenService->getRemainingTokenTypes($identity) !== []; |
|
66
|
|
|
$recoveryTokens = []; |
|
67
|
|
|
if ($selfAssertedTokenRegistration && $recoveryTokensAllowed) { |
|
68
|
|
|
$recoveryTokens = $this->recoveryTokenService->getRecoveryTokensForIdentity($identity); |
|
69
|
|
|
} |
|
70
|
|
|
$loaService = $this->secondFactorTypeService; |
|
71
|
|
|
|
|
72
|
|
|
return $this->render('second_factor/list.html.twig', |
|
|
|
|
|
|
73
|
|
|
[ |
|
74
|
|
|
'loaService' => $loaService, |
|
75
|
|
|
'email' => $identity->email, |
|
76
|
|
|
'maxNumberOfTokens' => $secondFactors->getMaximumNumberOfRegistrations(), |
|
77
|
|
|
'registrationsLeft' => $secondFactors->getRegistrationsLeft(), |
|
78
|
|
|
'unverifiedSecondFactors' => $secondFactors->unverified, |
|
79
|
|
|
'verifiedSecondFactors' => $secondFactors->verified, |
|
80
|
|
|
'vettedSecondFactors' => $secondFactors->vetted, |
|
81
|
|
|
'availableSecondFactors' => $secondFactors->available, |
|
82
|
|
|
'expirationHelper' => $this->registrationExpirationHelper, |
|
83
|
|
|
'selfAssertedTokenRegistration' => $selfAssertedTokenRegistration, |
|
84
|
|
|
'recoveryTokens' => $recoveryTokens, |
|
85
|
|
|
'hasRemainingRecoveryTokens' => $hasRemainingTokenTypes, |
|
86
|
|
|
] |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|