Completed
Push — feature/EVO-6305_worker_authen... ( 500766...23d108 )
by Bastian
61:47
created

SecurityToken::hasRole()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 17
rs 9.2
c 1
b 0
f 0
cc 4
eloc 9
nc 6
nop 1
1
<?php
2
/**
3
 * Enhanced PreAuthenticatedToken
4
 */
5
6
namespace Graviton\SecurityBundle\Authentication\Token;
7
8
use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken;
9
use Symfony\Component\Security\Core\Role\Role;
10
11
/**
12
 * Class SecurityToken
13
 *
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class SecurityToken extends PreAuthenticatedToken
19
{
20
    /**
21
     * Determines the token has the provided role.
22
     *
23
     * @param Role|string $role Role to be checked.
24
     *
25
     * @return boolean
26
     */
27
    public function hasRole($role)
28
    {
29
        $inList = false;
30
31
        if (is_string($role)) {
32
            $role = new Role($role);
33
        }
34
35
        foreach ($this->getRoles() as $listedRole) {
36
            if ($role->getRole() === $listedRole->getRole()) {
37
                $inList = true;
38
                break;
39
            }
40
        }
41
42
        return $inList;
43
    }
44
}
45