Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop entry acl #6

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Dbal/AclProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ public function __construct(Connection $connection, PermissionGrantingStrategyIn
$this->permissionGrantingStrategy = $permissionGrantingStrategy;
}

/**
* {@inheritdoc}
*/
public function releaseMemory()
{
$this->loadedAces = array();
$this->loadedAcls = array();
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -615,9 +624,9 @@ private function hydrateObjectIdentities(Statement $stmt, array $oidLookup, arra
}

if (null === $fieldName) {
$loadedAces[$aceId] = new Entry((int) $aceId, $acl, $sids[$key], $grantingStrategy, (int) $mask, !!$granting, !!$auditFailure, !!$auditSuccess);
$loadedAces[$aceId] = new Entry((int) $aceId, $sids[$key], $grantingStrategy, (int) $mask, !!$granting, !!$auditFailure, !!$auditSuccess);
} else {
$loadedAces[$aceId] = new FieldEntry((int) $aceId, $acl, $fieldName, $sids[$key], $grantingStrategy, (int) $mask, !!$granting, !!$auditFailure, !!$auditSuccess);
$loadedAces[$aceId] = new FieldEntry((int) $aceId, $fieldName, $sids[$key], $grantingStrategy, (int) $mask, !!$granting, !!$auditFailure, !!$auditSuccess);
}
}
$ace = $loadedAces[$aceId];
Expand Down
45 changes: 27 additions & 18 deletions Dbal/MutableAclProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use Symfony\Component\Security\Acl\Exception\AclAlreadyExistsException;
use Symfony\Component\Security\Acl\Exception\ConcurrentModificationException;
use Symfony\Component\Security\Acl\Model\AclCacheInterface;
use Symfony\Component\Security\Acl\Model\AclEntryInterface;
use Symfony\Component\Security\Acl\Model\AclInterface;
use Symfony\Component\Security\Acl\Model\EntryInterface;
use Symfony\Component\Security\Acl\Model\MutableAclInterface;
use Symfony\Component\Security\Acl\Model\MutableAclProviderInterface;
use Symfony\Component\Security\Acl\Model\ObjectIdentityInterface;
Expand All @@ -45,6 +45,15 @@ public function __construct(Connection $connection, PermissionGrantingStrategyIn
$this->propertyChanges = new \SplObjectStorage();
}

