Created
April 27, 2015 08:40
-
-
Save gergelypolonkai/883ace4f35e440f6fe0f to your computer and use it in GitHub Desktop.
Role and class based ACLs with Symfony 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $this->get('security.context')->isGranted('ROLE_ADMIN'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $securityIdentity = new RoleSecurityIdentity('ROLE_ADMIN'); | |
| $objectIdentity = new ObjectIdentity('newsClass', 'Acme\\DemoBundle\\Entity\\News'); | |
| $acl = $aclProvider->createAcl($objectIdentity); | |
| $acl->insertClassAce($securityIdentity, MaskBuilder::MASK_OWNER); | |
| $aclProvider->updateAcl($acl); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $this->objectIdentity = new ObjectIdentity(self::OBJECT_ID, self::OBJECT_FQCN); | |
| if ($this->securityContext->isGranted('OWNER', $this->objectIdentity) === false) { | |
| throw new AccessDeniedException('You don’t have the required permissions!'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment