ChainedPermissionManager.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\security\impl;
12 
14 
15 /**
16  * ChainedPermissionManager retrieves authorization rules included managers.
17  *
18  * @author ingo herwig <ingo@wemove.com>
19  */
21 
22  private $managers = [];
23 
24  /**
25  * Set the PermissionManager instances to delegate to.
26  * @param $managers Array of PermissionManager instances
27  */
28  public function setManagers($managers) {
29  $this->managers = $managers;
30  }
31 
32  /**
33  * @see PermissionManager::getPermissions()
34  */
35  public function getPermissions($resource, $context, $action) {
36  foreach ($this->managers as $manager) {
37  $permissions = $manager->getPermissions($resource, $context, $action);
38  if ($permissions != null) {
39  return $permissions;
40  }
41  }
42  return null;
43  }
44 
45  /**
46  * @see PermissionManager::setPermissions()
47  */
48  public function setPermissions($resource, $context, $action, $permissions) {
49  if (sizeof($this->managers) > 0) {
50  $this->managers[0]->setPermissions($resource, $context, $action, $permissions);
51  }
52  }
53 
54  /**
55  * @see PermissionManager::createPermission()
56  */
57  public function createPermission($resource, $context, $action, $role, $modifier) {
58  if (sizeof($this->managers) > 0) {
59  $this->managers[0]->createPermission($resource, $context, $action, $role, $modifier);
60  }
61  }
62 
63  /**
64  * @see PermissionManager::removePermission()
65  */
66  public function removePermission($resource, $context, $action, $role) {
67  if (sizeof($this->managers) > 0) {
68  $this->managers[0]->removePermission($resource, $context, $action, $role);
69  }
70  }
71 }
72 ?>
setPermissions($resource, $context, $action, $permissions)
ChainedPermissionManager retrieves authorization rules included managers.
createPermission($resource, $context, $action, $role, $modifier)
removePermission($resource, $context, $action, $role)
setManagers($managers)
Set the PermissionManager instances to delegate to.
AbstractPermissionManager is the base class for concrete PermissionManager implementations.
PermissionManager implementations are used to handle all authorization requests.