|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2014 SURFnet bv |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
namespace Surfnet\StepupSelfService\SelfServiceBundle\Controller; |
|
20
|
|
|
|
|
21
|
|
|
use Psr\Log\LoggerInterface; |
|
22
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Configuration\Dto\InstitutionConfigurationOptions; |
|
23
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity; |
|
24
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\InstitutionConfigurationOptionsService; |
|
25
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
26
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
27
|
|
|
use UnexpectedValueException; |
|
28
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; |
|
29
|
|
|
|
|
30
|
|
|
class Controller extends AbstractController |
|
|
|
|
|
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Default verify email option as defined by middleware. |
|
34
|
|
|
*/ |
|
35
|
|
|
final public const DEFAULT_VERIFY_EMAIL_OPTION = true; |
|
36
|
|
|
|
|
37
|
|
|
public function __construct( |
|
|
|
|
|
|
38
|
|
|
private readonly LoggerInterface $logger, |
|
39
|
|
|
private readonly InstitutionConfigurationOptionsService $configurationOptionsService |
|
40
|
|
|
) { |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function has(string $id): bool |
|
|
|
|
|
|
44
|
|
|
{ |
|
45
|
|
|
return $this->container->has($id); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
|
|
|
|
|
49
|
|
|
* @throws AccessDeniedException When the registrant isn't registered using a SAML token. |
|
50
|
|
|
*/ |
|
|
|
|
|
|
51
|
|
|
protected function getIdentity(): Identity |
|
52
|
|
|
{ |
|
53
|
|
|
$authenticatedIdentity = $this->getUser(); |
|
54
|
|
|
// During authentication, an AuthenticatedIdentity is created, a decorated Identity. |
|
55
|
|
|
// The app wants to work with the 'regular' Identity DTO from Middleware (client bundle) |
|
56
|
|
|
// So we extract the entity here |
|
57
|
|
|
$user = $authenticatedIdentity->getIdentity(); |
|
|
|
|
|
|
58
|
|
|
if (!$user instanceof Identity) { |
|
59
|
|
|
$actualType = get_debug_type($user); |
|
60
|
|
|
|
|
61
|
|
|
throw new UnexpectedValueException( |
|
62
|
|
|
sprintf( |
|
63
|
|
|
"Token did not contain user of type '%s', but one of type '%s'", |
|
64
|
|
|
Identity::class, |
|
65
|
|
|
$actualType |
|
66
|
|
|
) |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $user; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
protected function assertSecondFactorEnabled(string $type): void |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
if (!in_array($type, $this->getParameter('ss.enabled_second_factors'))) { |
|
76
|
|
|
$this->logger->warning('A controller action was called for a disabled second factor'); |
|
77
|
|
|
|
|
78
|
|
|
throw $this->createNotFoundException(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
|
|
|
|
|
83
|
|
|
* @return bool |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function emailVerificationIsRequired(): bool |
|
86
|
|
|
{ |
|
87
|
|
|
$config = $this->configurationOptionsService |
|
88
|
|
|
->getInstitutionConfigurationOptionsFor($this->getIdentity()->institution); |
|
89
|
|
|
|
|
90
|
|
|
if (!$config instanceof InstitutionConfigurationOptions) { |
|
91
|
|
|
return self::DEFAULT_VERIFY_EMAIL_OPTION; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $config->verifyEmail; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|