Passed
Push — main ( 1ee078...e7e8e3 )
by Michiel
26:57 queued 16:51
created

SecondFactorListController::__invoke()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 42
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 32
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 42
rs 9.408
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
 */
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 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
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class SecondFactorListController
Loading history...
34
{
35
    public function __construct(
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
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
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __invoke()
Loading history...
47
    {
48
        $identity = $this->getUser()->getIdentity();
0 ignored issues
show
Bug introduced by
The method getIdentity() does not exist on Symfony\Component\Security\Core\User\UserInterface. It seems like you code against a sub-type of Symfony\Component\Security\Core\User\UserInterface such as Surfnet\StepupSelfServic...n\AuthenticatedIdentity. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
        $identity = $this->getUser()->/** @scrutinizer ignore-call */ getIdentity();
Loading history...
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(
73
            'second_factor/list.html.twig',
74
            [
75
                'loaService' => $loaService,
76
                'email' => $identity->email,
77
                'maxNumberOfTokens' => $secondFactors->getMaximumNumberOfRegistrations(),
78
                'registrationsLeft' => $secondFactors->getRegistrationsLeft(),
79
                'unverifiedSecondFactors' => $secondFactors->unverified,
80
                'verifiedSecondFactors' => $secondFactors->verified,
81
                'vettedSecondFactors' => $secondFactors->vetted,
82
                'availableSecondFactors' => $secondFactors->available,
83
                'expirationHelper' => $this->registrationExpirationHelper,
84
                'selfAssertedTokenRegistration' => $selfAssertedTokenRegistration,
85
                'recoveryTokens' => $recoveryTokens,
86
                'hasRemainingRecoveryTokens' => $hasRemainingTokenTypes,
87
            ]
88
        );
89
    }
90
}
91