Problematic/ProblematicAclManagerBundle — Issue #15: Replaces all current permissions with this new one is not working as expected
Author: mailaneel
Created: 2012-02-25 04:32:07+00:00
State: open

If i call the below code 2 times i expect to see only one ACE added to the table, but i am seeing 2 entries.

$aclManager->setClassPermission($entity,MaskBuilder::MASK_OPERATOR,'ROLE_CLIENT');

I think the problem is in the below code, because $context->hasDifferentPermission($aceCollection[$i]) returns false when i create the same acl second time.
AclAbstractManager->doApplyPermission

```php
$updated = false;

$aceCollection = $this->getAceCollection($acl, $context->getPermissionType());
$size = count($aceCollection) - 1;
reset($aceCollection);
for ($i = $size; $i >= 0; $i--) {
if($replace_existing){
// Replace all existing permissions with the new one
if ($context->hasDifferentPermission($aceCollection[$i])) {
// The ACE was found but with a different permission. Update it.
$acl->{"update{$type}Ace"}($i, $context->getMask());
$updated = true;
}
} else {
if($context->equals($aceCollection[$i])){
// The exact same ACE was found. Nothing to do.
return;
}
}
}
if(!$updated){
$type = $context->getPermissionType();
$acl->{"insert{$type}Ace"}($context->getSecurityIdentity(), $context->getMask(), 0, $context->isGranting());
}

```

If we update the above code like this it is working as expected.

```php

$insertAce = true;
$type = $context->getPermissionType();

$aceCollection = $this->getAceCollection($acl, $context->getPermissionType());
$size = count($aceCollection) - 1;
reset($aceCollection);
for ($i = $size; $i >= 0; $i--) {
if($replace_existing){
// Replace all existing permissions with the new one
if ($context->hasDifferentPermission($aceCollection[$i])) {
// The ACE was found but with a different permission. Update it.
$acl->{"update{$type}Ace"}($i, $context->getMask());
}
$insertAce = false;
} else {
if($context->equals($aceCollection[$i])){
// The exact same ACE was found. Nothing to do.
return;
}
}
}
if($insertAce){
$acl->{"insert{$type}Ace"}($context->getSecurityIdentity(), $context->getMask(), 0, $context->isGranting());
}

```