UserProviderAdapter::createUserFromSamlInfo()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
rs 9.4286
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace AerialShip\SamlSPBundle\Security\Core\User;
4
5
use AerialShip\SamlSPBundle\Bridge\SamlSpInfo;
6
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
7
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
8
use Symfony\Component\Security\Core\User\UserInterface;
9
use Symfony\Component\Security\Core\User\UserProviderInterface;
10
11
class UserProviderAdapter implements UserManagerInterface
12
{
13
    /** @var \Symfony\Component\Security\Core\User\UserProviderInterface  */
14
    protected $userProvider;
15
16
17
18
    function __construct(UserProviderInterface $userProvider)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
19
    {
20
        $this->userProvider = $userProvider;
21
    }
22
23
24
    /**
25
     * @param SamlSpInfo $samlInfo
26
     * @return UserInterface
27
     * @throws UsernameNotFoundException if the user is not found
28
     */
29
    public function loadUserBySamlInfo(SamlSpInfo $samlInfo)
30
    {
31
        if ($this->userProvider instanceof UserManagerInterface) {
32
            return $this->userProvider->loadUserBySamlInfo($samlInfo);
33
        } else {
34
            return $this->loadUserByUsername($samlInfo->getNameID()->getValue());
35
        }
36
    }
37
38
    /**
39
     * @param SamlSpInfo $samlInfo
40
     * @throws \Symfony\Component\Security\Core\Exception\UsernameNotFoundException if the user could not created
41
     * @return \Symfony\Component\Security\Core\User\UserInterface
42
     */
43
    public function createUserFromSamlInfo(SamlSpInfo $samlInfo)
44
    {
45
        if ($this->userProvider instanceof UserManagerInterface) {
46
            return $this->userProvider->createUserFromSamlInfo($samlInfo);
47
        } else {
48
            throw new UsernameNotFoundException('Manager does not support creation of users');
49
        }
50
    }
51
52
    /**
53
     * Loads the user for the given username.
54
     *
55
     * This method must throw UsernameNotFoundException if the user is not
56
     * found.
57
     *
58
     * @param string $username The username
59
     *
60
     * @return UserInterface
61
     *
62
     * @see UsernameNotFoundException
63
     *
64
     * @throws UsernameNotFoundException if the user is not found
65
     *
66
     */
67
    public function loadUserByUsername($username)
68
    {
69
        return $this->userProvider->loadUserByUsername($username);
70
    }
71
72
    /**
73
     * Refreshes the user for the account interface.
74
     *
75
     * It is up to the implementation to decide if the user data should be
76
     * totally reloaded (e.g. from the database), or if the UserInterface
77
     * object can just be merged into some internal array of users / identity
78
     * map.
79
     * @param UserInterface $user
80
     *
81
     * @return UserInterface
82
     *
83
     * @throws UnsupportedUserException if the account is not supported
84
     */
85
    public function refreshUser(UserInterface $user)
86
    {
87
        return $this->userProvider->refreshUser($user);
88
    }
89
90
    /**
91
     * Whether this provider supports the given user class
92
     *
93
     * @param string $class
94
     *
95
     * @return Boolean
96
     */
97
    public function supportsClass($class)
98
    {
99
        return $this->userProvider->supportsClass($class);
100
    }
101
}
102