PermissionManager.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 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;
12 
14 
15 /**
16  * PermissionManager implementations are used to handle all authorization
17  * requests. PermissionManager instances are configured with an AuthUser
18  * instance, against which authorization requests are processed.
19  *
20  * @author ingo herwig <ingo@wemove.com>
21  */
22 interface PermissionManager {
23 
26 
27  /**
28  * Authorize for given resource, context, action triple.
29  * A resource could be one of the following:
30  * - Controller class name (e.g. `wcmf\application\controller\SaveController`)
31  * - Type name (e.g. `app.src.model.wcmf.User`)
32  * - Type and propery name (e.g. `app.src.model.wcmf.User.login`)
33  * - Object id (e.g. `app.src.model.wcmf.User:123`)
34  * - Object id and propery name (e.g. `app.src.model.wcmf.User:123.login`)
35  *
36  * @param $resource The resource to authorize (e.g. class name of the Controller or ObjectId instance).
37  * @param $context The context in which the action takes place.
38  * @param $action The action to process.
39  * @param $user User instance to use for authorization (optional, default: the user obtained by Session::getAuthUser method)
40  * @return Boolean whether authorization succeeded/failed.
41  */
42  public function authorize($resource, $context, $action, User $user=null);
43 
44  /**
45  * Add a temporary permission for the current user. The permission
46  * is valid only until end of execution or a call to
47  * PermissionManager::removeTempPermission() or PermissionManager::clearTempPermissions().
48  * @param $resource The resource to authorize (e.g. class name of the Controller or ObjectId).
49  * @param $context The context in which the action takes place.
50  * @param $action The action to process.
51  */
52  public function addTempPermission($resource, $context, $action);
53 
54  /**
55  * Remove a temporary permission for the current user.
56  * @param $resource The resource to authorize (e.g. class name of the Controller or ObjectId).
57  * @param $context The context in which the action takes place.
58  * @param $action The action to process.
59  */
60  public function removeTempPermission($resource, $context, $action);
61 
62  /**
63  * Check if a temporary permission for the current user exists.
64  * @param $resource The resource to authorize (e.g. class name of the Controller or ObjectId).
65  * @param $context The context in which the action takes place.
66  * @param $action The action to process.
67  * @return Boolean
68  */
69  public function hasTempPermission($resource, $context, $action);
70 
71  /**
72  * Reset all temporary permissions
73  */
74  public function clearTempPermissions();
75 
76  /**
77  * Permission management
78  */
79 
80  /**
81  * Get the permissions on a resource, context, action combination.
82  * @param $resource The resource (e.g. class name of the Controller or ObjectId).
83  * @param $context The context in which the action takes place.
84  * @param $action The action to process.
85  * @return Assoziative array with keys 'default' (boolean) and 'allow', 'deny'
86  * (arrays of role names) or null, if no permissions are defined.
87  */
88  public function getPermissions($resource, $context, $action);
89 
90  /**
91  * Set the permissions on a resource, context, action combination.
92  * @param $resource The resource (e.g. class name of the Controller or ObjectId).
93  * @param $context The context in which the action takes place.
94  * @param $action The action to process.
95  * @param $permissions Assoziative array with keys 'default' (boolean) and
96  * 'allow', 'deny' (arrays of role names) or null if all permissions should be deleted.
97  */
98  public function setPermissions($resource, $context, $action, $permissions);
99 
100  /**
101  * Create/Change a permission for a role on a resource, context, action combination.
102  * @param $resource The resource (e.g. class name of the Controller or ObjectId).
103  * @param $context The context in which the action takes place.
104  * @param $action The action to process.
105  * @param $role The role to authorize.
106  * @param $modifier One of the PERMISSION_MODIFIER constants.
107  * @return Boolean whether creation succeded/failed.
108  */
109  public function createPermission($resource, $context, $action, $role, $modifier);
110 
111  /**
112  * Remove a role from a permission on a resource, context, action combination.
113  * @param $resource The resource (e.g. class name of the Controller or ObjectId).
114  * @param $context The context in which the action takes place.
115  * @param $action The action to process.
116  * @param $role The role to remove.
117  * @return Boolean whether removal succeded/failed.
118  */
119  public function removePermission($resource, $context, $action, $role);
120 }
121 ?>
Security related interfaces and classes.
Definition: namespaces.php:83
removePermission($resource, $context, $action, $role)
Remove a role from a permission on a resource, context, action combination.
hasTempPermission($resource, $context, $action)
Check if a temporary permission for the current user exists.
User is the interface for users.
Definition: User.php:18
authorize($resource, $context, $action, User $user=null)
Authorize for given resource, context, action triple.
clearTempPermissions()
Reset all temporary permissions.
getPermissions($resource, $context, $action)
Permission management.
createPermission($resource, $context, $action, $role, $modifier)
Create/Change a permission for a role on a resource, context, action combination. ...
addTempPermission($resource, $context, $action)
Add a temporary permission for the current user.
PermissionManager implementations are used to handle all authorization requests.
removeTempPermission($resource, $context, $action)
Remove a temporary permission for the current user.
setPermissions($resource, $context, $action, $permissions)
Set the permissions on a resource, context, action combination.