/**
* {@inheritdoc}
*/
public function releaseMemory()
{
parent::releaseMemory();
$this->propertyChanges = new \SplObjectStorage();
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -166,17 +175,17 @@ public function findAcls(array $oids, array $sids = array())
*/
public function propertyChanged($sender, $propertyName, $oldValue, $newValue)
{
if (!$sender instanceof MutableAclInterface && !$sender instanceof EntryInterface) {
throw new \InvalidArgumentException('$sender must be an instance of MutableAclInterface, or EntryInterface.');
if (!$sender instanceof MutableAclInterface && !$sender instanceof AclEntryInterface) {
throw new \InvalidArgumentException('$sender must be an instance of MutableAclInterface, or AclEntryInterface.');
}

if ($sender instanceof EntryInterface) {
if (null === $sender->getId()) {
if ($sender instanceof AclEntryInterface) {
if (null === $sender->getEntry()->getId()) {
return;
}

$ace = $sender;
$sender = $ace->getAcl();
$ace = $sender->getEntry();
$sender = $sender->getAcl();
} else {
$ace = null;
}
Expand Down Expand Up @@ -291,18 +300,18 @@ public function updateAcl(MutableAclInterface $acl)

// check properties for deleted, and created ACEs, and perform creations
if (isset($propertyChanges['classAces'])) {
$this->updateNewAceProperty('classAces', $propertyChanges['classAces']);
$this->updateNewAceProperty('classAces', $propertyChanges['classAces'], $acl);
$sharedPropertyChanges['classAces'] = $propertyChanges['classAces'];
}
if (isset($propertyChanges['classFieldAces'])) {
$this->updateNewFieldAceProperty('classFieldAces', $propertyChanges['classFieldAces']);
$this->updateNewFieldAceProperty('classFieldAces', $propertyChanges['classFieldAces'], $acl);
$sharedPropertyChanges['classFieldAces'] = $propertyChanges['classFieldAces'];
}
if (isset($propertyChanges['objectAces'])) {
$this->updateNewAceProperty('objectAces', $propertyChanges['objectAces']);
$this->updateNewAceProperty('objectAces', $propertyChanges['objectAces'], $acl);
}
if (isset($propertyChanges['objectFieldAces'])) {
$this->updateNewFieldAceProperty('objectFieldAces', $propertyChanges['objectFieldAces']);
$this->updateNewFieldAceProperty('objectFieldAces', $propertyChanges['objectFieldAces'], $acl);
}

// if there have been changes to shared properties, we need to synchronize other
Expand Down Expand Up @@ -829,7 +838,7 @@ private function deleteObjectIdentityRelations($pk)
*
* @param AclInterface $acl
*/
private function regenerateAncestorRelations(AclInterface $acl)
private function regenerateAncestorRelations(MutableAclInterface $acl)
{
$pk = $acl->getId();
$this->connection->executeQuery($this->getDeleteObjectIdentityRelationsSql($pk));
Expand All @@ -849,7 +858,7 @@ private function regenerateAncestorRelations(AclInterface $acl)
* @param string $name
* @param array $changes
*/
private function updateNewFieldAceProperty($name, array $changes)
private function updateNewFieldAceProperty($name, array $changes, MutableAclInterface $acl)
{
$sids = new \SplObjectStorage();
$classIds = new \SplObjectStorage();
Expand All @@ -864,14 +873,14 @@ private function updateNewFieldAceProperty($name, array $changes)
$sid = $this->createOrRetrieveSecurityIdentityId($ace->getSecurityIdentity());
}

$oid = $ace->getAcl()->getObjectIdentity();
$oid = $acl->getObjectIdentity();
if ($classIds->contains($oid)) {
$classId = $classIds->offsetGet($oid);
} else {
$classId = $this->createOrRetrieveClassId($oid->getType());
}

$objectIdentityId = $name === 'classFieldAces' ? null : $ace->getAcl()->getId();
$objectIdentityId = $name === 'classFieldAces' ? null : $acl->getId();

$this->connection->executeQuery($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, $field, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, $field, $i))->fetchColumn();
Expand Down Expand Up @@ -922,7 +931,7 @@ private function updateOldFieldAceProperty($name, array $changes)
* @param string $name
* @param array $changes
*/
private function updateNewAceProperty($name, array $changes)
private function updateNewAceProperty($name, array $changes, MutableAclInterface $acl)
{
list($old, $new) = $changes;

Expand All @@ -938,14 +947,14 @@ private function updateNewAceProperty($name, array $changes)
$sid = $this->createOrRetrieveSecurityIdentityId($ace->getSecurityIdentity());
}

$oid = $ace->getAcl()->getObjectIdentity();
$oid = $acl->getObjectIdentity();
if ($classIds->contains($oid)) {
$classId = $classIds->offsetGet($oid);
} else {
$classId = $this->createOrRetrieveClassId($oid->getType());
}

$objectIdentityId = $name === 'classAces' ? null : $ace->getAcl()->getId();
$objectIdentityId = $name === 'classAces' ? null : $acl->getId();

$this->connection->executeQuery($this->getInsertAccessControlEntrySql($classId, $objectIdentityId, null, $i, $sid, $ace->getStrategy(), $ace->getMask(), $ace->isGranting(), $ace->isAuditSuccess(), $ace->isAuditFailure()));
$aceId = $this->connection->executeQuery($this->getSelectAccessControlEntryIdSql($classId, $objectIdentityId, null, $i))->fetchColumn();
Expand Down
8 changes: 4 additions & 4 deletions Domain/Acl.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ private function insertAce($property, $index, $mask, SecurityIdentityInterface $
}
}

$aces[$index] = new Entry(null, $this, $sid, $strategy, $mask, $granting, false, false);
$aces[$index] = new Entry(null, $sid, $strategy, $mask, $granting, false, false);
$this->onPropertyChanged($property, $oldValue, $this->$property);
}

Expand Down Expand Up @@ -543,7 +543,7 @@ private function insertFieldAce($property, $index, $field, $mask, SecurityIdenti
}
}

$aces[$field][$index] = new FieldEntry(null, $this, $field, $sid, $strategy, $mask, $granting, false, false);
$aces[$field][$index] = new FieldEntry(null, $field, $sid, $strategy, $mask, $granting, false, false);
$this->onPropertyChanged($property, $oldValue, $this->$property);
}

Expand Down Expand Up @@ -620,7 +620,7 @@ private function updateFieldAce($property, $index, $field, $mask, $strategy = nu
throw new \InvalidArgumentException('$field cannot be empty.');
}

$aces = &$this->$property;
$aces = $this->$property;
if (!isset($aces[$field][$index])) {
throw new \OutOfBoundsException(sprintf('The index "%d" does not exist.', $index));
}
Expand Down Expand Up @@ -661,7 +661,7 @@ private function onPropertyChanged($name, $oldValue, $newValue)
private function onEntryPropertyChanged(EntryInterface $entry, $name, $oldValue, $newValue)
{
foreach ($this->listeners as $listener) {
$listener->propertyChanged($entry, $name, $oldValue, $newValue);
$listener->propertyChanged(new AclEntry($this, $entry), $name, $oldValue, $newValue);
}
}
}
49 changes: 49 additions & 0 deletions Domain/AclEntry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Security\Acl\Domain;

use Symfony\Component\Security\Acl\Model\AclEntryInterface;
use Symfony\Component\Security\Acl\Model\AclInterface;
use Symfony\Component\Security\Acl\Model\EntryInterface;

