Completed
Push — master ( 53601d...990ac1 )
by
unknown
07:37 queued 28s
created

Controller::emailVerificationIsRequired()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
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
     * @return Identity
30
     * @throws AccessDeniedException When the registrant isn't registered using a SAML token.
31
     */
32
    protected function getIdentity()
33
    {
34
        $token = $this->get('security.token_storage')->getToken();
35
        $user  = $token->getUser();
36
37
        if (!$user instanceof Identity) {
38
            $actualType = is_object($token) ? get_class($token) : gettype($token);
39
40
            throw new UnexpectedValueException(
41
                sprintf(
42
                    "Token did not contain user of type '%s', but one of type '%s'",
43
                    'Surfnet\StepupMiddlewareClientBundle\Identity\Dto\Identity',
44
                    $actualType
45
                )
46
            );
47
        }
48
49
        return $user;
50
    }
51
52
    /**
53
     * @param string $type
54
     */
55
    protected function assertSecondFactorEnabled($type)
56
    {
57
        if (!in_array($type, $this->getParameter('ss.enabled_second_factors'))) {
58
            $this->get('logger')->warning('A controller action was called for a disabled second factor');
59
60
            throw $this->createNotFoundException();
61
        }
62
    }
63
}
64