AuthorizeService.php 2.17 KB
Newer Older
1
2
3
4
<?php
/**
 * BjyAuthorize Module (https://github.com/bjyoungblood/BjyAuthorize)
 *
5
 * @link    https://github.com/bjyoungblood/BjyAuthorize for the canonical source repository
6
7
8
9
 * @license http://framework.zend.com/license/new-bsd New BSD License
 */

namespace UnicaenAuth\Service;
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use UnicaenAuth\Service\Traits\UserContextServiceAwareTrait;

/**
 * Authorize service
 *
 * @author Laurent LÉCLUSE <laurent.lecluse at unicaen.fr>
 */
class AuthorizeService extends \BjyAuthorize\Service\Authorize
{
    use UserContextServiceAwareTrait;

    /**
     * Loading...
     *
     * @var boolean
     */
    protected $loading;


    /**
     * @deprecated this method will be removed in BjyAuthorize 1.4.x+,
     *             please retrieve the identity from the
     *             `BjyAuthorize\Provider\Identity\ProviderInterface` service
     *
     * @return string
     */
    public function getIdentity()
    {
        $this->loaded && $this->loaded->__invoke();
        if ($this->loading) return 'bjyauthorize-identity';
41

42
43
44
45
46
47
48
49
50
51
52
53
        // on retourne par défaut le rôle sélectionné
        $role = $this->getServiceUserContext()->getSelectedIdentityRole();
        if ($role) return $role;

        $roles = $this->getIdentityProvider()->getIdentityRoles();
        // sinon, si on est uniquement authentifié et que user est défini, on retourne le rôle user
        if (isset($roles['user'])) return $roles['user'];
        // sinon, si guest est défini alors on retourne guest
        if (isset($roles['guest'])) return $roles['guest'];

        // sinon rien du tout!!
        return null;
54
55
    }

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75


    /**
     * Retourne la liste des rôles fournis par l'ensemble des providers
     */
    public function getRoles()
    {
        $roles = [];
        foreach ($this->roleProviders as $provider) {
            $r = $provider->getRoles();
            foreach ($r as $role) {
                $roles[$role->getRoleId()] = $role;
            }
        }

        return $roles;
    }



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
    /**
     * Initializes the service
     *
     * @internal
     *
     * @return void
     */
    public function load()
    {
        $this->loading = true;
        parent::load();
        $this->loading = false;
    }

}