1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Copyright 2023 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
|
|
|
|
22
|
|
|
namespace Surfnet\StepupSelfService\SelfServiceBundle\Service; |
23
|
|
|
|
24
|
|
|
use Psr\Log\LoggerInterface; |
25
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Configuration\Dto\InstitutionConfigurationOptions; |
26
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
27
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
28
|
|
|
use Symfony\Bundle\SecurityBundle\Security; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* This class is a generic checker service to replace the two methods |
32
|
|
|
* before in the Controller class. |
33
|
|
|
* This makes the functions injectable instead of extendable. |
34
|
|
|
*/ |
|
|
|
|
35
|
|
|
|
36
|
|
|
class ControllerCheckerService |
37
|
|
|
{ |
38
|
|
|
final public const DEFAULT_VERIFY_EMAIL_OPTION = true; |
39
|
|
|
|
40
|
|
|
public function __construct( |
|
|
|
|
41
|
|
|
private readonly LoggerInterface $logger, |
42
|
|
|
private readonly InstitutionConfigurationOptionsService $configurationOptionsService, |
43
|
|
|
private readonly ParameterBagInterface $parameters, |
44
|
|
|
private readonly Security $security |
45
|
|
|
) { |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function assertSecondFactorEnabled(string $type): void |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$enabledSecondFactors = $this->parameters->get('ss.enabled_second_factors'); |
51
|
|
|
|
52
|
|
|
if (!in_array($type, $enabledSecondFactors)) { |
53
|
|
|
$this->logger->warning('A controller action was called for a disabled second factor'); |
54
|
|
|
|
55
|
|
|
throw new NotFoundHttpException(); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function emailVerificationIsRequired(): bool |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$config = $this->configurationOptionsService |
62
|
|
|
->getInstitutionConfigurationOptionsFor( |
63
|
|
|
$this->security->getUser()->getIdentity()->institution |
|
|
|
|
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
if (!$config instanceof InstitutionConfigurationOptions) { |
67
|
|
|
return self::DEFAULT_VERIFY_EMAIL_OPTION; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $config->verifyEmail; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|