1 | <?php |
||
23 | class KeycloakRoles |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @var array a list of roles associated with the realm |
||
28 | */ |
||
29 | protected $realmAccess = []; |
||
30 | /** |
||
31 | * @var array An associative array of KeycloakResourceRoles keyed by resource name |
||
32 | */ |
||
33 | protected $resourcesAndRoles = []; |
||
34 | |||
35 | /** |
||
36 | * KeycloakRoles constructor. |
||
37 | * |
||
38 | * @param $obj Object from JWT::decode |
||
39 | * |
||
40 | */ |
||
41 | 6 | public function __construct($obj) |
|
42 | { |
||
43 | 6 | if (isset($obj->realm_access->roles)) { |
|
44 | 2 | $this->realmAccess = $obj->realm_access->roles; |
|
45 | } |
||
46 | 6 | if (isset($obj->resource_access)) { |
|
47 | 2 | foreach ($obj->resource_access as $resource => $roles) { |
|
48 | 2 | $list = []; |
|
49 | 2 | foreach ($roles->roles as $role) { |
|
50 | 2 | $list[] = $role; |
|
51 | } |
||
52 | 2 | $resourceRoles = new KeycloakResourceRoles($resource, $list); |
|
53 | 2 | $this->resourcesAndRoles[$resource] = $resourceRoles; |
|
54 | } |
||
55 | } |
||
56 | 6 | } |
|
57 | |||
58 | public function hasResourceNamed($name) |
||
62 | |||
63 | 6 | public function getResourceNamesFound() |
|
67 | |||
68 | public function hasRealmRoleNamed($name) |
||
72 | |||
73 | 6 | public function getRealmRoles() |
|
77 | |||
78 | /** |
||
79 | * @param $name |
||
80 | * @return KeyCloakResourceRoles |
||
81 | */ |
||
82 | 2 | public function getRolesOfResourceNamed($name) |
|
86 | } |
||
87 |