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 Psr\Log\LoggerInterface; |
24
|
|
|
use Surfnet\SamlBundle\Http\RedirectBinding; |
25
|
|
|
use Surfnet\SamlBundle\SAML2\AuthnRequestFactory; |
26
|
|
|
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\ProviderRepository; |
27
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\ControllerCheckerService; |
28
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\GsspUserAttributeService; |
|
|
|
|
29
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
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 GssfAuthenticateController extends AbstractController |
37
|
|
|
{ |
38
|
|
|
public function __construct( |
|
|
|
|
39
|
|
|
private readonly LoggerInterface $logger, |
40
|
|
|
private readonly ProviderRepository $providerRepository, |
41
|
|
|
private readonly RedirectBinding $redirectBinding, |
42
|
|
|
private readonly GsspUserAttributeService $gsspUserAttributeService, |
43
|
|
|
private readonly ControllerCheckerService $checkerService, |
44
|
|
|
) { |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
#[Route( |
48
|
|
|
path: '/registration/gssf/{provider}/authenticate', |
49
|
|
|
name: 'ss_registration_gssf_authenticate', |
50
|
|
|
methods: ['POST'], |
51
|
|
|
)] |
52
|
|
|
public function authenticate(string $provider): Response |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$this->checkerService->assertSecondFactorEnabled($provider); |
55
|
|
|
|
56
|
|
|
$provider = $this->providerRepository->get($provider); |
57
|
|
|
|
58
|
|
|
$authnRequest = AuthnRequestFactory::createNewRequest( |
59
|
|
|
$provider->getServiceProvider(), |
60
|
|
|
$provider->getRemoteIdentityProvider(), |
61
|
|
|
false, |
62
|
|
|
'isGssfRequest' |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$this->gsspUserAttributeService->addGsspUserAttributes( |
66
|
|
|
$authnRequest, |
67
|
|
|
$provider, |
68
|
|
|
$this->getUser()->getIdentity() |
|
|
|
|
69
|
|
|
); |
70
|
|
|
$stateHandler = $provider->getStateHandler(); |
71
|
|
|
$stateHandler->setRequestId($authnRequest->getRequestId()); |
72
|
|
|
|
73
|
|
|
$this->logger->notice(sprintf( |
|
|
|
|
74
|
|
|
'Sending AuthnRequest with request ID: "%s" to GSSP "%s" at "%s"', |
75
|
|
|
$authnRequest->getRequestId(), |
76
|
|
|
$provider->getName(), |
77
|
|
|
$provider->getRemoteIdentityProvider()->getSsoUrl() |
78
|
|
|
)); |
|
|
|
|
79
|
|
|
|
80
|
|
|
return $this->redirectBinding->createResponseFor($authnRequest); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|