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 hiqdev\yii\compat\yii; |
14
|
|
|
use yii\rbac\RuleFactory; |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* HiPanel AuthManager. |
18
|
|
|
* |
19
|
|
|
* @author Andrii Vasyliev <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class AuthManager extends \yii\rbac\PhpManager |
22
|
|
|
{ |
23
|
|
|
use SetterTrait; |
24
|
|
|
|
25
|
|
|
public $itemFile = '@hipanel/rbac/files/items.php'; |
26
|
|
|
public $ruleFile = '@hipanel/rbac/files/rules.php'; |
27
|
|
|
public $assignmentFile = '@hipanel/rbac/files/assignments.php'; |
28
|
|
|
|
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
if (yii::is2()) { |
32
|
|
|
parent::init(); |
33
|
|
|
} else { |
34
|
|
|
$dir = __DIR__ . '/files'; |
35
|
|
|
parent::__construct($dir, new RuleFactory); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* We don't keep all the assignments, only persistent. |
41
|
|
|
* @see persistAssignments |
42
|
|
|
*/ |
43
|
|
|
protected function saveAssignments() |
44
|
|
|
{ |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Does real assignments saving. |
49
|
|
|
* The idea is to split persistent assignments from session only. |
50
|
|
|
*/ |
51
|
|
|
public function persistAssignments() |
52
|
|
|
{ |
53
|
|
|
parent::saveAssignments(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function checkAccess($userId, $permission, $params = []) |
57
|
|
|
{ |
58
|
|
|
if (empty($this->getAssignments($userId))) { |
59
|
|
|
$this->applyUserAssignments($userId); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return parent::checkAccess($userId, $permission, $params) |
63
|
|
|
&& !parent::checkAccess($userId, "deny:$permission", $params); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function applyUserAssignments($userId) |
67
|
|
|
{ |
68
|
|
|
$roles = ''; |
69
|
|
|
|
70
|
|
|
if (isset(yii::getApp()->user)) { |
71
|
|
|
$user = yii::getApp()->user->identity; |
72
|
|
|
if ((!$user || $user->id !== $userId) && $userId) { |
|
|
|
|
73
|
|
|
$user = call_user_func([yii::getApp()->user->identityClass, 'findIdentity'], $userId); |
74
|
|
|
} |
75
|
|
|
if (isset($user->roles)) { |
76
|
|
|
$roles = $user->roles; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if (empty($userId)) { |
81
|
|
|
$userId = ''; |
82
|
|
|
$roles = 'role:unauthorized'; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
if ($roles) { |
86
|
|
|
$this->setAssignments($roles, $userId); |
87
|
|
|
} |
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