|
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
|
|
|
*/ |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
namespace Surfnet\StepupSelfService\SelfServiceBundle\Controller\Registration\Gssf; |
|
22
|
|
|
|
|
23
|
|
|
use JMS\TranslationBundle\Annotation\Ignore; |
|
24
|
|
|
use Surfnet\StepupBundle\Value\Provider\ViewConfigCollection; |
|
25
|
|
|
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\ViewConfig; |
|
26
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Form\Type\StatusGssfType; |
|
27
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\ControllerCheckerService; |
|
28
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
29
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
30
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
31
|
|
|
use Symfony\Component\Routing\Attribute\Route; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Controls registration with Generic SAML Stepup Providers (GSSPs), yielding Generic SAML Second Factors (GSSFs). |
|
35
|
|
|
*/ |
|
|
|
|
|
|
36
|
|
|
final class GssfStatusController extends AbstractController |
|
37
|
|
|
{ |
|
38
|
|
|
public function __construct( |
|
|
|
|
|
|
39
|
|
|
private readonly ViewConfigCollection $viewConfigCollection, |
|
40
|
|
|
private readonly ControllerCheckerService $checkerService, |
|
41
|
|
|
) { |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
|
|
|
|
|
45
|
|
|
* Render the status form. |
|
46
|
|
|
* |
|
47
|
|
|
* This action has two parameters: |
|
48
|
|
|
* |
|
49
|
|
|
* - authenticationFailed (default false), will trigger an error message |
|
50
|
|
|
* and is used when a SAML failure response was received, for example |
|
51
|
|
|
* when the users cancelled the registration |
|
52
|
|
|
* |
|
53
|
|
|
* - proofOfPossessionFailed (default false), will trigger an error message |
|
54
|
|
|
* when possession was not proven, but the SAML response was successful |
|
55
|
|
|
*/ |
|
|
|
|
|
|
56
|
|
|
#[Route( |
|
57
|
|
|
path: '/registration/gssf/{provider}/status', |
|
58
|
|
|
name: 'ss_registration_gssf_status_report', |
|
59
|
|
|
defaults: ['authenticationFailed' => false, 'proofOfPossessionFailed'=> false ], |
|
60
|
|
|
methods: ['GET'], |
|
61
|
|
|
)] |
|
62
|
|
|
public function status(Request $request, string $provider): Response |
|
63
|
|
|
{ |
|
64
|
|
|
$this->checkerService->assertSecondFactorEnabled($provider); |
|
65
|
|
|
|
|
66
|
|
|
return $this->renderStatusForm( |
|
67
|
|
|
$provider, |
|
68
|
|
|
[ |
|
69
|
|
|
'authenticationFailed' => (bool) $request->query->get('authenticationFailed'), |
|
70
|
|
|
'proofOfPossessionFailed' => (bool) $request->query->get('proofOfPossessionFailed'), |
|
71
|
|
|
] |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
private function renderStatusForm(string $provider, array $parameters = []): Response |
|
|
|
|
|
|
76
|
|
|
{ |
|
77
|
|
|
/** @var ViewConfig $secondFactorConfig */ |
|
|
|
|
|
|
78
|
|
|
$secondFactorConfig = $this->viewConfigCollection->getByIdentifier($provider); |
|
79
|
|
|
|
|
80
|
|
|
$form = $this->createForm( |
|
81
|
|
|
StatusGssfType::class, |
|
82
|
|
|
null, |
|
83
|
|
|
[ |
|
84
|
|
|
'provider' => $provider, |
|
85
|
|
|
/** @Ignore from translation message extraction */ |
|
|
|
|
|
|
86
|
|
|
'label' => $secondFactorConfig->getInitiateButton() |
|
87
|
|
|
] |
|
88
|
|
|
); |
|
89
|
|
|
$templateParameters = array_merge( |
|
90
|
|
|
$parameters, |
|
91
|
|
|
[ |
|
92
|
|
|
'form' => $form->createView(), |
|
93
|
|
|
'provider' => $provider, |
|
94
|
|
|
'secondFactorConfig' => $secondFactorConfig, |
|
95
|
|
|
'verifyEmail' => $this->checkerService->emailVerificationIsRequired(), |
|
96
|
|
|
] |
|
97
|
|
|
); |
|
98
|
|
|
return $this->render( |
|
99
|
|
|
'registration/gssf/status.html.twig', |
|
100
|
|
|
$templateParameters |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|