1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2014 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; |
22
|
|
|
|
23
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\ControllerCheckerService; |
24
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Command\VerifyYubikeyOtpCommand; |
25
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Form\Type\ProveYubikeyPossessionType; |
26
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\YubikeySecondFactorServiceInterface; |
27
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
28
|
|
|
use Symfony\Component\HttpFoundation\Request; |
29
|
|
|
use Symfony\Component\HttpFoundation\Response; |
30
|
|
|
use Symfony\Component\Routing\Attribute\Route; |
31
|
|
|
|
32
|
|
|
class YubikeyController extends AbstractController |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
public function __construct( |
|
|
|
|
35
|
|
|
private readonly ControllerCheckerService $checkerService, |
36
|
|
|
private readonly YubikeySecondFactorServiceInterface $yubikeySecondFactorService, |
37
|
|
|
) { |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
#[Route( |
41
|
|
|
path: '/registration/yubikey/prove-possession', |
42
|
|
|
name: 'ss_registration_yubikey_prove_possession', |
43
|
|
|
methods: ['GET','POST'], |
44
|
|
|
)] |
45
|
|
|
public function provePossession(Request $request): Response |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$this->checkerService->assertSecondFactorEnabled('yubikey'); |
48
|
|
|
|
49
|
|
|
$identity = $this->getUser()->getIdentity(); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$command = new VerifyYubikeyOtpCommand(); |
52
|
|
|
$command->identity = $identity->id; |
53
|
|
|
$command->institution = $identity->institution; |
54
|
|
|
|
55
|
|
|
$form = $this->createForm(ProveYubikeyPossessionType::class, $command)->handleRequest($request); |
56
|
|
|
|
57
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
58
|
|
|
$result = $this->yubikeySecondFactorService->provePossession($command); |
59
|
|
|
|
60
|
|
|
if ($result->isSuccessful()) { |
61
|
|
|
if ($this->checkerService->emailVerificationIsRequired()) { |
62
|
|
|
return $this->redirectToRoute( |
63
|
|
|
'ss_registration_email_verification_email_sent', |
64
|
|
|
['secondFactorId' => $result->getSecondFactorId()] |
65
|
|
|
); |
66
|
|
|
} else { |
67
|
|
|
return $this->redirectToRoute( |
68
|
|
|
'ss_second_factor_vetting_types', |
69
|
|
|
['secondFactorId' => $result->getSecondFactorId()] |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} elseif ($result->isOtpInvalid()) { |
73
|
|
|
$this->addFlash('error', 'ss.verify_yubikey_command.otp.otp_invalid'); |
74
|
|
|
} elseif ($result->didOtpVerificationFail()) { |
75
|
|
|
$this->addFlash('error', 'ss.verify_yubikey_command.otp.verification_error'); |
76
|
|
|
} else { |
77
|
|
|
$this->addFlash('error', 'ss.prove_yubikey_possession.proof_of_possession_failed'); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
// OTP field is rendered empty in the template. |
82
|
|
|
return $this->render( |
83
|
|
|
'registration/yubikey/prove_possession.html.twig', |
84
|
|
|
[ |
85
|
|
|
'form' => $form->createView(), |
86
|
|
|
'verifyEmail' => $this->checkerService->emailVerificationIsRequired(), |
87
|
|
|
] |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|