public function testToAclIdentityValidRole() { $identity = new SecurityIdentity(); $identity->setIdentifier('ROLE_ADMIN'); $identity->setUsername(false); $secIdentity = SecurityIdentity::toAclIdentity($identity); $this->assertInstanceOf('Symfony\\Component\\Security\\Acl\\Domain\\RoleSecurityIdentity', $secIdentity); $identity = new SecurityIdentity(); $identity->setIdentifier('IS_AUTHENTICATED_ANONYMOUSLY'); $identity->setUsername(false); $secIdentity = SecurityIdentity::toAclIdentity($identity); $this->assertInstanceOf('Symfony\\Component\\Security\\Acl\\Domain\\RoleSecurityIdentity', $secIdentity); }
/** * Constructor. * * @param \Propel\Bundle\PropelAclBundle\Model\Acl\Entry $entry * @param \Symfony\Component\Security\Acl\Model\AclInterface $acl */ public function __construct(ModelEntry $entry, AclInterface $acl) { $this->acl = $acl; $this->securityIdentity = SecurityIdentity::toAclIdentity($entry->getSecurityIdentity()); /* * A new ACE (from a MutableAcl) does not have an ID, * but will be persisted by the MutableAclProvider afterwards, if issued. */ if ($entry->getId()) { $this->id = $entry->getId(); } $this->mask = $entry->getMask(); $this->isGranting = $entry->getGranting(); $this->strategy = $entry->getGrantingStrategy(); $this->auditFailure = $entry->getAuditFailure(); $this->auditSuccess = $entry->getAuditSuccess(); }
/** * Returns the ACL that belongs to the given object identity. * * @throws \Symfony\Component\Security\Acl\Exception\AclNotFoundException * * @param \Symfony\Component\Security\Acl\Model\ObjectIdentityInterface $objectIdentity * @param array $securityIdentities * * @return \Symfony\Component\Security\Acl\Model\AclInterface */ public function findAcl(ObjectIdentityInterface $objectIdentity, array $securityIdentities = array()) { $modelObj = ObjectIdentityQuery::create()->findOneByAclObjectIdentity($objectIdentity, $this->connection); if (null !== $this->cache and null !== $modelObj) { $cachedAcl = $this->cache->getFromCacheById($modelObj->getId()); if ($cachedAcl instanceof AclInterface) { return $cachedAcl; } } $collection = EntryQuery::create()->findByAclIdentity($objectIdentity, $securityIdentities, $this->connection); if (0 === count($collection)) { if (empty($securityIdentities)) { $errorMessage = 'There is no ACL available for this object identity. Please create one using the MutableAclProvider.'; } else { $errorMessage = 'There is at least no ACL for this object identity and the given security identities. Try retrieving the ACL without security identity filter and add ACEs for the security identities.'; } throw new AclNotFoundException($errorMessage); } $loadedSecurityIdentities = array(); foreach ($collection as $eachEntry) { if (!isset($loadedSecurityIdentities[$eachEntry->getSecurityIdentity()->getId()])) { $loadedSecurityIdentities[$eachEntry->getSecurityIdentity()->getId()] = SecurityIdentity::toAclIdentity($eachEntry->getSecurityIdentity()); } } $parentAcl = null; $entriesInherited = true; if (null !== $modelObj) { $entriesInherited = $modelObj->getEntriesInheriting(); if (null !== $modelObj->getParentObjectIdentityId()) { $parentObj = $modelObj->getObjectIdentityRelatedByParentObjectIdentityId($this->connection); try { $parentAcl = $this->findAcl(new ObjectIdentity($parentObj->getIdentifier(), $parentObj->getAclClass($this->connection)->getType())); } catch (AclNotFoundException $e) { /* * This happens e.g. if the parent ACL is created, but does not contain any ACE by now. * The ACEs may be applied later on. */ } } } return $this->getAcl($collection, $objectIdentity, $loadedSecurityIdentities, $parentAcl, $entriesInherited); }