Skip to content

Instantly share code, notes, and snippets.

@gergelypolonkai
Created April 27, 2015 08:40
Show Gist options
  • Select an option

  • Save gergelypolonkai/883ace4f35e440f6fe0f to your computer and use it in GitHub Desktop.

Select an option

Save gergelypolonkai/883ace4f35e440f6fe0f to your computer and use it in GitHub Desktop.
Role and class based ACLs with Symfony 2
<?php
$this->get('security.context')->isGranted('ROLE_ADMIN');
<?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);
<?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