33 $this->permissionMap->init();
39 if (! $reflect->isAbstract() && $reflect->isSubclassOf(Controller::class)) {
44 }
catch (\Exception $e) {
47 $this->mainResource = $annotsResource[0] ??
null;
48 $this->mainPermission = $annotsPermission[0] ??
null;
49 if (\is_array($annotAllows) && \count($annotAllows) > 0) {
50 $resource = $this->mainResource ? $this->mainResource->name : $reflect->getShortName();
51 $permission = $this->mainPermission ? $this->mainPermission->name :
'ALL';
53 $this->permissionMap->addAction(
$controllerClass,
'*', $resource, $permission);
61 $hasPermission =
false;
64 foreach ($methods as $method) {
65 $this->
parseMethod($method, $hasPermission, $controller);
67 if ($hasPermission || $this->mainResource !=
null || $this->mainPermission !=
null) {
69 $resource = $this->mainResource ? $this->mainResource->name : $controller;
70 $this->permissionMap->addAction(
$controllerClass,
'*', $resource, $this->mainPermission ? $this->mainPermission->name :
'ALL');
72 if (isset($this->mainPermission)) {
73 $permission = $this->mainPermission->name;
77 if (\is_array($annotsAllow) && \count($annotsAllow) > 0) {
78 $this->
addAllows($annotsAllow, $controller,
'*', $resource, $permission);
83 protected function parseMethod(\ReflectionMethod $method,
bool &$hasPermission, $controller) {
84 $action = $method->name;
93 $resource = $annotResource->name;
96 if ($annotPermission) {
97 if(\is_int($annotPermission->name) && $annotPermission->level===0){
98 $annotPermission->level=$annotPermission->name;
99 $annotPermission->name=
null;
101 $permission = $annotPermission->name??\strtoupper($action);
103 $hasPermission =
true;
105 $resource ??= $this->mainResource ? $this->mainResource->name : ($controller .
'.' . $action);
108 if (\is_array($annotsAllow) && \count($annotsAllow) > 0) {
109 $this->
addAllows($annotsAllow, $controller, $action, $resource, $permission);
110 $this->permissionMap->addAction(
$controllerClass, $action, $resource, $permission ??
'ALL');
111 } elseif ($permission !==
null && $resource !==
null) {
112 $this->permissionMap->addAction(
$controllerClass, $action, $resource, $permission ??
'ALL');
114 }
catch (\Exception $e) {
120 protected function addAllows($annotsAllow, $controller, $action, &$resource, &$permission) {
121 foreach ($annotsAllow as $annotAllow) {
122 if (isset($annotAllow->resource) && isset($resource) && \strpos($resource,
'.') === FALSE && $resource !== $annotAllow->resource && $permission !=
null) {
123 throw new AclException(
"Resources {$resource} and {$annotAllow->resource} are in conflict for action {$controller}.{$action}");
125 if (isset($annotAllow->permission) && isset($permission) && $permission !== $annotAllow->permission) {
126 throw new AclException(
"Permissions {$permission} and {$annotAllow->permission} are in conflict for action {$controller}.{$action}");
129 $resource = ($annotAllow->resource ?? $resource)??$controller .
'.' . $action;
130 $permission = ($annotAllow->permission ?? $permission)??\strtoupper($action);
132 if (\is_array($annotAllow->role)) {
133 foreach ($annotAllow->role as $role) {
143 $this->permissionMap->save();
Manipulates class and namespace names Ubiquity\cache$ClassUtils This class is part of Ubiquity.
static getClassSimpleName($classnameWithNamespace)
Returns the simple class name of a class, without namespace.
Base class for controllers.
Ubiquity\exceptions$AclException This class is part of Ubiquity.
Reflection utilities in dev environment only.
static getAnnotationClass($class, $annotation)
static getAnnotationMethod($class, $method, $annotation)
static getMethods($instance, $filter=null)
static getAnnotationsMethod($class, $method, $annotation)
Ubiquity\security\acl$AclManager This class is part of Ubiquity.
static saveAll()
Save all acls,roles, resources and permissions for AclProviders with no autoSave.
static addAndAllow(string $role, ?string $resource=' *', ?string $permission='ALL')
Add role, resource and permission and allow this role to access to resource with the permission.
static addPermission(string $name, int $level=0)
static addResource(string $name, ?string $value=null)
Ubiquity\security\acl\cache$AclControllerParser This class is part of Ubiquity.
addAllows($annotsAllow, $controller, $action, &$resource, &$permission)
parseMethod(\ReflectionMethod $method, bool &$hasPermission, $controller)
Ubiquity\security\acl\cache$PermissionsMap This class is part of Ubiquity.
static cacheUpdated()
Checks if ACL cache is updated.