Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
AclManager.php
Go to the documentation of this file.
1<?php
3
21
31
32 protected static ?AclList $aclList=null;
33
35
36 protected static array $providersPersistence;
37
38
39 public static function addRole(string $name, ?array $parents = []): void {
40 self::$aclList->addRole(new Role($name, $parents));
41 }
42
43 public static function addRoles(array $nameParents): void {
44 foreach ($nameParents as $name => $parents) {
45 self::$aclList->addRole(new Role($name, $parents));
46 }
47 }
48
49 public static function addResource(string $name, ?string $value = null): void {
50 self::$aclList->addResource(new Resource($name, $value));
51 }
52
53 public static function addResources(array $nameValue): void {
54 foreach ($nameValue as $name => $value) {
55 self::$aclList->addResource(new Resource($name, $value));
56 }
57 }
58
59 public static function addPermission(string $name, int $level = 0): void {
60 self::$aclList->addPermission(new Permission($name, $level));
61 }
62
63 public static function addPermissions(array $nameLevel): void {
64 foreach ($nameLevel as $name => $level) {
65 self::$aclList->addPermission(new Permission($name, $level));
66 }
67 }
68
69 public static function setPermissionLevel(string $name, int $level): void {
70 self::$aclList->setPermissionLevel($name, $level);
71 }
72
73 public static function getRoles(): array {
74 return self::$aclList->getRoles();
75 }
76
77 public static function getResources(): array {
78 return self::$aclList->getResources();
79 }
80
85 public static function getAclList(): ?AclList {
86 return AclManager::$aclList;
87 }
88
89 public static function getPermissions():array {
90 return self::$aclList->getPermissions();
91 }
92
93 public static function getAcls() {
94 return self::$aclList->getAcls();
95 }
96
104 public static function allow(string $role, ?string $resource = '*', ?string $permission = 'ALL'): void {
105 self::$aclList->allow($role, $resource ?? '*', $permission ?? 'ALL');
106 }
107
115 public static function addAndAllow(string $role, ?string $resource = '*', ?string $permission = 'ALL'): void {
116 self::$aclList->addAndAllow($role, $resource ?? '*', $permission ?? 'ALL');
117 }
118
127 public static function isAllowed(string $role, ?string $resource = '*', ?string $permission = 'ALL'): bool {
128 return self::$aclList->isAllowed($role, $resource ?? '*', $permission ?? 'ALL');
129 }
130
131 public static function isAllowedRoute(string $role,string $routeName): bool {
132 $routeInfo=Router::getRouteInfoByName($routeName);
133 if (!isset ( $routeInfo ['controller'] )) {
134 $routeInfo=\current($routeInfo);
135 }
136 $controller=$routeInfo['controller']??null;
137 $action=$routeInfo['action']??null;
138 if(isset($controller) && isset($action)){
139 $resourceController = self::getPermissionMap ()->getRessourcePermission ( $controller, $action );
140 if (isset ( $resourceController )) {
141 try{
142 if (self::isAllowed ( $role, $resourceController ['resource'], $resourceController ['permission'] )) {
143 return true;
144 }
145 }
146 catch(AclException $e){
147 //Nothing to do
148 }
149 }
150 return false;
151 }
152 return false;
153 }
154
158 public static function saveAll(): void {
159 self::$aclList->saveAll();
160 }
161
166 public static function removeRole(string $role): void {
167 self::$aclList->removeRole($role);
168 }
169
174 public static function removePermission(string $permission): void {
175 self::$aclList->removePermission($permission);
176 }
177
182 public static function removeResource(string $resource): void {
183 self::$aclList->removeResource($resource);
184 }
185
192 public static function removeAcl(string $role, string $resource, ?string $permission = null): void {
193 self::$aclList->removeAcl($role, $resource, $permission);
194 }
195
200 public static function getPermissionMap():PermissionsMap {
201 if (! isset(self::$permissionMap)) {
202 self::$permissionMap = new PermissionsMap();
203 self::$permissionMap->load();
204 }
205 return self::$permissionMap;
206 }
207
215 public static function associate(string $controller, string $action, string $resource, string $permission = 'ALL'):void {
216 self::$aclList->getResourceByName($resource);
217 self::$aclList->getPermissionByName($permission);
218 self::$permissionMap->addAction($controller, $action, $resource, $permission);
219 }
220}
Manager for caches (Router, Rest, models).
Manipulates class and namespace names Ubiquity\cache$ClassUtils This class is part of Ubiquity.
Ubiquity\exceptions$AclException This class is part of Ubiquity.
Ubiquity\security\acl$AclManager This class is part of Ubiquity.
static removeAcl(string $role, string $resource, ?string $permission=null)
static saveAll()
Save all acls,roles, resources and permissions for AclProviders with no autoSave.
static addRoles(array $nameParents)
static removePermission(string $permission)
static isAllowed(string $role, ?string $resource=' *', ?string $permission='ALL')
Check if access to resource is allowed for role with the permission.
static isAllowedRoute(string $role, string $routeName)
static allow(string $role, ?string $resource=' *', ?string $permission='ALL')
Allow role to access to resource with the permission.
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 removeRole(string $role)
static removeResource(string $resource)
static addResources(array $nameValue)
static addRole(string $name, ?array $parents=[])
static addPermission(string $name, int $level=0)
static associate(string $controller, string $action, string $resource, string $permission='ALL')
static addPermissions(array $nameLevel)
static setPermissionLevel(string $name, int $level)
static addResource(string $name, ?string $value=null)
static PermissionsMap $permissionMap
Ubiquity\security\acl\cache$AclControllerParser This class is part of Ubiquity.
Ubiquity\security\acl\cache$PermissionsMap This class is part of Ubiquity.
Ubiquity\security\acl\models$AbastractAclElement This class is part of Ubiquity.
Ubiquity\security\acl\models$AclElement This class is part of Ubiquity.
Ubiquity\security\acl\models$AclList This class is part of Ubiquity.
Definition AclList.php:18
Ubiquity\security\acl\models$Permission This class is part of Ubiquity.
Ubiquity\security\acl\models$Resource This class is part of Ubiquity.
Definition Resource.php:12
Ubiquity\security\acl\models$Role This class is part of Ubiquity.
Definition Role.php:12
Ubiquity\security\acl\persistence$AclCacheProvider This class is part of Ubiquity.
Load and save Acls with a database using DAO.
Ubiquity\security\acl\persistence$AclProviderInterface This class is part of Ubiquity.