Completed
Push — feature/fine-grained-authoriza... ( 3e6dd7 )
by Michiel
02:20
created

SelfServiceBundle/Controller/Controller.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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) {
0 ignored issues
show
The class Surfnet\StepupMiddleware...e\Identity\Dto\Identity does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
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