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; |
22
|
|
|
|
23
|
|
|
use Psr\Log\LoggerInterface; |
24
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Configuration\Dto\InstitutionConfigurationOptions; |
25
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity; |
26
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\InstitutionConfigurationOptionsService; |
27
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
28
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
29
|
|
|
use UnexpectedValueException; |
30
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
31
|
|
|
|
32
|
|
|
class Controller extends AbstractController |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Default verify email option as defined by middleware. |
36
|
|
|
*/ |
37
|
|
|
final public const DEFAULT_VERIFY_EMAIL_OPTION = true; |
38
|
|
|
|
39
|
|
|
public function __construct( |
|
|
|
|
40
|
|
|
private readonly LoggerInterface $logger, |
41
|
|
|
private readonly InstitutionConfigurationOptionsService $configurationOptionsService |
42
|
|
|
) { |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function getIdentity(): Identity |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
// During authentication, an AuthenticatedIdentity is created, a decorated Identity. |
48
|
|
|
// The app wants to work with the 'regular' Identity DTO from Middleware (client bundle) |
49
|
|
|
// So we extract the entity here |
50
|
|
|
|
51
|
|
|
return $this->getUser()->getIdentity(); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function assertSecondFactorEnabled(string $type): void |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
if (!in_array($type, $this->getParameter('ss.enabled_second_factors'))) { |
57
|
|
|
$this->logger->warning('A controller action was called for a disabled second factor'); |
58
|
|
|
|
59
|
|
|
throw $this->createNotFoundException(); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function emailVerificationIsRequired(): bool |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$config = $this->configurationOptionsService |
66
|
|
|
->getInstitutionConfigurationOptionsFor($this->getIdentity()->institution); |
67
|
|
|
|
68
|
|
|
if (!$config instanceof InstitutionConfigurationOptions) { |
69
|
|
|
return self::DEFAULT_VERIFY_EMAIL_OPTION; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return $config->verifyEmail; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|