Skip to content

Commit

Permalink
Document ACL Manager addition
Browse files Browse the repository at this point in the history
  • Loading branch information
curiosity26 committed Nov 5, 2018
1 parent be58ebe commit a647685
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,59 @@ class MyController extends FOSRestController implements ClassResourceInterface {
}
}

```

## ACL Manager

To make it easier to build ACLs, the ACL Manager was created. It's pretty much just a chain wrapper
that allows the ACL to be found/created and ACEs to be inserted, updated or deleted.

### Example

```php
<?php

namespace App\Controller;

use Curiosity26\AclHelperBundle\Helper\AclHelper;
use Curiosity26\AclHelperBundle\Tests\Entity\TestObject;
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
use Symfony\Component\Security\Acl\Permission\MaskBuilder;

class MyController extends FOSRestController implements ClassResourceInterface {

/**
* @var AclHelper
*/
private $aclHelper;

public function __construct(AclHelper $aclHelper)
{
$this->aclHelper = $aclHelper;
}

public function postAction(TestObject $object)
{
$manager = $this->getDoctrine()->getManager();
$manager->persist($object);

$aclManager = $this->aclHelper->createAclManager();

// The current user needs to be the owner
// The ROLE_ADMIN must have view, edit, delete permissions
// ROLE_USER users should be able to view
$aclManager->aclFor($object)
->insertObjectAce(UserSecurityIdentity::fromAccount($this->getUser()), MaskBuilder::MASK_OWNER)
->insertObjectAce(
new RoleSecurityIdentity('ROLE_ADMIN'),
MaskBuilder::MASK_VIEW | MaskBuilder::MASK_EDIT | MaskBuilder::MASK_DELETE
)
->insertObjectAce(new RoleSecurityIdentity('ROLE_USER'), MaskBuilder::MASK_VIEW)
->save()
;

return $this->view(null, 201);
}
}
```

0 comments on commit a647685

Please sign in to comment.