|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Copyright 2021 SURFnet B.V. |
|
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\SelfVet; |
|
22
|
|
|
|
|
23
|
|
|
use Psr\Log\LoggerInterface; |
|
24
|
|
|
use Surfnet\SamlBundle\Http\RedirectBinding; |
|
25
|
|
|
use Surfnet\SamlBundle\Monolog\SamlAuthenticationLogger; |
|
26
|
|
|
use Surfnet\StepupBundle\Service\LoaResolutionService; |
|
27
|
|
|
use Surfnet\StepupBundle\Service\SecondFactorTypeService; |
|
28
|
|
|
use Surfnet\StepupBundle\Value\Loa; |
|
29
|
|
|
use Surfnet\StepupBundle\Value\SecondFactorType; |
|
30
|
|
|
use Surfnet\StepupBundle\Value\VettingType; |
|
31
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\AuthorizationService; |
|
32
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SecondFactorService; |
|
33
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SelfVetMarshaller; |
|
34
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\TestSecondFactor\TestAuthenticationRequestFactory; |
|
|
|
|
|
|
35
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Value\SelfVetRequestId; |
|
36
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
37
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
38
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
39
|
|
|
use Symfony\Component\Routing\Attribute\Route; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
|
|
|
|
|
42
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList) |
|
43
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
|
44
|
|
|
*/ |
|
|
|
|
|
|
45
|
|
|
class SelfVetController extends AbstractController |
|
46
|
|
|
{ |
|
47
|
|
|
final public const SELF_VET_SESSION_ID = 'second_factor_self_vet_request_id'; |
|
48
|
|
|
|
|
49
|
|
|
public function __construct( |
|
|
|
|
|
|
50
|
|
|
private readonly LoggerInterface $logger, |
|
51
|
|
|
private readonly TestAuthenticationRequestFactory $authenticationRequestFactory, |
|
52
|
|
|
private readonly SecondFactorService $secondFactorService, |
|
53
|
|
|
private readonly SecondFactorTypeService $secondFactorTypeService, |
|
54
|
|
|
private readonly SelfVetMarshaller $selfVetMarshaller, |
|
55
|
|
|
private readonly AuthorizationService $authorizationService, |
|
56
|
|
|
private readonly RedirectBinding $redirectBinding, |
|
57
|
|
|
private readonly LoaResolutionService $loaResolutionService, |
|
58
|
|
|
private readonly SamlAuthenticationLogger $samlAuthenticationLogger, |
|
59
|
|
|
private readonly RequestStack $requestStack, |
|
60
|
|
|
) { |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
#[Route( |
|
65
|
|
|
path: '/second-factor/{secondFactorId}/self-vet', |
|
66
|
|
|
name: 'ss_second_factor_self_vet', |
|
67
|
|
|
methods: ['GET'], |
|
68
|
|
|
)] |
|
69
|
|
|
public function selfVet(string $secondFactorId): RedirectResponse |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
$this->logger->notice('Starting self vet proof of possession using higher or equal LoA token'); |
|
72
|
|
|
$identity = $this->getUser()->getIdentity(); |
|
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
if (!$this->selfVetMarshaller->isAllowed($identity, $secondFactorId)) { |
|
75
|
|
|
throw $this->createNotFoundException(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
// Start with some assumptions that are overwritten with the correct values in the code below |
|
79
|
|
|
$candidateSecondFactorLoa = $this->loaResolutionService->getLoaByLevel(Loa::LOA_SELF_VETTED); |
|
|
|
|
|
|
80
|
|
|
$isSelfVetOfSatToken = false; |
|
81
|
|
|
|
|
82
|
|
|
// Determine if we are dealing with a SelfVet action of a SAT token |
|
83
|
|
|
if ($this->authorizationService->maySelfVetSelfAssertedTokens($identity)) { |
|
84
|
|
|
$this->logger->notice('Determined we are self vetting a token using a self-asserted token'); |
|
85
|
|
|
$isSelfVetOfSatToken = true; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// When a regular self-vet action is performed grab the candidate second factor loa from the SF projection |
|
89
|
|
|
if (!$isSelfVetOfSatToken) { |
|
90
|
|
|
$this->logger->notice('Determined we are self vetting a token using an identity vetted token'); |
|
91
|
|
|
$candidateSecondFactor = $this->secondFactorService->findOneVerified($secondFactorId); |
|
92
|
|
|
$candidateSecondFactorLoa = $this->secondFactorTypeService->getLevel( |
|
93
|
|
|
new SecondFactorType($candidateSecondFactor->type), |
|
94
|
|
|
new VettingType(VettingType::TYPE_SELF_VET) |
|
95
|
|
|
); |
|
96
|
|
|
$candidateSecondFactorLoa = $this->loaResolutionService->getLoaByLevel($candidateSecondFactorLoa); |
|
97
|
|
|
} |
|
98
|
|
|
$this->logger->notice( |
|
99
|
|
|
sprintf( |
|
100
|
|
|
'Creating AuthNRequest requiring a LoA %s or higher token for self vetting.', |
|
101
|
|
|
$candidateSecondFactorLoa |
|
102
|
|
|
) |
|
103
|
|
|
); |
|
104
|
|
|
$authenticationRequest = $this->authenticationRequestFactory->createSecondFactorTestRequest( |
|
105
|
|
|
$identity->nameId, |
|
106
|
|
|
$candidateSecondFactorLoa |
|
107
|
|
|
); |
|
108
|
|
|
|
|
109
|
|
|
$this->requestStack->getSession()->set( |
|
110
|
|
|
self::SELF_VET_SESSION_ID, |
|
111
|
|
|
new SelfVetRequestId($authenticationRequest->getRequestId(), $secondFactorId) |
|
112
|
|
|
); |
|
113
|
|
|
|
|
114
|
|
|
$samlLogger = $this->samlAuthenticationLogger->forAuthentication($authenticationRequest->getRequestId()); |
|
115
|
|
|
$samlLogger->notice('Sending authentication request to the second factor only IdP'); |
|
116
|
|
|
|
|
117
|
|
|
return $this->redirectBinding->createResponseFor($authenticationRequest); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|