/**
* AclEntry
*
* @author Evgeniy Sokolov <[email protected]>
*/
class AclEntry implements AclEntryInterface
{
private $acl;
private $entry;

public function __construct(AclInterface $acl, EntryInterface $entry)
{
$this->acl = $acl;
$this->entry = $entry;
}

/**
* @return AclInterface
*/
public function getAcl()
{
return $this->acl;
}

/**
* @return EntryInterface
*/
public function getEntry()
{
return $this->entry;
}
}
30 changes: 0 additions & 30 deletions Domain/DoctrineAclCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,36 +169,6 @@ private function unserializeAcl($serialized)
$reflectionProperty->setValue($acl, $this->permissionGrantingStrategy);
$reflectionProperty->setAccessible(false);

$aceAclProperty = new \ReflectionProperty('Symfony\Component\Security\Acl\Domain\Entry', 'acl');
$aceAclProperty->setAccessible(true);

foreach ($acl->getObjectAces() as $ace) {
$aceAclProperty->setValue($ace, $acl);
}
foreach ($acl->getClassAces() as $ace) {
$aceAclProperty->setValue($ace, $acl);
}

$aceClassFieldProperty = new \ReflectionProperty($acl, 'classFieldAces');
$aceClassFieldProperty->setAccessible(true);
foreach ($aceClassFieldProperty->getValue($acl) as $aces) {
foreach ($aces as $ace) {
$aceAclProperty->setValue($ace, $acl);
}
}
$aceClassFieldProperty->setAccessible(false);

$aceObjectFieldProperty = new \ReflectionProperty($acl, 'objectFieldAces');
$aceObjectFieldProperty->setAccessible(true);
foreach ($aceObjectFieldProperty->getValue($acl) as $aces) {
foreach ($aces as $ace) {
$aceAclProperty->setValue($ace, $acl);
}
}
$aceObjectFieldProperty->setAccessible(false);

$aceAclProperty->setAccessible(false);

return $acl;
}

Expand Down
13 changes: 1 addition & 12 deletions Domain/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
*/
class Entry implements AuditableEntryInterface
{
private $acl;
private $mask;
private $id;
private $securityIdentity;
Expand All @@ -35,18 +34,16 @@ class Entry implements AuditableEntryInterface
* Constructor.
*
* @param int $id
* @param AclInterface $acl
* @param SecurityIdentityInterface $sid
* @param string $strategy
* @param int $mask
* @param bool $granting
* @param bool $auditFailure
* @param bool $auditSuccess
*/
public function __construct($id, AclInterface $acl, SecurityIdentityInterface $sid, $strategy, $mask, $granting, $auditFailure, $auditSuccess)
public function __construct($id, SecurityIdentityInterface $sid, $strategy, $mask, $granting, $auditFailure, $auditSuccess)
{
$this->id = $id;
$this->acl = $acl;
$this->securityIdentity = $sid;
$this->strategy = $strategy;
$this->mask = $mask;
Expand All @@ -55,14 +52,6 @@ public function __construct($id, AclInterface $acl, SecurityIdentityInterface $s
$this->auditSuccess = $auditSuccess;
}

/**
* {@inheritdoc}
*/
public function getAcl()
{
return $this->acl;
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 2 additions & 3 deletions Domain/FieldEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class FieldEntry extends Entry implements FieldEntryInterface
* Constructor.
*
* @param int $id
* @param AclInterface $acl
* @param string $field
* @param SecurityIdentityInterface $sid
* @param string $strategy
Expand All @@ -37,9 +36,9 @@ class FieldEntry extends Entry implements FieldEntryInterface
* @param bool $auditFailure
* @param bool $auditSuccess
*/
public function __construct($id, AclInterface $acl, $field, SecurityIdentityInterface $sid, $strategy, $mask, $granting, $auditFailure, $auditSuccess)
public function __construct($id, $field, SecurityIdentityInterface $sid, $strategy, $mask, $granting, $auditFailure, $auditSuccess)
{
parent::__construct($id, $acl, $sid, $strategy, $mask, $granting, $auditFailure, $auditSuccess);
parent::__construct($id, $sid, $strategy, $mask, $granting, $auditFailure, $auditSuccess);

$this->field = $field;
}
Expand Down
37 changes: 37 additions & 0 deletions Model/AclEntryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Security\Acl\Model;

/**
* This class represents an entry and acl.
*
* Instances MUST be immutable, as they are returned by the ACL and should not
* allow client modification.
*
* @author Evgeniy Sokolov <[email protected]>
*/
interface AclEntryInterface
{
/**
* Acl
*
* @return AclInterface
*/
public function getAcl();

/**
* Entry
*
* @return EntryInterface
*/
public function getEntry();
}
7 changes: 7 additions & 0 deletions Model/AclProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ public function findAcl(ObjectIdentityInterface $oid, array $sids = array());
* @throws AclNotFoundException when we cannot find an ACL for all identities
*/
public function findAcls(array $oids, array $sids = array());

/**
* AclProvider for better performance can save some information in memory.
* You can ask provider to free this memory if you perform many calls
* @return void
*/
public function releaseMemory();
}
Loading