Passed
Push — feature/add-azure-mfa-registra... ( 39aafb...5b7d89 )
by
unknown
02:14
created

GsspFallbackService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2025 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\StepupGateway\SecondFactorOnlyBundle\Service\Gateway;
20
21
use Psr\Log\LoggerInterface;
22
use Surfnet\SamlBundle\SAML2\ReceivedAuthnRequest;
23
use Surfnet\StepupBundle\Value\Loa;
24
use Surfnet\StepupGateway\GatewayBundle\Controller\SecondFactorController;
25
use Surfnet\StepupGateway\GatewayBundle\Entity\SecondFactorRepository;
26
use Surfnet\StepupGateway\GatewayBundle\Saml\Proxy\ProxyStateHandler;
27
use Surfnet\StepupGateway\GatewayBundle\Service\SecondFactor\SecondFactorInterface;
28
use Surfnet\StepupGateway\GatewayBundle\Service\WhitelistService;
29
30
class GsspFallbackService
31
{
32
33
    private SecondFactorRepository $secondFactorRepository;
34
    private ProxyStateHandler $stateHandler;
35
    private LoggerInterface $logger;
36
37
    public function __construct(SecondFactorRepository $secondFactorRepository, ProxyStateHandler $stateHandler, LoggerInterface $logger)
38
    {
39
        $this->secondFactorRepository = $secondFactorRepository;
40
        $this->stateHandler = $stateHandler;
41
        $this->logger = $logger;
42
    }
43
44
    /**
45
     * @param ReceivedAuthnRequest $originalRequest
46
     */
47
    public function handleSamlGsspExtension(ReceivedAuthnRequest $originalRequest): void
0 ignored issues
show
Unused Code introduced by
The parameter $originalRequest is not used and could be removed. ( Ignorable by Annotation )

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

47
    public function handleSamlGsspExtension(/** @scrutinizer ignore-unused */ ReceivedAuthnRequest $originalRequest): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49
        // todo: get extension data from authn request!
50
    }
51
52
    public function determineGsspFallbackNeeded(
53
        string $identityNameId,
0 ignored issues
show
Unused Code introduced by
The parameter $identityNameId is not used and could be removed. ( Ignorable by Annotation )

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

53
        /** @scrutinizer ignore-unused */ string $identityNameId,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
        string $authenticationMode,
0 ignored issues
show
Unused Code introduced by
The parameter $authenticationMode is not used and could be removed. ( Ignorable by Annotation )

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

54
        /** @scrutinizer ignore-unused */ string $authenticationMode,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
        Loa $requestedLoa,
0 ignored issues
show
Unused Code introduced by
The parameter $requestedLoa is not used and could be removed. ( Ignorable by Annotation )

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

55
        /** @scrutinizer ignore-unused */ Loa $requestedLoa,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
        WhitelistService $whitelistService
0 ignored issues
show
Unused Code introduced by
The parameter $whitelistService is not used and could be removed. ( Ignorable by Annotation )

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

56
        /** @scrutinizer ignore-unused */ WhitelistService $whitelistService

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
57
    ): bool {
58
59
        return false;
60
61
        if ($authenticationMode === SecondFactorController::MODE_SFO) {
0 ignored issues
show
Unused Code introduced by
IfNode is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
62
            return true;
63
        }
64
65
        return false;
66
67
        // - a LoA1.5 (i.e. self asserted) authentication is requested
68
        // - a fallback GSSP is configured
69
        // - this "fallback" option is enabled for the institution that the user belongs to.
70
        // - the configured user attribute is present in the AuthnRequest
71
72
//        $this->logger->info('Determine GSSP fallback');
73
//
74
//        $candidateSecondFactors = $this->secondFactorRepository->getInstitutionByNameId($identityNameId);
75
//        $this->logger->info(
76
//            sprintf('Loaded %d matching candidate second factors', count($candidateSecondFactors))
77
//        );
78
//
79
//        if ($candidateSecondFactors->isEmpty()) {
80
//            $this->logger->alert('No suitable candidate second factors found, sending Loa cannot be given response');
81
//        }
82
83
        return false;
84
    }
85
86
    public function isSecondFactorFallback(): bool
87
    {
88
        return $this->stateHandler->isSecondFactorFallback();
89
    }
90
91
    public function createSecondFactor(): SecondFactorInterface
92
    {
93
        return SecondfactorGsspFallback::create('azuremfa', $this->stateHandler->getPreferredLocale());
0 ignored issues
show
Bug introduced by
It seems like $this->stateHandler->getPreferredLocale() can also be of type null; however, parameter $displayLocale of Surfnet\StepupGateway\Se...rGsspFallback::create() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

93
        return SecondfactorGsspFallback::create('azuremfa', /** @scrutinizer ignore-type */ $this->stateHandler->getPreferredLocale());
Loading history...
94
    }
95
}
96