1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2024 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\Security\Authentication; |
22
|
|
|
|
23
|
|
|
use Surfnet\SamlBundle\Security\Authentication\SamlAuthenticator as StepupSamlAuthenticator; |
24
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\ActivationFlowService; |
25
|
|
|
use Symfony\Component\HttpFoundation\Request; |
26
|
|
|
use Symfony\Component\HttpFoundation\Response; |
27
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
28
|
|
|
use Symfony\Component\Security\Core\Exception\AuthenticationException; |
29
|
|
|
use Symfony\Component\Security\Http\Authenticator\InteractiveAuthenticatorInterface; |
30
|
|
|
use Symfony\Component\Security\Http\Authenticator\Passport\Passport; |
31
|
|
|
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface; |
32
|
|
|
|
33
|
|
|
class SamlAuthenticator implements InteractiveAuthenticatorInterface, AuthenticationEntryPointInterface |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
public function __construct( |
|
|
|
|
36
|
|
|
readonly private StepupSamlAuthenticator $authenticator, |
37
|
|
|
private readonly ActivationFlowService $activationFlowService, |
38
|
|
|
) { |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function start(Request $request, ?AuthenticationException $authException = null): Response |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
// Check if we need to do a registration flow nudge |
44
|
|
|
// This is used for when we are not logged in yet because the authentication is done in the Stepup-SAML-bundle |
45
|
|
|
$this->activationFlowService->processPreferenceFromUri($request->getUri()); |
46
|
|
|
return $this->authenticator->start($request, $authException); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function supports(Request $request): ?bool |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
return $this->authenticator->supports($request); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function authenticate(Request $request): Passport |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
return $this->authenticator->authenticate($request); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function createToken(Passport $passport, string $firewallName): TokenInterface |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
return $this->authenticator->createToken($passport, $firewallName); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
return $this->authenticator->onAuthenticationSuccess($request, $token, $firewallName); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
return $this->authenticator->onAuthenticationFailure($request, $exception); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function isInteractive(): bool |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
return $this->authenticator->isInteractive(); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|