|
0
|
1 |
<?php |
|
|
2 |
/* |
|
|
3 |
* This file is part of the Symfony package. |
|
|
4 |
* |
|
|
5 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
6 |
* |
|
|
7 |
* For the full copyright and license information, please view the LICENSE |
|
|
8 |
* file that was distributed with this source code. |
|
|
9 |
*/ |
|
|
10 |
|
|
|
11 |
namespace Symfony\Component\Security\Acl\Domain; |
|
|
12 |
|
|
|
13 |
use Doctrine\Common\NotifyPropertyChanged; |
|
|
14 |
use Doctrine\Common\PropertyChangedListener; |
|
|
15 |
use Symfony\Component\Security\Acl\Model\AclInterface; |
|
|
16 |
use Symfony\Component\Security\Acl\Model\AuditableAclInterface; |
|
|
17 |
use Symfony\Component\Security\Acl\Model\EntryInterface; |
|
|
18 |
use Symfony\Component\Security\Acl\Model\MutableAclInterface; |
|
|
19 |
use Symfony\Component\Security\Acl\Model\ObjectIdentityInterface; |
|
|
20 |
use Symfony\Component\Security\Acl\Model\PermissionGrantingStrategyInterface; |
|
|
21 |
use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface; |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
/** |
|
|
25 |
* An ACL implementation. |
|
|
26 |
* |
|
|
27 |
* Each object identity has exactly one associated ACL. Each ACL can have four |
|
|
28 |
* different types of ACEs (class ACEs, object ACEs, class field ACEs, object field |
|
|
29 |
* ACEs). |
|
|
30 |
* |
|
|
31 |
* You should not iterate over the ACEs yourself, but instead use isGranted(), |
|
|
32 |
* or isFieldGranted(). These will utilize an implementation of PermissionGrantingStrategy |
|
|
33 |
* internally. |
|
|
34 |
* |
|
|
35 |
* @author Johannes M. Schmitt <schmittjoh@gmail.com> |
|
|
36 |
*/ |
|
|
37 |
class Acl implements AuditableAclInterface, NotifyPropertyChanged |
|
|
38 |
{ |
|
|
39 |
private $parentAcl; |
|
|
40 |
private $permissionGrantingStrategy; |
|
|
41 |
private $objectIdentity; |
|
|
42 |
private $classAces; |
|
|
43 |
private $classFieldAces; |
|
|
44 |
private $objectAces; |
|
|
45 |
private $objectFieldAces; |
|
|
46 |
private $id; |
|
|
47 |
private $loadedSids; |
|
|
48 |
private $entriesInheriting; |
|
|
49 |
private $listeners; |
|
|
50 |
|
|
|
51 |
/** |
|
|
52 |
* Constructor |
|
|
53 |
* |
|
|
54 |
* @param integer $id |
|
|
55 |
* @param ObjectIdentityInterface $objectIdentity |
|
|
56 |
* @param PermissionGrantingStrategyInterface $permissionGrantingStrategy |
|
|
57 |
* @param array $loadedSids |
|
|
58 |
* @param Boolean $entriesInheriting |
|
|
59 |
* @return void |
|
|
60 |
*/ |
|
|
61 |
public function __construct($id, ObjectIdentityInterface $objectIdentity, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $loadedSids = array(), $entriesInheriting) |
|
|
62 |
{ |
|
|
63 |
$this->id = $id; |
|
|
64 |
$this->objectIdentity = $objectIdentity; |
|
|
65 |
$this->permissionGrantingStrategy = $permissionGrantingStrategy; |
|
|
66 |
$this->loadedSids = $loadedSids; |
|
|
67 |
$this->entriesInheriting = $entriesInheriting; |
|
|
68 |
$this->parentAcl = null; |
|
|
69 |
$this->classAces = array(); |
|
|
70 |
$this->classFieldAces = array(); |
|
|
71 |
$this->objectAces = array(); |
|
|
72 |
$this->objectFieldAces = array(); |
|
|
73 |
$this->listeners = array(); |
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
/** |
|
|
77 |
* Adds a property changed listener |
|
|
78 |
* |
|
|
79 |
* @param PropertyChangedListener $listener |
|
|
80 |
* @return void |
|
|
81 |
*/ |
|
|
82 |
public function addPropertyChangedListener(PropertyChangedListener $listener) |
|
|
83 |
{ |
|
|
84 |
$this->listeners[] = $listener; |
|
|
85 |
} |
|
|
86 |
|
|
|
87 |
/** |
|
|
88 |
* {@inheritDoc} |
|
|
89 |
*/ |
|
|
90 |
public function deleteClassAce($index) |
|
|
91 |
{ |
|
|
92 |
$this->deleteAce('classAces', $index); |
|
|
93 |
} |
|
|
94 |
|
|
|
95 |
/** |
|
|
96 |
* {@inheritDoc} |
|
|
97 |
*/ |
|
|
98 |
public function deleteClassFieldAce($index, $field) |
|
|
99 |
{ |
|
|
100 |
$this->deleteFieldAce('classFieldAces', $index, $field); |
|
|
101 |
} |
|
|
102 |
|
|
|
103 |
/** |
|
|
104 |
* {@inheritDoc} |
|
|
105 |
*/ |
|
|
106 |
public function deleteObjectAce($index) |
|
|
107 |
{ |
|
|
108 |
$this->deleteAce('objectAces', $index); |
|
|
109 |
} |
|
|
110 |
|
|
|
111 |
/** |
|
|
112 |
* {@inheritDoc} |
|
|
113 |
*/ |
|
|
114 |
public function deleteObjectFieldAce($index, $field) |
|
|
115 |
{ |
|
|
116 |
$this->deleteFieldAce('objectFieldAces', $index, $field); |
|
|
117 |
} |
|
|
118 |
|
|
|
119 |
/** |
|
|
120 |
* {@inheritDoc} |
|
|
121 |
*/ |
|
|
122 |
public function getClassAces() |
|
|
123 |
{ |
|
|
124 |
return $this->classAces; |
|
|
125 |
} |
|
|
126 |
|
|
|
127 |
/** |
|
|
128 |
* {@inheritDoc} |
|
|
129 |
*/ |
|
|
130 |
public function getClassFieldAces($field) |
|
|
131 |
{ |
|
|
132 |
return isset($this->classFieldAces[$field])? $this->classFieldAces[$field] : array(); |
|
|
133 |
} |
|
|
134 |
|
|
|
135 |
/** |
|
|
136 |
* {@inheritDoc} |
|
|
137 |
*/ |
|
|
138 |
public function getObjectAces() |
|
|
139 |
{ |
|
|
140 |
return $this->objectAces; |
|
|
141 |
} |
|
|
142 |
|
|
|
143 |
/** |
|
|
144 |
* {@inheritDoc} |
|
|
145 |
*/ |
|
|
146 |
public function getObjectFieldAces($field) |
|
|
147 |
{ |
|
|
148 |
return isset($this->objectFieldAces[$field]) ? $this->objectFieldAces[$field] : array(); |
|
|
149 |
} |
|
|
150 |
|
|
|
151 |
/** |
|
|
152 |
* {@inheritDoc} |
|
|
153 |
*/ |
|
|
154 |
public function getId() |
|
|
155 |
{ |
|
|
156 |
return $this->id; |
|
|
157 |
} |
|
|
158 |
|
|
|
159 |
/** |
|
|
160 |
* {@inheritDoc} |
|
|
161 |
*/ |
|
|
162 |
public function getObjectIdentity() |
|
|
163 |
{ |
|
|
164 |
return $this->objectIdentity; |
|
|
165 |
} |
|
|
166 |
|
|
|
167 |
/** |
|
|
168 |
* {@inheritDoc} |
|
|
169 |
*/ |
|
|
170 |
public function getParentAcl() |
|
|
171 |
{ |
|
|
172 |
return $this->parentAcl; |
|
|
173 |
} |
|
|
174 |
|
|
|
175 |
/** |
|
|
176 |
* {@inheritDoc} |
|
|
177 |
*/ |
|
|
178 |
public function insertClassAce(SecurityIdentityInterface $sid, $mask, $index = 0, $granting = true, $strategy = null) |
|
|
179 |
{ |
|
|
180 |
$this->insertAce('classAces', $index, $mask, $sid, $granting, $strategy); |
|
|
181 |
} |
|
|
182 |
|
|
|
183 |
/** |
|
|
184 |
* {@inheritDoc} |
|
|
185 |
*/ |
|
|
186 |
public function insertClassFieldAce($field, SecurityIdentityInterface $sid, $mask, $index = 0, $granting = true, $strategy = null) |
|
|
187 |
{ |
|
|
188 |
$this->insertFieldAce('classFieldAces', $index, $field, $mask, $sid, $granting, $strategy); |
|
|
189 |
} |
|
|
190 |
|
|
|
191 |
/** |
|
|
192 |
* {@inheritDoc} |
|
|
193 |
*/ |
|
|
194 |
public function insertObjectAce(SecurityIdentityInterface $sid, $mask, $index = 0, $granting = true, $strategy = null) |
|
|
195 |
{ |
|
|
196 |
$this->insertAce('objectAces', $index, $mask, $sid, $granting, $strategy); |
|
|
197 |
} |
|
|
198 |
|
|
|
199 |
/** |
|
|
200 |
* {@inheritDoc} |
|
|
201 |
*/ |
|
|
202 |
public function insertObjectFieldAce($field, SecurityIdentityInterface $sid, $mask, $index = 0, $granting = true, $strategy = null) |
|
|
203 |
{ |
|
|
204 |
$this->insertFieldAce('objectFieldAces', $index, $field, $mask, $sid, $granting, $strategy); |
|
|
205 |
} |
|
|
206 |
|
|
|
207 |
/** |
|
|
208 |
* {@inheritDoc} |
|
|
209 |
*/ |
|
|
210 |
public function isEntriesInheriting() |
|
|
211 |
{ |
|
|
212 |
return $this->entriesInheriting; |
|
|
213 |
} |
|
|
214 |
|
|
|
215 |
/** |
|
|
216 |
* {@inheritDoc} |
|
|
217 |
*/ |
|
|
218 |
public function isFieldGranted($field, array $masks, array $securityIdentities, $administrativeMode = false) |
|
|
219 |
{ |
|
|
220 |
return $this->permissionGrantingStrategy->isFieldGranted($this, $field, $masks, $securityIdentities, $administrativeMode); |
|
|
221 |
} |
|
|
222 |
|
|
|
223 |
/** |
|
|
224 |
* {@inheritDoc} |
|
|
225 |
*/ |
|
|
226 |
public function isGranted(array $masks, array $securityIdentities, $administrativeMode = false) |
|
|
227 |
{ |
|
|
228 |
return $this->permissionGrantingStrategy->isGranted($this, $masks, $securityIdentities, $administrativeMode); |
|
|
229 |
} |
|
|
230 |
|
|
|
231 |
/** |
|
|
232 |
* {@inheritDoc} |
|
|
233 |
*/ |
|
|
234 |
public function isSidLoaded($sids) |
|
|
235 |
{ |
|
|
236 |
if (!$this->loadedSids) { |
|
|
237 |
return true; |
|
|
238 |
} |
|
|
239 |
|
|
|
240 |
if (!is_array($sids)) { |
|
|
241 |
$sids = array($sids); |
|
|
242 |
} |
|
|
243 |
|
|
|
244 |
foreach ($sids as $sid) { |
|
|
245 |
if (!$sid instanceof SecurityIdentityInterface) { |
|
|
246 |
throw new \InvalidArgumentException( |
|
|
247 |
'$sid must be an instance of SecurityIdentityInterface.'); |
|
|
248 |
} |
|
|
249 |
|
|
|
250 |
foreach ($this->loadedSids as $loadedSid) { |
|
|
251 |
if ($loadedSid->equals($sid)) { |
|
|
252 |
continue 2; |
|
|
253 |
} |
|
|
254 |
} |
|
|
255 |
|
|
|
256 |
return false; |
|
|
257 |
} |
|
|
258 |
|
|
|
259 |
return true; |
|
|
260 |
} |
|
|
261 |
|
|
|
262 |
/** |
|
|
263 |
* Implementation for the \Serializable interface |
|
|
264 |
* |
|
|
265 |
* @return string |
|
|
266 |
*/ |
|
|
267 |
public function serialize() |
|
|
268 |
{ |
|
|
269 |
return serialize(array( |
|
|
270 |
null === $this->parentAcl ? null : $this->parentAcl->getId(), |
|
|
271 |
$this->objectIdentity, |
|
|
272 |
$this->classAces, |
|
|
273 |
$this->classFieldAces, |
|
|
274 |
$this->objectAces, |
|
|
275 |
$this->objectFieldAces, |
|
|
276 |
$this->id, |
|
|
277 |
$this->loadedSids, |
|
|
278 |
$this->entriesInheriting, |
|
|
279 |
)); |
|
|
280 |
} |
|
|
281 |
|
|
|
282 |
/** |
|
|
283 |
* Implementation for the \Serializable interface |
|
|
284 |
* |
|
|
285 |
* @param string $serialized |
|
|
286 |
* @return void |
|
|
287 |
*/ |
|
|
288 |
public function unserialize($serialized) |
|
|
289 |
{ |
|
|
290 |
list($this->parentAcl, |
|
|
291 |
$this->objectIdentity, |
|
|
292 |
$this->classAces, |
|
|
293 |
$this->classFieldAces, |
|
|
294 |
$this->objectAces, |
|
|
295 |
$this->objectFieldAces, |
|
|
296 |
$this->id, |
|
|
297 |
$this->loadedSids, |
|
|
298 |
$this->entriesInheriting |
|
|
299 |
) = unserialize($serialized); |
|
|
300 |
|
|
|
301 |
$this->listeners = array(); |
|
|
302 |
} |
|
|
303 |
|
|
|
304 |
/** |
|
|
305 |
* {@inheritDoc} |
|
|
306 |
*/ |
|
|
307 |
public function setEntriesInheriting($boolean) |
|
|
308 |
{ |
|
|
309 |
if ($this->entriesInheriting !== $boolean) { |
|
|
310 |
$this->onPropertyChanged('entriesInheriting', $this->entriesInheriting, $boolean); |
|
|
311 |
$this->entriesInheriting = $boolean; |
|
|
312 |
} |
|
|
313 |
} |
|
|
314 |
|
|
|
315 |
/** |
|
|
316 |
* {@inheritDoc} |
|
|
317 |
*/ |
|
|
318 |
public function setParentAcl(AclInterface $acl) |
|
|
319 |
{ |
|
|
320 |
if (null === $acl->getId()) { |
|
|
321 |
throw new \InvalidArgumentException('$acl must have an ID.'); |
|
|
322 |
} |
|
|
323 |
|
|
|
324 |
if ($this->parentAcl !== $acl) { |
|
|
325 |
$this->onPropertyChanged('parentAcl', $this->parentAcl, $acl); |
|
|
326 |
$this->parentAcl = $acl; |
|
|
327 |
} |
|
|
328 |
} |
|
|
329 |
|
|
|
330 |
/** |
|
|
331 |
* {@inheritDoc} |
|
|
332 |
*/ |
|
|
333 |
public function updateClassAce($index, $mask, $strategy = null) |
|
|
334 |
{ |
|
|
335 |
$this->updateAce('classAces', $index, $mask, $strategy); |
|
|
336 |
} |
|
|
337 |
|
|
|
338 |
/** |
|
|
339 |
* {@inheritDoc} |
|
|
340 |
*/ |
|
|
341 |
public function updateClassFieldAce($index, $field, $mask, $strategy = null) |
|
|
342 |
{ |
|
|
343 |
$this->updateFieldAce('classFieldAces', $index, $field, $mask, $strategy); |
|
|
344 |
} |
|
|
345 |
|
|
|
346 |
/** |
|
|
347 |
* {@inheritDoc} |
|
|
348 |
*/ |
|
|
349 |
public function updateObjectAce($index, $mask, $strategy = null) |
|
|
350 |
{ |
|
|
351 |
$this->updateAce('objectAces', $index, $mask, $strategy); |
|
|
352 |
} |
|
|
353 |
|
|
|
354 |
/** |
|
|
355 |
* {@inheritDoc} |
|
|
356 |
*/ |
|
|
357 |
public function updateObjectFieldAce($index, $field, $mask, $strategy = null) |
|
|
358 |
{ |
|
|
359 |
$this->updateFieldAce('objectFieldAces', $index, $field, $mask, $strategy); |
|
|
360 |
} |
|
|
361 |
|
|
|
362 |
/** |
|
|
363 |
* {@inheritDoc} |
|
|
364 |
*/ |
|
|
365 |
public function updateClassAuditing($index, $auditSuccess, $auditFailure) |
|
|
366 |
{ |
|
|
367 |
$this->updateAuditing($this->classAces, $index, $auditSuccess, $auditFailure); |
|
|
368 |
} |
|
|
369 |
|
|
|
370 |
/** |
|
|
371 |
* {@inheritDoc} |
|
|
372 |
*/ |
|
|
373 |
public function updateClassFieldAuditing($index, $field, $auditSuccess, $auditFailure) |
|
|
374 |
{ |
|
|
375 |
if (!isset($this->classFieldAces[$field])) { |
|
|
376 |
throw new \InvalidArgumentException(sprintf('There are no ACEs for field "%s".', $field)); |
|
|
377 |
} |
|
|
378 |
|
|
|
379 |
$this->updateAuditing($this->classFieldAces[$field], $index, $auditSuccess, $auditFailure); |
|
|
380 |
} |
|
|
381 |
|
|
|
382 |
/** |
|
|
383 |
* {@inheritDoc} |
|
|
384 |
*/ |
|
|
385 |
public function updateObjectAuditing($index, $auditSuccess, $auditFailure) |
|
|
386 |
{ |
|
|
387 |
$this->updateAuditing($this->objectAces, $index, $auditSuccess, $auditFailure); |
|
|
388 |
} |
|
|
389 |
|
|
|
390 |
/** |
|
|
391 |
* {@inheritDoc} |
|
|
392 |
*/ |
|
|
393 |
public function updateObjectFieldAuditing($index, $field, $auditSuccess, $auditFailure) |
|
|
394 |
{ |
|
|
395 |
if (!isset($this->objectFieldAces[$field])) { |
|
|
396 |
throw new \InvalidArgumentException(sprintf('There are no ACEs for field "%s".', $field)); |
|
|
397 |
} |
|
|
398 |
|
|
|
399 |
$this->updateAuditing($this->objectFieldAces[$field], $index, $auditSuccess, $auditFailure); |
|
|
400 |
} |
|
|
401 |
|
|
|
402 |
/** |
|
|
403 |
* Deletes an ACE |
|
|
404 |
* |
|
|
405 |
* @param string $property |
|
|
406 |
* @param integer $index |
|
|
407 |
* @throws \OutOfBoundsException |
|
|
408 |
* @return void |
|
|
409 |
*/ |
|
|
410 |
private function deleteAce($property, $index) |
|
|
411 |
{ |
|
|
412 |
$aces =& $this->$property; |
|
|
413 |
if (!isset($aces[$index])) { |
|
|
414 |
throw new \OutOfBoundsException(sprintf('The index "%d" does not exist.', $index)); |
|
|
415 |
} |
|
|
416 |
|
|
|
417 |
$oldValue = $this->$property; |
|
|
418 |
unset($aces[$index]); |
|
|
419 |
$this->$property = array_values($this->$property); |
|
|
420 |
$this->onPropertyChanged($property, $oldValue, $this->$property); |
|
|
421 |
|
|
|
422 |
for ($i=$index,$c=count($this->$property); $i<$c; $i++) { |
|
|
423 |
$this->onEntryPropertyChanged($aces[$i], 'aceOrder', $i+1, $i); |
|
|
424 |
} |
|
|
425 |
} |
|
|
426 |
|
|
|
427 |
/** |
|
|
428 |
* Deletes a field-based ACE |
|
|
429 |
* |
|
|
430 |
* @param string $property |
|
|
431 |
* @param integer $index |
|
|
432 |
* @param string $field |
|
|
433 |
* @throws \OutOfBoundsException |
|
|
434 |
* @return void |
|
|
435 |
*/ |
|
|
436 |
private function deleteFieldAce($property, $index, $field) |
|
|
437 |
{ |
|
|
438 |
$aces =& $this->$property; |
|
|
439 |
if (!isset($aces[$field][$index])) { |
|
|
440 |
throw new \OutOfBoundsException(sprintf('The index "%d" does not exist.', $index)); |
|
|
441 |
} |
|
|
442 |
|
|
|
443 |
$oldValue = $this->$property; |
|
|
444 |
unset($aces[$field][$index]); |
|
|
445 |
$aces[$field] = array_values($aces[$field]); |
|
|
446 |
$this->onPropertyChanged($property, $oldValue, $this->$property); |
|
|
447 |
|
|
|
448 |
for ($i=$index,$c=count($aces[$field]); $i<$c; $i++) { |
|
|
449 |
$this->onEntryPropertyChanged($aces[$field][$i], 'aceOrder', $i+1, $i); |
|
|
450 |
} |
|
|
451 |
} |
|
|
452 |
|
|
|
453 |
/** |
|
|
454 |
* Inserts an ACE |
|
|
455 |
* |
|
|
456 |
* @param string $property |
|
|
457 |
* @param integer $index |
|
|
458 |
* @param integer $mask |
|
|
459 |
* @param SecurityIdentityInterface $sid |
|
|
460 |
* @param Boolean $granting |
|
|
461 |
* @param string $strategy |
|
|
462 |
* @throws \OutOfBoundsException |
|
|
463 |
* @throws \InvalidArgumentException |
|
|
464 |
* @return void |
|
|
465 |
*/ |
|
|
466 |
private function insertAce($property, $index, $mask, SecurityIdentityInterface $sid, $granting, $strategy = null) |
|
|
467 |
{ |
|
|
468 |
if ($index < 0 || $index > count($this->$property)) { |
|
|
469 |
throw new \OutOfBoundsException(sprintf('The index must be in the interval [0, %d].', count($this->$property))); |
|
|
470 |
} |
|
|
471 |
|
|
|
472 |
if (!is_int($mask)) { |
|
|
473 |
throw new \InvalidArgumentException('$mask must be an integer.'); |
|
|
474 |
} |
|
|
475 |
|
|
|
476 |
if (null === $strategy) { |
|
|
477 |
if (true === $granting) { |
|
|
478 |
$strategy = PermissionGrantingStrategy::ALL; |
|
|
479 |
} else { |
|
|
480 |
$strategy = PermissionGrantingStrategy::ANY; |
|
|
481 |
} |
|
|
482 |
} |
|
|
483 |
|
|
|
484 |
$aces =& $this->$property; |
|
|
485 |
$oldValue = $this->$property; |
|
|
486 |
if (isset($aces[$index])) { |
|
|
487 |
$this->$property = array_merge( |
|
|
488 |
array_slice($this->$property, 0, $index), |
|
|
489 |
array(true), |
|
|
490 |
array_slice($this->$property, $index) |
|
|
491 |
); |
|
|
492 |
|
|
|
493 |
for ($i=$index,$c=count($this->$property)-1; $i<$c; $i++) { |
|
|
494 |
$this->onEntryPropertyChanged($aces[$i+1], 'aceOrder', $i, $i+1); |
|
|
495 |
} |
|
|
496 |
} |
|
|
497 |
|
|
|
498 |
$aces[$index] = new Entry(null, $this, $sid, $strategy, $mask, $granting, false, false); |
|
|
499 |
$this->onPropertyChanged($property, $oldValue, $this->$property); |
|
|
500 |
} |
|
|
501 |
|
|
|
502 |
/** |
|
|
503 |
* Inserts a field-based ACE |
|
|
504 |
* |
|
|
505 |
* @param string $property |
|
|
506 |
* @param integer $index |
|
|
507 |
* @param string $field |
|
|
508 |
* @param integer $mask |
|
|
509 |
* @param SecurityIdentityInterface $sid |
|
|
510 |
* @param Boolean $granting |
|
|
511 |
* @param string $strategy |
|
|
512 |
* @throws \InvalidArgumentException |
|
|
513 |
* @throws \OutOfBoundsException |
|
|
514 |
* @return void |
|
|
515 |
*/ |
|
|
516 |
private function insertFieldAce($property, $index, $field, $mask, SecurityIdentityInterface $sid, $granting, $strategy = null) |
|
|
517 |
{ |
|
|
518 |
if (0 === strlen($field)) { |
|
|
519 |
throw new \InvalidArgumentException('$field cannot be empty.'); |
|
|
520 |
} |
|
|
521 |
|
|
|
522 |
if (!is_int($mask)) { |
|
|
523 |
throw new \InvalidArgumentException('$mask must be an integer.'); |
|
|
524 |
} |
|
|
525 |
|
|
|
526 |
if (null === $strategy) { |
|
|
527 |
if (true === $granting) { |
|
|
528 |
$strategy = PermissionGrantingStrategy::ALL; |
|
|
529 |
} else { |
|
|
530 |
$strategy = PermissionGrantingStrategy::ANY; |
|
|
531 |
} |
|
|
532 |
} |
|
|
533 |
|
|
|
534 |
$aces =& $this->$property; |
|
|
535 |
if (!isset($aces[$field])) { |
|
|
536 |
$aces[$field] = array(); |
|
|
537 |
} |
|
|
538 |
|
|
|
539 |
if ($index < 0 || $index > count($aces[$field])) { |
|
|
540 |
throw new \OutOfBoundsException(sprintf('The index must be in the interval [0, %d].', count($this->$property))); |
|
|
541 |
} |
|
|
542 |
|
|
|
543 |
$oldValue = $aces; |
|
|
544 |
if (isset($aces[$field][$index])) { |
|
|
545 |
$aces[$field] = array_merge( |
|
|
546 |
array_slice($aces[$field], 0, $index), |
|
|
547 |
array(true), |
|
|
548 |
array_slice($aces[$field], $index) |
|
|
549 |
); |
|
|
550 |
|
|
|
551 |
for ($i=$index,$c=count($aces[$field])-1; $i<$c; $i++) { |
|
|
552 |
$this->onEntryPropertyChanged($aces[$field][$i+1], 'aceOrder', $i, $i+1); |
|
|
553 |
} |
|
|
554 |
} |
|
|
555 |
|
|
|
556 |
$aces[$field][$index] = new FieldEntry(null, $this, $field, $sid, $strategy, $mask, $granting, false, false); |
|
|
557 |
$this->onPropertyChanged($property, $oldValue, $this->$property); |
|
|
558 |
} |
|
|
559 |
|
|
|
560 |
/** |
|
|
561 |
* Updates an ACE |
|
|
562 |
* |
|
|
563 |
* @param string $property |
|
|
564 |
* @param integer $index |
|
|
565 |
* @param integer $mask |
|
|
566 |
* @param string $strategy |
|
|
567 |
* @throws \OutOfBoundsException |
|
|
568 |
* @return void |
|
|
569 |
*/ |
|
|
570 |
private function updateAce($property, $index, $mask, $strategy = null) |
|
|
571 |
{ |
|
|
572 |
$aces =& $this->$property; |
|
|
573 |
if (!isset($aces[$index])) { |
|
|
574 |
throw new \OutOfBoundsException(sprintf('The index "%d" does not exist.', $index)); |
|
|
575 |
} |
|
|
576 |
|
|
|
577 |
$ace = $aces[$index]; |
|
|
578 |
if ($mask !== $oldMask = $ace->getMask()) { |
|
|
579 |
$this->onEntryPropertyChanged($ace, 'mask', $oldMask, $mask); |
|
|
580 |
$ace->setMask($mask); |
|
|
581 |
} |
|
|
582 |
if (null !== $strategy && $strategy !== $oldStrategy = $ace->getStrategy()) { |
|
|
583 |
$this->onEntryPropertyChanged($ace, 'strategy', $oldStrategy, $strategy); |
|
|
584 |
$ace->setStrategy($strategy); |
|
|
585 |
} |
|
|
586 |
} |
|
|
587 |
|
|
|
588 |
/** |
|
|
589 |
* Updates auditing for an ACE |
|
|
590 |
* |
|
|
591 |
* @param array $aces |
|
|
592 |
* @param integer $index |
|
|
593 |
* @param Boolean $auditSuccess |
|
|
594 |
* @param Boolean $auditFailure |
|
|
595 |
* @throws \OutOfBoundsException |
|
|
596 |
* @return void |
|
|
597 |
*/ |
|
|
598 |
private function updateAuditing(array &$aces, $index, $auditSuccess, $auditFailure) |
|
|
599 |
{ |
|
|
600 |
if (!isset($aces[$index])) { |
|
|
601 |
throw new \OutOfBoundsException(sprintf('The index "%d" does not exist.', $index)); |
|
|
602 |
} |
|
|
603 |
|
|
|
604 |
if ($auditSuccess !== $aces[$index]->isAuditSuccess()) { |
|
|
605 |
$this->onEntryPropertyChanged($aces[$index], 'auditSuccess', !$auditSuccess, $auditSuccess); |
|
|
606 |
$aces[$index]->setAuditSuccess($auditSuccess); |
|
|
607 |
} |
|
|
608 |
|
|
|
609 |
if ($auditFailure !== $aces[$index]->isAuditFailure()) { |
|
|
610 |
$this->onEntryPropertyChanged($aces[$index], 'auditFailure', !$auditFailure, $auditFailure); |
|
|
611 |
$aces[$index]->setAuditFailure($auditFailure); |
|
|
612 |
} |
|
|
613 |
} |
|
|
614 |
|
|
|
615 |
/** |
|
|
616 |
* Updates a field-based ACE |
|
|
617 |
* |
|
|
618 |
* @param string $property |
|
|
619 |
* @param integer $index |
|
|
620 |
* @param string $field |
|
|
621 |
* @param integer $mask |
|
|
622 |
* @param string $strategy |
|
|
623 |
* @throws \InvalidArgumentException |
|
|
624 |
* @throws \OutOfBoundsException |
|
|
625 |
* @return void |
|
|
626 |
*/ |
|
|
627 |
private function updateFieldAce($property, $index, $field, $mask, $strategy = null) |
|
|
628 |
{ |
|
|
629 |
if (0 === strlen($field)) { |
|
|
630 |
throw new \InvalidArgumentException('$field cannot be empty.'); |
|
|
631 |
} |
|
|
632 |
|
|
|
633 |
$aces =& $this->$property; |
|
|
634 |
if (!isset($aces[$field][$index])) { |
|
|
635 |
throw new \OutOfBoundsException(sprintf('The index "%d" does not exist.', $index)); |
|
|
636 |
} |
|
|
637 |
|
|
|
638 |
$ace = $aces[$field][$index]; |
|
|
639 |
if ($mask !== $oldMask = $ace->getMask()) { |
|
|
640 |
$this->onEntryPropertyChanged($ace, 'mask', $oldMask, $mask); |
|
|
641 |
$ace->setMask($mask); |
|
|
642 |
} |
|
|
643 |
if (null !== $strategy && $strategy !== $oldStrategy = $ace->getStrategy()) { |
|
|
644 |
$this->onEntryPropertyChanged($ace, 'strategy', $oldStrategy, $strategy); |
|
|
645 |
$ace->setStrategy($strategy); |
|
|
646 |
} |
|
|
647 |
} |
|
|
648 |
|
|
|
649 |
/** |
|
|
650 |
* Called when a property of the ACL changes |
|
|
651 |
* |
|
|
652 |
* @param string $name |
|
|
653 |
* @param mixed $oldValue |
|
|
654 |
* @param mixed $newValue |
|
|
655 |
* @return void |
|
|
656 |
*/ |
|
|
657 |
private function onPropertyChanged($name, $oldValue, $newValue) |
|
|
658 |
{ |
|
|
659 |
foreach ($this->listeners as $listener) { |
|
|
660 |
$listener->propertyChanged($this, $name, $oldValue, $newValue); |
|
|
661 |
} |
|
|
662 |
} |
|
|
663 |
|
|
|
664 |
/** |
|
|
665 |
* Called when a property of an ACE associated with this ACL changes |
|
|
666 |
* |
|
|
667 |
* @param EntryInterface $entry |
|
|
668 |
* @param string $name |
|
|
669 |
* @param mixed $oldValue |
|
|
670 |
* @param mixed $newValue |
|
|
671 |
* @return void |
|
|
672 |
*/ |
|
|
673 |
private function onEntryPropertyChanged(EntryInterface $entry, $name, $oldValue, $newValue) |
|
|
674 |
{ |
|
|
675 |
foreach ($this->listeners as $listener) { |
|
|
676 |
$listener->propertyChanged($entry, $name, $oldValue, $newValue); |
|
|
677 |
} |
|
|
678 |
} |
|
|
679 |
} |