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 Symfony\Bridge\Twig\Attribute\Template; |
24
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Command\VerifyYubikeyOtpCommand; |
25
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Controller\Controller; |
26
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Form\Type\ProveYubikeyPossessionType; |
27
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\YubikeySecondFactorService; |
28
|
|
|
use Symfony\Component\Form\FormError; |
29
|
|
|
use Symfony\Component\HttpFoundation\Request; |
30
|
|
|
use Symfony\Component\Routing\Attribute\Route; |
31
|
|
|
|
32
|
|
|
class YubikeyController extends Controller |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
#[Template('registration/yubikey/prove_possession.html.twig')] |
35
|
|
|
#[Route( |
36
|
|
|
path: '/registration/yubikey/prove-possession', |
37
|
|
|
name: 'ss_registration_yubikey_prove_possession', |
38
|
|
|
methods: ['GET','POST'], |
39
|
|
|
)] |
40
|
|
|
public function provePossession(Request $request): \Symfony\Component\HttpFoundation\RedirectResponse|array |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
$this->assertSecondFactorEnabled('yubikey'); |
43
|
|
|
|
44
|
|
|
$identity = $this->getIdentity(); |
45
|
|
|
|
46
|
|
|
$command = new VerifyYubikeyOtpCommand(); |
47
|
|
|
$command->identity = $identity->id; |
48
|
|
|
$command->institution = $identity->institution; |
49
|
|
|
|
50
|
|
|
$form = $this->createForm(ProveYubikeyPossessionType::class, $command)->handleRequest($request); |
51
|
|
|
|
52
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
53
|
|
|
/** @var YubikeySecondFactorService $service */ |
|
|
|
|
54
|
|
|
$service = $this->get('surfnet_stepup_self_service_self_service.service.yubikey_second_factor'); |
|
|
|
|
55
|
|
|
$result = $service->provePossession($command); |
56
|
|
|
|
57
|
|
|
if ($result->isSuccessful()) { |
58
|
|
|
if ($this->emailVerificationIsRequired()) { |
59
|
|
|
return $this->redirectToRoute( |
60
|
|
|
'ss_registration_email_verification_email_sent', |
61
|
|
|
['secondFactorId' => $result->getSecondFactorId()] |
62
|
|
|
); |
63
|
|
|
} else { |
64
|
|
|
return $this->redirectToRoute( |
65
|
|
|
'ss_second_factor_vetting_types', |
66
|
|
|
['secondFactorId' => $result->getSecondFactorId()] |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
} elseif ($result->isOtpInvalid()) { |
70
|
|
|
$this->addFlash('error', 'ss.verify_yubikey_command.otp.otp_invalid'); |
71
|
|
|
} elseif ($result->didOtpVerificationFail()) { |
72
|
|
|
$this->addFlash('error', 'ss.verify_yubikey_command.otp.verification_error'); |
73
|
|
|
} else { |
74
|
|
|
$this->addFlash('error', 'ss.prove_yubikey_possession.proof_of_possession_failed'); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// OTP field is rendered empty in the template. |
79
|
|
|
return [ |
80
|
|
|
'form' => $form->createView(), |
81
|
|
|
'verifyEmail' => $this->emailVerificationIsRequired(), |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|