|
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\YubikeySecondFactorService; |
|
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 YubikeySecondFactorService $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
|
|
|
|
|
59
|
|
|
$result = $this->yubikeySecondFactorService->provePossession($command); |
|
60
|
|
|
|
|
61
|
|
|
if ($result->isSuccessful()) { |
|
62
|
|
|
if ($this->checkerService->emailVerificationIsRequired()) { |
|
63
|
|
|
return $this->redirectToRoute( |
|
64
|
|
|
'ss_registration_email_verification_email_sent', |
|
65
|
|
|
['secondFactorId' => $result->getSecondFactorId()] |
|
66
|
|
|
); |
|
67
|
|
|
} else { |
|
68
|
|
|
return $this->redirectToRoute( |
|
69
|
|
|
'ss_second_factor_vetting_types', |
|
70
|
|
|
['secondFactorId' => $result->getSecondFactorId()] |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
} elseif ($result->isOtpInvalid()) { |
|
74
|
|
|
$this->addFlash('error', 'ss.verify_yubikey_command.otp.otp_invalid'); |
|
75
|
|
|
} elseif ($result->didOtpVerificationFail()) { |
|
76
|
|
|
$this->addFlash('error', 'ss.verify_yubikey_command.otp.verification_error'); |
|
77
|
|
|
} else { |
|
78
|
|
|
$this->addFlash('error', 'ss.prove_yubikey_possession.proof_of_possession_failed'); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// OTP field is rendered empty in the template. |
|
83
|
|
|
return $this->render( |
|
84
|
|
|
'registration/yubikey/prove_possession.html.twig', |
|
85
|
|
|
[ |
|
86
|
|
|
'form' => $form->createView(), |
|
87
|
|
|
'verifyEmail' => $this->checkerService->emailVerificationIsRequired(), |
|
88
|
|
|
]); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|