KuleuvenUserToken::getProviderKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Kuleuven\AuthenticationBundle\Security;
4
5
use Kuleuven\AuthenticationBundle\Traits\ShibbolethAttributesResolverTrait;
6
use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
7
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
8
use Symfony\Component\Security\Core\User\UserInterface;
9
10
class KuleuvenUserToken extends AbstractToken implements TokenInterface
11
{
12
    use ShibbolethAttributesResolverTrait;
13
14
    protected $providerKey;
15
16
    public function __construct($user = null, array $attributes = [], $providerKey, array $roles = [])
17
    {
18
        $this->setUser($user);
19
20
        $this->setAttributes($attributes);
21
22
        $this->providerKey = $providerKey;
23
24
        if (empty($roles) && $user instanceof UserInterface) {
25
            $roles = $user->getRoles();
26
        }
27
        if ($this->isStudent()) {
28
            $roles[] = 'ROLE_STUDENT';
29
        }
30
        if ($this->isEmployee()) {
31
            $roles[] = 'ROLE_EMPLOYEE';
32
        }
33
        if ($this->isFaculty()) {
34
            $roles[] = 'ROLE_FACULTY';
35
        }
36
        if ($this->isMember()) {
37
            $roles[] = 'ROLE_MEMBER';
38
        }
39
        if ($this->isStaff()) {
40
            $roles[] = 'ROLE_STAFF';
41
        }
42
        parent::__construct($roles);
43
    }
44
45
    public function getCredentials()
46
    {
47
        return '';
48
    }
49
50
    public function getProviderKey()
51
    {
52
        return $this->providerKey;
53
    }
54
}
55