1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* RBAC implementation for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-rbac |
6
|
|
|
* @package hipanel-rbac |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2016-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\rbac; |
12
|
|
|
|
13
|
|
|
use yii\rbac\RuleFactory; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* HiPanel AuthManager. |
17
|
|
|
* |
18
|
|
|
* @author Andrii Vasyliev <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class AuthManager extends \yii\rbac\PhpManager |
21
|
|
|
{ |
22
|
|
|
use SetterTrait; |
23
|
|
|
|
24
|
|
|
public function __construct() |
25
|
|
|
{ |
26
|
|
|
if (class_exists('Yii')) { |
27
|
|
|
parent::init(); |
28
|
|
|
} else { |
29
|
|
|
$dir = __DIR__ . '/files'; |
30
|
|
|
parent::__construct($dir, new RuleFactory); |
|
|
|
|
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* We don't keep all the assignments, only persistent. |
36
|
|
|
* @see persistAssignments |
37
|
|
|
*/ |
38
|
|
|
protected function saveAssignments() |
39
|
|
|
{ |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Does real assignments saving. |
44
|
|
|
* The idea is to split persistent assignments from session only. |
45
|
|
|
*/ |
46
|
|
|
public function persistAssignments() |
47
|
|
|
{ |
48
|
|
|
parent::saveAssignments(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function checkAccess($userId, $permission, $params = []) |
52
|
|
|
{ |
53
|
|
|
if (empty($this->getAssignments($userId))) { |
54
|
|
|
$this->applyUserAssignments($userId); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return parent::checkAccess($userId, $permission, $params) |
58
|
|
|
&& !parent::checkAccess($userId, "deny:$permission", $params); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function applyUserAssignments($userId) |
62
|
|
|
{ |
63
|
|
|
$roles = ''; |
64
|
|
|
|
65
|
|
|
if (isset($this->getApp()->user)) { |
66
|
|
|
$user = $this->getApp()->user->identity; |
67
|
|
|
if ((!$user || $user->id !== $userId) && $userId) { |
|
|
|
|
68
|
|
|
$user = call_user_func([$this->getApp()->user->identityClass, 'findIdentity'], $userId); |
69
|
|
|
} |
70
|
|
|
if (isset($user->roles)) { |
71
|
|
|
$roles = $user->roles; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if (empty($userId)) { |
76
|
|
|
$userId = ''; |
77
|
|
|
$roles = 'role:unauthorized'; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if ($roles) { |
81
|
|
|
$this->setAssignments($roles, $userId); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
protected function getApp() |
86
|
|
|
{ |
87
|
|
|
return class_exists('Yii') ? \Yii::$app : \yii\helpers\Yii::getApp(); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths