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 Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity; |
22
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller as FrameworkController; |
23
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
24
|
|
|
use UnexpectedValueException; |
25
|
|
|
|
26
|
|
|
class Controller extends FrameworkController |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Default verify email option as defined by middleware. |
30
|
|
|
*/ |
31
|
|
|
const DEFAULT_VERIFY_EMAIL_OPTION = true; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @return Identity |
35
|
|
|
* @throws AccessDeniedException When the registrant isn't registered using a SAML token. |
36
|
|
|
*/ |
37
|
|
|
protected function getIdentity() |
38
|
|
|
{ |
39
|
|
|
$token = $this->get('security.token_storage')->getToken(); |
40
|
|
|
$user = $token->getUser(); |
41
|
|
|
|
42
|
|
|
if (!$user instanceof Identity) { |
43
|
|
|
$actualType = is_object($token) ? get_class($token) : gettype($token); |
44
|
|
|
|
45
|
|
|
throw new UnexpectedValueException( |
46
|
|
|
sprintf( |
47
|
|
|
"Token did not contain user of type '%s', but one of type '%s'", |
48
|
|
|
'Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity', |
49
|
|
|
$actualType |
50
|
|
|
) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $user; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $type |
59
|
|
|
*/ |
60
|
|
|
protected function assertSecondFactorEnabled($type) |
61
|
|
|
{ |
62
|
|
|
if (!in_array($type, $this->getParameter('ss.enabled_second_factors'))) { |
63
|
|
|
$this->get('logger')->warning('A controller action was called for a disabled second factor'); |
64
|
|
|
|
65
|
|
|
throw $this->createNotFoundException(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
protected function emailVerificationIsRequired() |
73
|
|
|
{ |
74
|
|
|
$config = $this->get('self_service.service.institution_configuration_options') |
75
|
|
|
->getInstitutionConfigurationOptionsFor($this->getIdentity()->institution); |
76
|
|
|
|
77
|
|
|
if ($config === null) { |
78
|
|
|
return self::DEFAULT_VERIFY_EMAIL_OPTION; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $config->verifyEmail; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|