-
Notifications
You must be signed in to change notification settings - Fork 294
/
permissions.php
144 lines (141 loc) · 4.84 KB
/
permissions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* Copyright 2010 - 2019, Cake Development Corporation (https://www.cakedc.com)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2010 - 2018, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/*
* IMPORTANT:
* This is an example configuration file. Copy this file into your config directory and edit to
* setup your app permissions.
*
* This is a quick roles-permissions implementation
* Rules are evaluated top-down, first matching rule will apply
* Each line define
* [
* 'role' => 'role' | ['roles'] | '*'
* 'prefix' => 'Prefix' | , (default = null)
* 'plugin' => 'Plugin' | , (default = null)
* 'controller' => 'Controller' | ['Controllers'] | '*',
* 'action' => 'action' | ['actions'] | '*',
* 'allowed' => true | false | callback (default = true)
* ]
* You could use '*' to match anything
* 'allowed' will be considered true if not defined. It allows a callable to manage complex
* permissions, like this
* 'allowed' => function (array $user, $role, Request $request) {}
*
* Example, using allowed callable to define permissions only for the owner of the Posts to edit/delete
*
* (remember to add the 'uses' at the top of the permissions.php file for Hash, TableRegistry and Request
[
'role' => ['user'],
'controller' => ['Posts'],
'action' => ['edit', 'delete'],
'allowed' => function(array $user, $role, Request $request) {
$postId = Hash::get($request->params, 'pass.0');
$post = TableRegistry::getTableLocator()->get('Posts')->get($postId);
$userId = Hash::get($user, 'id');
if (!empty($post->user_id) && !empty($userId)) {
return $post->user_id === $userId;
}
return false;
}
],
*/
return [
'CakeDC/Auth.permissions' => [
//all bypass
[
'prefix' => false,
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => [
// LoginTrait
'socialLogin',
'login',
'logout',
'socialEmail',
'verify',
// RegisterTrait
'register',
'validateEmail',
// PasswordManagementTrait used in RegisterTrait
'changePassword',
'resetPassword',
'requestResetPassword',
// UserValidationTrait used in PasswordManagementTrait
'resendTokenValidation',
'linkSocial',
//U2F actions
'u2f',
'u2fRegister',
'u2fRegisterFinish',
'u2fAuthenticate',
'u2fAuthenticateFinish',
'webauthn2fa',
'webauthn2faRegister',
'webauthn2faRegisterOptions',
'webauthn2faAuthenticate',
'webauthn2faAuthenticateOptions',
],
'bypassAuth' => true,
],
[
'prefix' => false,
'plugin' => 'CakeDC/Users',
'controller' => 'SocialAccounts',
'action' => [
'validateAccount',
'resendValidation',
],
'bypassAuth' => true,
],
//admin role allowed to all the things
[
'role' => 'admin',
'prefix' => '*',
'extension' => '*',
'plugin' => '*',
'controller' => '*',
'action' => '*',
],
//specific actions allowed for the all roles in Users plugin
[
'role' => '*',
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => ['profile', 'logout', 'linkSocial', 'callbackLinkSocial'],
],
[
'role' => '*',
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => 'resetOneTimePasswordAuthenticator',
'allowed' => function (array $user, $role, \Cake\Http\ServerRequest $request) {
$userId = \Cake\Utility\Hash::get($request->getAttribute('params'), 'pass.0');
if (!empty($userId) && !empty($user)) {
return $userId === $user['id'];
}
return false;
}
],
//all roles allowed to Pages/display
[
'role' => '*',
'controller' => 'Pages',
'action' => 'display',
],
[
'role' => '*',
'plugin' => 'DebugKit',
'controller' => '*',
'action' => '*',
'bypassAuth' => true,
],
]
];