|
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 |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
// todo: get extension data from authn request! |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function determineGsspFallbackNeeded( |
|
53
|
|
|
string $identityNameId, |
|
|
|
|
|
|
54
|
|
|
string $authenticationMode, |
|
|
|
|
|
|
55
|
|
|
Loa $requestedLoa, |
|
|
|
|
|
|
56
|
|
|
WhitelistService $whitelistService |
|
|
|
|
|
|
57
|
|
|
): bool { |
|
58
|
|
|
|
|
59
|
|
|
return false; |
|
60
|
|
|
|
|
61
|
|
|
if ($authenticationMode === SecondFactorController::MODE_SFO) { |
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.