Passed
Pull Request — main (#308)
by Paul
12:52 queued 05:50
created

SecondFactorListController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 34
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 41 4
A __construct() 0 10 1
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
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
20
21
namespace Surfnet\StepupSelfService\SelfServiceBundle\Controller\SecondFactor;
22
23
use Psr\Log\LoggerInterface;
24
use Surfnet\StepupBundle\DateTime\RegistrationExpirationHelper;
25
use Surfnet\StepupBundle\Service\SecondFactorTypeService;
26
use Surfnet\StepupSelfService\SelfServiceBundle\Controller\Controller;
27
use Surfnet\StepupSelfService\SelfServiceBundle\Service\AuthorizationService;
28
use Surfnet\StepupSelfService\SelfServiceBundle\Service\InstitutionConfigurationOptionsService;
29
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SecondFactorService;
30
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfAssertedTokens\RecoveryTokenService;
31
use Symfony\Bridge\Twig\Attribute\Template;
32
use Symfony\Component\Routing\Attribute\Route;
33
34
class SecondFactorListController extends Controller
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class SecondFactorListController
Loading history...
35
{
36
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
37
        LoggerInterface $logger,
38
        private readonly InstitutionConfigurationOptionsService $configurationOptionsService,
39
        private readonly RecoveryTokenService    $recoveryTokenService,
40
        private readonly AuthorizationService    $authorizationService,
41
        private readonly SecondFactorTypeService $secondFactorTypeService,
42
        private readonly SecondFactorService $secondFactorService,
43
        private readonly RegistrationExpirationHelper $registrationExpirationHelper,
44
    ) {
45
        parent::__construct($logger, $configurationOptionsService);
46
    }
47
    #[Template('second_factor/list.html.twig')]
48
    #[Route(path: '/overview', name: 'ss_second_factor_list', methods:  ['GET'])]
49
    public function __invoke(): array
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __invoke()
Loading history...
50
    {
51
        $identity = $this->getIdentity();
52
        $institution = $this->getIdentity()->institution;
53
        $options = $this->configurationOptionsService
54
            ->getInstitutionConfigurationOptionsFor($institution);
55
56
        // Get all available second factors from the config.
57
        $allSecondFactors = $this->getParameter('ss.enabled_second_factors');
58
59
        $secondFactors = $this->secondFactorService->getSecondFactorsForIdentity(
60
            $identity,
61
            $allSecondFactors,
62
            $options->allowedSecondFactors,
63
            $options->numberOfTokensPerIdentity
64
        );
65
66
        $recoveryTokensAllowed = $this->authorizationService->mayRegisterRecoveryTokens($identity);
67
        $selfAssertedTokenRegistration = $options->allowSelfAssertedTokens === true && $recoveryTokensAllowed;
68
        $hasRemainingTokenTypes = $this->recoveryTokenService->getRemainingTokenTypes($identity) !== [];
69
        $recoveryTokens = [];
70
        if ($selfAssertedTokenRegistration && $recoveryTokensAllowed) {
71
            $recoveryTokens = $this->recoveryTokenService->getRecoveryTokensForIdentity($identity);
72
        }
73
        $loaService = $this->secondFactorTypeService;
74
75
        return [
76
            'loaService' => $loaService,
77
            'email' => $identity->email,
78
            'maxNumberOfTokens' => $secondFactors->getMaximumNumberOfRegistrations(),
79
            'registrationsLeft' => $secondFactors->getRegistrationsLeft(),
80
            'unverifiedSecondFactors' => $secondFactors->unverified,
81
            'verifiedSecondFactors' => $secondFactors->verified,
82
            'vettedSecondFactors' => $secondFactors->vetted,
83
            'availableSecondFactors' => $secondFactors->available,
84
            'expirationHelper' => $this->registrationExpirationHelper,
85
            'selfAssertedTokenRegistration' => $selfAssertedTokenRegistration,
86
            'recoveryTokens' => $recoveryTokens,
87
            'hasRemainingRecoveryTokens' => $hasRemainingTokenTypes,
88
        ];
89
    }
90
}
91