1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Casbin; |
6
|
|
|
|
7
|
|
|
use Casbin\Constant\Constants; |
8
|
|
|
use Closure; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* ManagementEnforcer = InternalEnforcer + Management API. |
12
|
|
|
* |
13
|
|
|
* @author [email protected] |
|
|
|
|
14
|
|
|
*/ |
|
|
|
|
15
|
|
|
class ManagementEnforcer extends InternalEnforcer |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Gets the list of subjects that show up in the current policy. |
19
|
|
|
* |
20
|
|
|
* @return array |
21
|
|
|
*/ |
22
|
9 |
|
public function getAllSubjects(): array |
23
|
|
|
{ |
24
|
9 |
|
return $this->model->getValuesForFieldInPolicyAllTypesByName('p', Constants::SUBJECT_INDEX); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Gets the list of subjects that show up in the current named policy. |
29
|
|
|
* |
30
|
|
|
* @param string $ptype |
|
|
|
|
31
|
|
|
* |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
3 |
|
public function getAllNamedSubjects(string $ptype): array |
35
|
|
|
{ |
36
|
3 |
|
$fieldIndex = $this->model->getFieldIndex('p', Constants::SUBJECT_INDEX); |
37
|
3 |
|
return $this->model->getValuesForFieldInPolicy('p', $ptype, $fieldIndex); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Gets the list of objects that show up in the current policy. |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
6 |
|
public function getAllObjects(): array |
46
|
|
|
{ |
47
|
6 |
|
return $this->model->getValuesForFieldInPolicyAllTypesByName('p', Constants::OBJECT_INDEX); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Gets the list of objects that show up in the current named policy. |
52
|
|
|
* |
53
|
|
|
* @param string $ptype |
|
|
|
|
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
3 |
|
public function getAllNamedObjects(string $ptype): array |
58
|
|
|
{ |
59
|
3 |
|
$fieldIndex = $this->model->getFieldIndex('p', Constants::OBJECT_INDEX); |
60
|
3 |
|
return $this->model->getValuesForFieldInPolicy('p', $ptype, $fieldIndex); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Gets the list of actions that show up in the current policy. |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
6 |
|
public function getAllActions(): array |
69
|
|
|
{ |
70
|
6 |
|
return $this->model->getValuesForFieldInPolicyAllTypesByName('p', Constants::ACTION_INDEX); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Gets the list of actions that show up in the current named policy. |
75
|
|
|
* |
76
|
|
|
* @param string $ptype |
|
|
|
|
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
3 |
|
public function getAllNamedActions(string $ptype): array |
81
|
|
|
{ |
82
|
3 |
|
$fieldIndex = $this->model->getFieldIndex('p', Constants::ACTION_INDEX); |
83
|
3 |
|
return $this->model->getValuesForFieldInPolicy('p', $ptype, $fieldIndex); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Gets the list of roles that show up in the current policy. |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
6 |
|
public function getAllRoles(): array |
92
|
|
|
{ |
93
|
6 |
|
return $this->model->getValuesForFieldInPolicyAllTypes('g', 1); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Gets the list of roles that show up in the current named policy. |
98
|
|
|
* |
99
|
|
|
* @param string $ptype |
|
|
|
|
100
|
|
|
* |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
3 |
|
public function getAllNamedRoles(string $ptype): array |
104
|
|
|
{ |
105
|
3 |
|
return $this->model->getValuesForFieldInPolicy('g', $ptype, 1); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Gets all the authorization rules in the policy. |
110
|
|
|
* |
111
|
|
|
* @return array |
112
|
|
|
*/ |
113
|
12 |
|
public function getPolicy(): array |
114
|
|
|
{ |
115
|
12 |
|
return $this->getNamedPolicy('p'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Gets all the authorization rules in the policy, field filters can be specified. |
120
|
|
|
* |
121
|
|
|
* @param int $fieldIndex |
|
|
|
|
122
|
|
|
* @param string ...$fieldValues |
|
|
|
|
123
|
|
|
* |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
18 |
|
public function getFilteredPolicy(int $fieldIndex, string ...$fieldValues): array |
127
|
|
|
{ |
128
|
18 |
|
return $this->getFilteredNamedPolicy('p', $fieldIndex, ...$fieldValues); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Gets all the authorization rules in the named policy. |
133
|
|
|
* |
134
|
|
|
* @param string $ptype |
|
|
|
|
135
|
|
|
* |
136
|
|
|
* @return array |
137
|
|
|
*/ |
138
|
12 |
|
public function getNamedPolicy(string $ptype): array |
139
|
|
|
{ |
140
|
12 |
|
return $this->model->getPolicy('p', $ptype); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Gets all the authorization rules in the named policy, field filters can be specified. |
145
|
|
|
* |
146
|
|
|
* @param string $ptype |
|
|
|
|
147
|
|
|
* @param int $fieldIndex |
|
|
|
|
148
|
|
|
* @param string ...$fieldValues |
|
|
|
|
149
|
|
|
* |
150
|
|
|
* @return array |
151
|
|
|
*/ |
152
|
18 |
|
public function getFilteredNamedPolicy(string $ptype, int $fieldIndex, string ...$fieldValues): array |
153
|
|
|
{ |
154
|
18 |
|
return $this->model->getFilteredPolicy('p', $ptype, $fieldIndex, ...$fieldValues); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Gets all the role inheritance rules in the policy. |
159
|
|
|
* |
160
|
|
|
* @return array |
161
|
|
|
*/ |
162
|
9 |
|
public function getGroupingPolicy(): array |
163
|
|
|
{ |
164
|
9 |
|
return $this->getNamedGroupingPolicy('g'); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Gets all the role inheritance rules in the policy, field filters can be specified. |
169
|
|
|
* |
170
|
|
|
* @param int $fieldIndex |
|
|
|
|
171
|
|
|
* @param string ...$fieldValues |
|
|
|
|
172
|
|
|
* |
173
|
|
|
* @return array |
174
|
|
|
*/ |
175
|
3 |
|
public function getFilteredGroupingPolicy(int $fieldIndex, string ...$fieldValues): array |
176
|
|
|
{ |
177
|
3 |
|
return $this->getFilteredNamedGroupingPolicy('g', $fieldIndex, ...$fieldValues); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Gets all the role inheritance rules in the policy. |
182
|
|
|
* |
183
|
|
|
* @param string $ptype |
|
|
|
|
184
|
|
|
* |
185
|
|
|
* @return array |
186
|
|
|
*/ |
187
|
9 |
|
public function getNamedGroupingPolicy(string $ptype): array |
188
|
|
|
{ |
189
|
9 |
|
return $this->model->getPolicy('g', $ptype); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Gets all the role inheritance rules in the policy, field filters can be specified. |
194
|
|
|
* |
195
|
|
|
* @param string $ptype |
|
|
|
|
196
|
|
|
* @param int $fieldIndex |
|
|
|
|
197
|
|
|
* @param string ...$fieldValues |
|
|
|
|
198
|
|
|
* |
199
|
|
|
* @return array |
200
|
|
|
*/ |
201
|
3 |
|
public function getFilteredNamedGroupingPolicy(string $ptype, int $fieldIndex, string ...$fieldValues): array |
202
|
|
|
{ |
203
|
3 |
|
return $this->model->getFilteredPolicy('g', $ptype, $fieldIndex, ...$fieldValues); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Determines whether an authorization rule exists. |
208
|
|
|
* |
209
|
|
|
* @param mixed ...$params |
|
|
|
|
210
|
|
|
* |
211
|
|
|
* @return bool |
212
|
|
|
*/ |
213
|
27 |
|
public function hasPolicy(...$params): bool |
214
|
|
|
{ |
215
|
27 |
|
return $this->hasNamedPolicy('p', ...$params); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Determines whether a named authorization rule exists. |
220
|
|
|
* |
221
|
|
|
* @param string $ptype |
|
|
|
|
222
|
|
|
* @param mixed ...$params |
|
|
|
|
223
|
|
|
* |
224
|
|
|
* @return bool |
225
|
|
|
*/ |
226
|
27 |
|
public function hasNamedPolicy(string $ptype, ...$params): bool |
227
|
|
|
{ |
228
|
27 |
|
if (1 == count($params) && is_array($params[0])) { |
229
|
6 |
|
$params = $params[0]; |
230
|
|
|
} |
231
|
|
|
|
232
|
27 |
|
return $this->model->hasPolicy('p', $ptype, $params); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* AddPolicy adds an authorization rule to the current policy. |
237
|
|
|
* If the rule already exists, the function returns false and the rule will not be added. |
238
|
|
|
* Otherwise the function returns true by adding the new rule. |
239
|
|
|
* |
240
|
|
|
* @param mixed ...$params |
|
|
|
|
241
|
|
|
* |
242
|
|
|
* @return bool |
243
|
|
|
*/ |
244
|
21 |
|
public function addPolicy(...$params): bool |
245
|
|
|
{ |
246
|
21 |
|
return $this->addNamedPolicy('p', ...$params); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* AddPolicies adds authorization rules to the current policy. |
251
|
|
|
* If the rule already exists, the function returns false for the corresponding rule and the rule will not be added. |
252
|
|
|
* Otherwise the function returns true for the corresponding rule by adding the new rule. |
253
|
|
|
* |
254
|
|
|
* @param string[][] $rules |
|
|
|
|
255
|
|
|
* |
256
|
|
|
* @return bool |
257
|
|
|
* @throws Exceptions\CasbinException |
258
|
|
|
*/ |
259
|
12 |
|
public function addPolicies(array $rules): bool |
260
|
|
|
{ |
261
|
12 |
|
return $this->addNamedPolicies('p', $rules); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* AddNamedPolicy adds an authorization rule to the current named policy. |
266
|
|
|
* If the rule already exists, the function returns false and the rule will not be added. |
267
|
|
|
* Otherwise the function returns true by adding the new rule. |
268
|
|
|
* |
269
|
|
|
* @param string $ptype |
|
|
|
|
270
|
|
|
* @param mixed ...$params |
|
|
|
|
271
|
|
|
* |
272
|
|
|
* @return bool |
273
|
|
|
*/ |
274
|
21 |
|
public function addNamedPolicy(string $ptype, ...$params): bool |
275
|
|
|
{ |
276
|
21 |
|
if (1 == count($params) && is_array($params[0])) { |
277
|
3 |
|
$params = $params[0]; |
278
|
|
|
} |
279
|
|
|
|
280
|
21 |
|
return $this->addPolicyInternal('p', $ptype, $params); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* AddNamedPolicies adds authorization rules to the current named policy. |
285
|
|
|
* If the rule already exists, the function returns false for the corresponding rule and the rule will not be added. |
286
|
|
|
* Otherwise the function returns true for the corresponding by adding the new rule. |
287
|
|
|
* |
288
|
|
|
* @param string $ptype |
|
|
|
|
289
|
|
|
* @param string[][] $rules |
|
|
|
|
290
|
|
|
* |
291
|
|
|
* @return bool |
292
|
|
|
* @throws Exceptions\CasbinException |
293
|
|
|
*/ |
294
|
12 |
|
public function addNamedPolicies(string $ptype, array $rules): bool |
295
|
|
|
{ |
296
|
12 |
|
return $this->addPoliciesInternal('p', $ptype, $rules); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Removes an authorization rule from the current policy. |
301
|
|
|
* |
302
|
|
|
* @param mixed ...$params |
|
|
|
|
303
|
|
|
* |
304
|
|
|
* @return bool |
305
|
|
|
*/ |
306
|
15 |
|
public function removePolicy(...$params): bool |
307
|
|
|
{ |
308
|
15 |
|
return $this->removeNamedPolicy('p', ...$params); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Removes an authorization rules from the current policy. |
313
|
|
|
* |
314
|
|
|
* @param array $rules |
|
|
|
|
315
|
|
|
* |
316
|
|
|
* @return bool |
317
|
|
|
*/ |
318
|
9 |
|
public function removePolicies(array $rules): bool |
319
|
|
|
{ |
320
|
9 |
|
return $this->removeNamedPolicies('p', $rules); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
/** |
324
|
|
|
* Removes an authorization rule from the current policy. |
325
|
|
|
* |
326
|
|
|
* @param string[] $oldRule |
|
|
|
|
327
|
|
|
* @param string[] $newRule |
|
|
|
|
328
|
|
|
* |
329
|
|
|
* @return bool |
330
|
|
|
*/ |
331
|
3 |
|
public function updatePolicy(array $oldRule, array $newRule): bool |
332
|
|
|
{ |
333
|
3 |
|
return $this->updateNamedPolicy("p", $oldRule, $newRule); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Updates an authorization rule from the current policy. |
338
|
|
|
* |
339
|
|
|
* @param string $ptype |
|
|
|
|
340
|
|
|
* @param string[] $oldRule |
|
|
|
|
341
|
|
|
* @param string[] $newRule |
|
|
|
|
342
|
|
|
* |
343
|
|
|
* @return bool |
344
|
|
|
*/ |
345
|
3 |
|
public function updateNamedPolicy(string $ptype, array $oldRule, array $newRule): bool |
346
|
|
|
{ |
347
|
3 |
|
return $this->updatePolicyInternal("p", $ptype, $oldRule, $newRule); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* UpdatePolicies updates authorization rules from the current policies. |
352
|
|
|
* |
353
|
|
|
* @param string[][] $oldPolices |
|
|
|
|
354
|
|
|
* @param string[][] $newPolicies |
|
|
|
|
355
|
|
|
* @return boolean |
|
|
|
|
356
|
|
|
*/ |
357
|
3 |
|
public function updatePolicies(array $oldPolices, array $newPolicies): bool |
358
|
|
|
{ |
359
|
3 |
|
return $this->updateNamedPolicies("p", $oldPolices, $newPolicies); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* Updates authorization rules from the current policy. |
364
|
|
|
* |
365
|
|
|
* @param string $ptype |
|
|
|
|
366
|
|
|
* @param string[][] $oldPolices |
|
|
|
|
367
|
|
|
* @param string[][] $newPolicies |
|
|
|
|
368
|
|
|
* @return boolean |
|
|
|
|
369
|
|
|
*/ |
370
|
3 |
|
public function updateNamedPolicies(string $ptype, array $oldPolices, array $newPolicies): bool |
371
|
|
|
{ |
372
|
3 |
|
return $this->updatePoliciesInternal("p", $ptype, $oldPolices, $newPolicies); |
373
|
|
|
} |
374
|
|
|
|
375
|
6 |
|
public function updateFilteredPolicies(array $newPolicies, int $fieldIndex, string ...$fieldValues): bool |
|
|
|
|
376
|
|
|
{ |
377
|
6 |
|
return $this->updateFilteredNamedPolicies("p", $newPolicies, $fieldIndex, ...$fieldValues); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Undocumented function |
382
|
|
|
* |
383
|
|
|
* @param string $ptype |
|
|
|
|
384
|
|
|
* @param array $newPolicies |
|
|
|
|
385
|
|
|
* @param integer $fieldIndex |
|
|
|
|
386
|
|
|
* @param string ...$fieldValues |
|
|
|
|
387
|
|
|
* @return boolean |
|
|
|
|
388
|
|
|
*/ |
389
|
6 |
|
public function updateFilteredNamedPolicies(string $ptype, array $newPolicies, int $fieldIndex, string ...$fieldValues): bool |
390
|
|
|
{ |
391
|
6 |
|
return $this->updateFilteredPoliciesInternal("p", $ptype, $newPolicies, $fieldIndex, ...$fieldValues); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* Removes an authorization rule from the current policy, field filters can be specified. |
396
|
|
|
* |
397
|
|
|
* @param int $fieldIndex |
|
|
|
|
398
|
|
|
* @param string ...$fieldValues |
|
|
|
|
399
|
|
|
* |
400
|
|
|
* @return bool |
401
|
|
|
*/ |
402
|
18 |
|
public function removeFilteredPolicy(int $fieldIndex, string ...$fieldValues): bool |
403
|
|
|
{ |
404
|
18 |
|
return $this->removeFilteredNamedPolicy('p', $fieldIndex, ...$fieldValues); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Removes an authorization rule from the current named policy. |
409
|
|
|
* |
410
|
|
|
* @param string $ptype |
|
|
|
|
411
|
|
|
* @param mixed ...$params |
|
|
|
|
412
|
|
|
* |
413
|
|
|
* @return bool |
414
|
|
|
*/ |
415
|
15 |
|
public function removeNamedPolicy(string $ptype, ...$params): bool |
416
|
|
|
{ |
417
|
15 |
|
if (1 == count($params) && is_array($params[0])) { |
418
|
3 |
|
$params = $params[0]; |
419
|
|
|
} |
420
|
|
|
|
421
|
15 |
|
return $this->removePolicyInternal('p', $ptype, $params); |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Removes an authorization rules from the current named policy. |
426
|
|
|
* |
427
|
|
|
* @param string $ptype |
|
|
|
|
428
|
|
|
* @param array $rules |
|
|
|
|
429
|
|
|
* |
430
|
|
|
* @return bool |
431
|
|
|
*/ |
432
|
9 |
|
public function removeNamedPolicies(string $ptype, array $rules): bool |
433
|
|
|
{ |
434
|
9 |
|
return $this->removePoliciesInternal('p', $ptype, $rules); |
435
|
|
|
} |
436
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* Removes an authorization rule from the current named policy, field filters can be specified. |
439
|
|
|
* |
440
|
|
|
* @param string $ptype |
|
|
|
|
441
|
|
|
* @param int $fieldIndex |
|
|
|
|
442
|
|
|
* @param string ...$fieldValues |
|
|
|
|
443
|
|
|
* |
444
|
|
|
* @return bool |
445
|
|
|
*/ |
446
|
18 |
|
public function removeFilteredNamedPolicy(string $ptype, int $fieldIndex, string ...$fieldValues): bool |
447
|
|
|
{ |
448
|
18 |
|
return $this->removeFilteredPolicyInternal('p', $ptype, $fieldIndex, ...$fieldValues); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* Determines whether a role inheritance rule exists. |
453
|
|
|
* |
454
|
|
|
* @param mixed ...$params |
|
|
|
|
455
|
|
|
* |
456
|
|
|
* @return bool |
457
|
|
|
*/ |
458
|
3 |
|
public function hasGroupingPolicy(...$params): bool |
459
|
|
|
{ |
460
|
3 |
|
return $this->hasNamedGroupingPolicy('g', ...$params); |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Determines whether a named role inheritance rule exists. |
465
|
|
|
* |
466
|
|
|
* @param string $ptype |
|
|
|
|
467
|
|
|
* @param mixed ...$params |
|
|
|
|
468
|
|
|
* |
469
|
|
|
* @return bool |
470
|
|
|
*/ |
471
|
3 |
|
public function hasNamedGroupingPolicy(string $ptype, ...$params): bool |
472
|
|
|
{ |
473
|
3 |
|
if (1 == count($params) && is_array($params[0])) { |
474
|
3 |
|
$params = $params[0]; |
475
|
|
|
} |
476
|
|
|
|
477
|
3 |
|
return $this->model->hasPolicy('g', $ptype, $params); |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
/** |
481
|
|
|
* AddGroupingPolicy adds a role inheritance rule to the current policy. |
482
|
|
|
* If the rule already exists, the function returns false and the rule will not be added. |
483
|
|
|
* Otherwise the function returns true by adding the new rule. |
484
|
|
|
* |
485
|
|
|
* @param mixed ...$params |
|
|
|
|
486
|
|
|
* |
487
|
|
|
* @return bool |
488
|
|
|
*/ |
489
|
18 |
|
public function addGroupingPolicy(...$params): bool |
490
|
|
|
{ |
491
|
18 |
|
return $this->addNamedGroupingPolicy('g', ...$params); |
492
|
|
|
} |
493
|
|
|
|
494
|
|
|
/** |
495
|
|
|
* AddGroupingPolicy adds a role inheritance rules to the current policy. |
496
|
|
|
* If the rule already exists, the function returns false and the rule will not be added. |
497
|
|
|
* Otherwise the function returns true by adding the new rule. |
498
|
|
|
* |
499
|
|
|
* @param array $rules |
|
|
|
|
500
|
|
|
* |
501
|
|
|
* @return bool |
502
|
|
|
*/ |
503
|
6 |
|
public function addGroupingPolicies(array $rules): bool |
504
|
|
|
{ |
505
|
6 |
|
return $this->addNamedGroupingPolicies('g', $rules); |
506
|
|
|
} |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* AddNamedGroupingPolicy adds a named role inheritance rule to the current policy. |
510
|
|
|
* If the rule already exists, the function returns false and the rule will not be added. |
511
|
|
|
* Otherwise the function returns true by adding the new rule. |
512
|
|
|
* |
513
|
|
|
* @param string $ptype |
|
|
|
|
514
|
|
|
* @param mixed ...$params |
|
|
|
|
515
|
|
|
* |
516
|
|
|
* @return bool |
517
|
|
|
*/ |
518
|
18 |
|
public function addNamedGroupingPolicy(string $ptype, ...$params): bool |
519
|
|
|
{ |
520
|
18 |
|
if (1 == count($params) && is_array($params[0])) { |
521
|
3 |
|
$params = $params[0]; |
522
|
|
|
} |
523
|
|
|
|
524
|
18 |
|
$ruleAdded = $this->addPolicyInternal('g', $ptype, $params); |
525
|
|
|
|
526
|
18 |
|
if ($this->autoBuildRoleLinks) { |
527
|
18 |
|
$this->buildRoleLinks(); |
528
|
|
|
} |
529
|
|
|
|
530
|
18 |
|
return $ruleAdded; |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* AddNamedGroupingPolicy adds a named role inheritance rules to the current policy. |
535
|
|
|
* If the rule already exists, the function returns false and the rule will not be added. |
536
|
|
|
* Otherwise the function returns true by adding the new rule. |
537
|
|
|
* |
538
|
|
|
* @param string $ptype |
|
|
|
|
539
|
|
|
* @param array $rules |
|
|
|
|
540
|
|
|
* |
541
|
|
|
* @return bool |
542
|
|
|
*/ |
543
|
6 |
|
public function addNamedGroupingPolicies(string $ptype, array $rules): bool |
544
|
|
|
{ |
545
|
6 |
|
$ruleAdded = $this->addPoliciesInternal('g', $ptype, $rules); |
546
|
|
|
|
547
|
6 |
|
if ($this->autoBuildRoleLinks) { |
548
|
6 |
|
$this->buildRoleLinks(); |
549
|
|
|
} |
550
|
|
|
|
551
|
6 |
|
return $ruleAdded; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* Removes a role inheritance rule from the current policy. |
556
|
|
|
* |
557
|
|
|
* @param mixed ...$params |
|
|
|
|
558
|
|
|
* |
559
|
|
|
* @return bool |
560
|
|
|
*/ |
561
|
18 |
|
public function removeGroupingPolicy(...$params): bool |
562
|
|
|
{ |
563
|
18 |
|
return $this->removeNamedGroupingPolicy('g', ...$params); |
564
|
|
|
} |
565
|
|
|
|
566
|
|
|
/** |
567
|
|
|
* Removes a role inheritance rules from the current policy. |
568
|
|
|
* |
569
|
|
|
* @param array $rules |
|
|
|
|
570
|
|
|
* |
571
|
|
|
* @return bool |
572
|
|
|
*/ |
573
|
12 |
|
public function removeGroupingPolicies(array $rules): bool |
574
|
|
|
{ |
575
|
12 |
|
return $this->removeNamedGroupingPolicies('g', $rules); |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
/** |
579
|
|
|
* Removes a role inheritance rule from the current policy, field filters can be specified. |
580
|
|
|
* |
581
|
|
|
* @param int $fieldIndex |
|
|
|
|
582
|
|
|
* @param string ...$fieldValues |
|
|
|
|
583
|
|
|
* |
584
|
|
|
* @return bool |
585
|
|
|
*/ |
586
|
12 |
|
public function removeFilteredGroupingPolicy(int $fieldIndex, string ...$fieldValues): bool |
587
|
|
|
{ |
588
|
12 |
|
return $this->removeFilteredNamedGroupingPolicy('g', $fieldIndex, ...$fieldValues); |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
/** |
592
|
|
|
* Removes a role inheritance rule from the current named policy. |
593
|
|
|
* |
594
|
|
|
* @param string $ptype |
|
|
|
|
595
|
|
|
* @param mixed ...$params |
|
|
|
|
596
|
|
|
* |
597
|
|
|
* @return bool |
598
|
|
|
*/ |
599
|
18 |
|
public function removeNamedGroupingPolicy(string $ptype, ...$params): bool |
600
|
|
|
{ |
601
|
18 |
|
if (1 == count($params) && is_array($params[0])) { |
602
|
3 |
|
$params = $params[0]; |
603
|
|
|
} |
604
|
|
|
|
605
|
18 |
|
$ruleRemoved = $this->removePolicyInternal('g', $ptype, $params); |
606
|
|
|
|
607
|
18 |
|
if ($this->autoBuildRoleLinks) { |
608
|
18 |
|
$this->buildRoleLinks(); |
609
|
|
|
} |
610
|
|
|
|
611
|
18 |
|
return $ruleRemoved; |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
/** |
615
|
|
|
* Removes a role inheritance rules from the current named policy. |
616
|
|
|
* |
617
|
|
|
* @param string $ptype |
|
|
|
|
618
|
|
|
* @param array $rules |
|
|
|
|
619
|
|
|
* |
620
|
|
|
* @return bool |
621
|
|
|
*/ |
622
|
12 |
|
public function removeNamedGroupingPolicies(string $ptype, array $rules): bool |
623
|
|
|
{ |
624
|
12 |
|
$ruleRemoved = $this->removePoliciesInternal('g', $ptype, $rules); |
625
|
|
|
|
626
|
12 |
|
if ($this->autoBuildRoleLinks) { |
627
|
12 |
|
$this->buildRoleLinks(); |
628
|
|
|
} |
629
|
|
|
|
630
|
12 |
|
return $ruleRemoved; |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
/** |
634
|
|
|
* Removes a role inheritance rule from the current named policy, field filters can be specified. |
635
|
|
|
* |
636
|
|
|
* @param string $ptype |
|
|
|
|
637
|
|
|
* @param int $fieldIndex |
|
|
|
|
638
|
|
|
* @param string ...$fieldValues |
|
|
|
|
639
|
|
|
* |
640
|
|
|
* @return bool |
641
|
|
|
*/ |
642
|
12 |
|
public function removeFilteredNamedGroupingPolicy(string $ptype, int $fieldIndex, string ...$fieldValues): bool |
643
|
|
|
{ |
644
|
12 |
|
$ruleRemoved = $this->removeFilteredPolicyInternal('g', $ptype, $fieldIndex, ...$fieldValues); |
645
|
|
|
|
646
|
12 |
|
if ($this->autoBuildRoleLinks) { |
647
|
12 |
|
$this->buildRoleLinks(); |
648
|
|
|
} |
649
|
|
|
|
650
|
12 |
|
return $ruleRemoved; |
651
|
|
|
} |
652
|
|
|
|
653
|
|
|
/** |
654
|
|
|
* Adds a customized function. |
655
|
|
|
* |
656
|
|
|
* @param string $name |
|
|
|
|
657
|
|
|
* @param Closure $func |
|
|
|
|
658
|
|
|
*/ |
|
|
|
|
659
|
|
|
public function addFunction(string $name, Closure $func): void |
660
|
|
|
{ |
661
|
|
|
$this->fm->addFunction($name, $func); |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
/** |
665
|
|
|
* Gets the index for a given ptype and field. |
666
|
|
|
* |
667
|
|
|
* @param string $ptype |
|
|
|
|
668
|
|
|
* @param string $field |
|
|
|
|
669
|
|
|
* |
670
|
|
|
* @return int $fieldIndex |
671
|
|
|
* @throws Exceptions\CasbinException |
672
|
|
|
*/ |
673
|
3 |
|
public function getFieldIndex(string $ptype, string $field): int |
674
|
|
|
{ |
675
|
3 |
|
return $this->model->getFieldIndex($ptype, $field); |
676
|
|
|
} |
677
|
|
|
|
678
|
|
|
/** |
679
|
|
|
* Sets the index for a given ptype and field. |
680
|
|
|
* |
681
|
|
|
* @param string $ptype |
|
|
|
|
682
|
|
|
* @param string $field |
|
|
|
|
683
|
|
|
* @param int $index |
|
|
|
|
684
|
|
|
*/ |
|
|
|
|
685
|
3 |
|
public function setFieldIndex(string $ptype, string $field, int $index): void |
686
|
|
|
{ |
687
|
3 |
|
$this->model->setFieldIndex($ptype, $field, $index); |
688
|
2 |
|
} |
689
|
|
|
} |
690
|
|
|
|