8000 [Security] some more visibility changes · jaimesuez/symfony@a64cc0e · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a64cc0e

Browse files
committed
[Security] some more visibility changes
1 parent 13665fc commit a64cc0e

File tree

2 files changed

+112
-114
lines changed

2 files changed

+112
-114
lines changed

src/Symfony/Component/Security/Acl/Dbal/AclProvider.php

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class AclProvider implements AclProviderInterface
3838
{
3939
const MAX_BATCH_SIZE = 30;
4040

41-
protected $aclCache;
41+
protected $cache;
4242
protected $connection;
4343
protected $loadedAces;
4444
protected $loadedAcls;
@@ -51,11 +51,11 @@ class AclProvider implements AclProviderInterface
5151
* @param Connection $connection
5252
* @param PermissionGrantingStrategyInterface $permissionGrantingStrategy
5353
* @param array $options
54-
* @param AclCacheInterface $aclCache
54+
* @param AclCacheInterface $cache
5555
*/
56-
public function __construct(Connection $connection, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $options, AclCacheInterface $aclCache = null)
56+
public function __construct(Connection $connection, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $options, AclCacheInterface $cache = null)
5757
{
58-
$this->aclCache = $aclCache;
58+
$this->cache = $cache;
5959
$this->connection = $connection;
6060
$this->loadedAces = array();
6161
$this->loadedAcls = array();
@@ -122,8 +122,8 @@ public function findAcls(array $oids, array $sids = array())
122122
}
123123

124124
// check if we can locate the ACL in the cache
125-
if (!$aclFound && null !== $this->aclCache) {
126-
$acl = $this->aclCache->getFromCacheByIdentity($oid);
125+
if (!$aclFound && null !== $this->cache) {
126+
$acl = $this->cache->getFromCacheByIdentity($oid);
127127

128128
if (null !== $acl) {
129129
if ($acl->isSidLoaded($sids)) {
@@ -149,10 +149,10 @@ public function findAcls(array $oids, array $sids = array())
149149
$result->attach($oid, $acl);
150150
$aclFound = true;
151151
} else {
152-
$this->aclCache->evictFromCacheByIdentity($oid);
152+
$this->cache->evictFromCacheByIdentity($oid);
153153

154154
foreach ($this->findChildren($oid) as $childOid) {
155-
$this->aclCache->evictFromCacheByIdentity($childOid);
155+
$this->cache->evictFromCacheByIdentity($childOid);
156156
}
157157
}
158158
}
@@ -170,8 +170,8 @@ public function findAcls(array $oids, array $sids = array())
170170
foreach ($loadedBatch as $loadedOid) {
171171
$loadedAcl = $loadedBatch->offsetGet($loadedOid);
172172

173-
if (null !== $this->aclCache) {
174-
$this->aclCache->putInCache($loadedAcl);
173+
if (null !== $this->cache) {
174+
$this->cache-& 579F gt;putInCache($loadedAcl);
175175
}
176176

177177
if (isset($oidLookup[$loadedOid->getIdentifier().$loadedOid->getType()])) {
@@ -204,20 +204,13 @@ public function findAcls(array $oids, array $sids = array())
204204
* Constructs the query used for looking up object identities and associated
205205
* ACEs, and security identities.
206206
*
207-
* @param array $batch
208-
* @param array $sids
209-
* @throws AclNotFoundException
207+
* @param array $ancestorIds
210208
* @return string
211209
*/
212-
protected function getLookupSql(array $batch, array $sids)
210+
protected fu B429 nction getLookupSql(array $ancestorIds)
213211
{
214212
// FIXME: add support for filtering by sids (right now we select all sids)
215213

216-
$ancestorIds = $this->getAncestorIds($batch);
217-
if (0 === count($ancestorIds)) {
218-
throw new AclNotFoundException('There is no ACL for the given object identity.');
219-
}
220-
221214
$sql = <<<SELECTCLAUSE
222215
SELECT
223216
o.id as acl_id,
@@ -346,7 +339,7 @@ protected function getSelectObjectIdentityIdSql(ObjectIdentityInterface $oid)
346339
* @param ObjectIdentityInterface $oid
347340
* @return integer
348341
*/
349-
protected function retrieveObjectIdentityPrimaryKey(ObjectIdentityInterface $oid)
342+
protected final function retrieveObjectIdentityPrimaryKey(ObjectIdentityInterface $oid)
350343
{
351344
return $this->connection->executeQuery($this->getSelectObjectIdentityIdSql($oid))->fetchColumn();
352345
}
@@ -428,7 +421,12 @@ private function doUpdateAceIdentityMap(array &$aces)
428421
*/
429422
private function lookupObjectIdentities(array $batch, array $sids, array $oidLookup)
430423
{
431-
$sql = $this->getLookupSql($batch, $sids);
424+
$ancestorIds = $this->getAncestorIds($batch);
425+
if (!$ancestorIds) {
426+
throw new AclNotFoundException('There is no ACL for the given object identity.');
427+
}
428+
429+
$sql = $this->getLookupSql($ancestorIds);
432430
$stmt = $this->connection->executeQuery($sql);
433431

434432
return $this->hydrateObjectIdentities($stmt, $oidLookup, $sids);

src/Symfony/Component/Security/Acl/Dbal/MutableAclProvider.php

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ class MutableAclProvider extends AclProvider implements MutableAclProviderInterf
3939
/**
4040
* {@inheritDoc}
4141
*/
42-
public function __construct(Connection $connection, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $options, AclCacheInterface $aclCache = null)
42+
public function __construct(Connection $connection, PermissionGrantingStrategyInterface $permissionGrantingStrategy, array $options, AclCacheInterface $cache = null)
4343
{
44-
parent::__construct($connection, $permissionGrantingStrategy, $options, $aclCache);
44+
parent::__construct($connection, $permissionGrantingStrategy, $options, $cache);
4545

4646
$this->propertyChanges = new \SplObjectStorage();
4747
}
@@ -104,8 +104,8 @@ public function deleteAcl(ObjectIdentityInterface $oid)
104104
}
105105

106106
// evict the ACL from any caches
107-
if (null !== $this->aclCache) {
108-
$this->aclCache->evictFromCacheByIdentity($oid);
107+
if (null !== $this->cache) {
108+
$this->cache->evictFromCacheByIdentity($oid);
109109
}
110110
}
111111

@@ -312,110 +312,25 @@ public function updateAcl(MutableAclInterface $acl)
312312

313313
$this->propertyChanges->offsetSet($acl, array());
314314

315-
if (null !== $this->aclCache) {
315+
if (null !== $this->cache) {
316316
if (count($sharedPropertyChanges) > 0) {
317317
// FIXME: Currently, there is no easy way to clear the cache for ACLs
318318
// of a certain type. 10000 The problem here is that we need to make
319319
// sure to clear the cache of all child ACLs as well, and these
320320
// child ACLs might be of a different class type.
321-
$this->aclCache->clearCache();
321+
$this->cache->clearCache();
322322
} else {
323323
// if there are no shared property changes, it's sufficient to just delete
324324
// the cache for this ACL
325-
$this->aclCache->evictFromCacheByIdentity($acl->getObjectIdentity());
325+
$this->cache->evictFromCacheByIdentity($acl->getObjectIdentity());
326326

327327
foreach ($this->findChildren($acl->getObjectIdentity()) as $childOid) {
328-
$this->aclCache->evictFromCacheByIdentity($childOid);
328+
$this->cache->evictFromCacheByIdentity($childOid);
329329
}
330330
}
331331
}
332332
}
333333

334-
/**
335-
* Creates the ACL for the passed object identity
336-
*
337-
* @param ObjectIdentityInterface $oid
338-
* @return void
339-
*/
340-
protected function createObjectIdentity(ObjectIdentityInterface $oid)
341-
{
342-
$classId = $this->createOrRetrieveClassId($oid->getType());
343-
344-
$this->connection->executeQuery($this->getInsertObjectIdentitySql($oid->getIdentifier(), $classId, true));
345-
}
346-
347-
/**
348-
* Returns the primary key for the passed class type.
349-
*
350-
* If the type does not yet exist in the database, it will be created.
351-
*
352-
* @param string $classType
353-
* @return integer
354-
*/
355-
protected function createOrRetrieveClassId($classType)
356-
{
357-
if (false !== $id = $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn()) {
358-
return $id;
359-
}
360-
361-
$this->connection->executeQuery($this->getInsertClassSql($classType));
362-
363-
return $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn();
364-
}
365-
366-
/**
367-
* Returns the primary key for the passed security identity.
368-
*
369-
* If the security identity does not yet exist in the database, it will be
370-
* created.
371-
*
372-
* @param SecurityIdentityInterface $sid
373-
* @return integer
374-
*/
375-
protected function createOrRetrieveSecurityIdentityId(SecurityIdentityInterface $sid)
376-
{
377-
if (false !== $id = $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn()) {
378-
return $id;
379-
}
380-
381-
$this->connection->executeQuery($this->getInsertSecurityIdentitySql($sid));
382-
383-
return $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn();
384-
}
385-
386-
/**
387-
* Deletes all ACEs for the given object identity primary key.
388-
*
389-
* @param integer $oidPK
390-
* @return void
391-
*/
392-
protected function deleteAccessControlEntries($oidPK)
393-
{
394-
$this->connection->executeQuery($this->getDeleteAccessControlEntriesSql($oidPK));
395-
}
396-
397-
/**
398-
* Deletes the object identity from the database.
399-
*
400-
* @param integer $pk
401-
* @return void
402-
*/
403-
protected function deleteObjectIdentity($pk)
404-
{
405-
$this->connection->executeQuery($this->getDeleteObjectIdentitySql($pk));
406-
}
407-
408-
/**
409-
* Deletes all entries from the relations table from the database.
410-
*
411-
* @param integer $pk
412-
* @return void
413-
*/
414-
protected function deleteObjectIdentityRelations($pk)
415-
{
416-
$this->connection->executeQuery($this->getDeleteObjectIdentityRelationsSql($pk));
417-
}
418-
419334
/**
420335
* Constructs the SQL for deleting access control entries.
421336
*
@@ -720,6 +635,91 @@ protected function getUpdateAccessControlEntrySql($pk, array $sets)
720635
);
721636
}
722637

638+
/**
639+
* Creates the ACL for the passed object identity
640+
*
641+
* @param ObjectIdentityInterface $oid
642+
* @return void
643+
*/
644+
private function createObjectIdentity(ObjectIdentityInterface $oid)
645+
{
646+
$classId = $this->createOrRetrieveClassId($oid->getType());
647+
648+
$this->connection->executeQuery($this->getInsertObjectIdentitySql($oid->getIdentifier(), $classId, true));
649+
}
650+
651+
/**
652+
* Returns the primary key for the passed class type.
653+
*
654+
* If the type does not yet exist in the database, it will be created.
655+
*
656+
* @param string $classType
657+
* @return integer
658+
*/
659+
private function createOrRetrieveClassId($classType)
660+
{
661+
if (false !== $id = $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn()) {
662+
return $id;
663+
}
664+
665+
$this->connection->executeQuery($this->getInsertClassSql($classType));
666+
667+
return $this->connection->executeQuery($this->getSelectClassIdSql($classType))->fetchColumn();
668+
}
669+
670+
/**
671+
* Returns the primary key for the passed security identity.
672+
*
673+
* If the security identity does not yet exist in the database, it will be
674+
* created.
675+
*
676+
* @param SecurityIdentityInterface $sid
677+
* @return integer
678+
*/
679+
private function createOrRetrieveSecurityIdentityId(SecurityIdentityInterface $sid)
680+
{
681+
if (false !== $id = $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn()) {
682+
return $id;
683+
}
684+
685+
$this->connection->executeQuery($this->getInsertSecurityIdentitySql($sid));
686+
687+
return $this->connection->executeQuery($this->getSelectSecurityIdentityIdSql($sid))->fetchColumn();
688+
}
689+
690+
/**
691+
* Deletes all ACEs for the given object identity primary key.
692+
*
693+
* @param integer $oidPK
694+
* @return void
695+
*/
696+
private function deleteAccessControlEntries($oidPK)
697+
{
698+
$this->connection->executeQuery($this->getDeleteAccessControlEntriesSql($oidPK));
699+
}
700+
701+
/**
702+
* Deletes the object identity from the database.
703+
*
704+
* @param integer $pk
705+
* @return void
706+
*/
707+
private function deleteObjectIdentity($pk)
708+
{
709+
$this->connection->executeQuery($this->getDeleteObjectIdentitySql($pk));
710+
}
711+
712+
/**
713+
* Deletes all entries from the relations table from the database.
714+
*
715+
* @param integer $pk
716+
* @return void
717+
*/
718+
private function deleteObjectIdentityRelations($pk)
719+
{
720+
$this->connection->executeQuery($this->getDeleteObjectIdentityRelationsSql($pk));
721+
}
722+
723723
/**
724724
* This regenerates the ancestor table which is used for fast read access.
725725
*

0 commit comments

Comments
 (0)
0