This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security][ACL] Fixed ObjectIdentity::fromDomainObject and UserSecuri…
…tyIdentity::from(Account|Token) when working with proxies Backported ClassUtils class from Doctrine Common 2.2 Fixes #2611, #2056, #2048, #2035
- Loading branch information
Showing
6 changed files
with
200 additions
and
68 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Security\Core\Util; | ||
|
||
/** | ||
* Class related functionality for objects that | ||
* might or might not be proxy objects at the moment. | ||
* | ||
* @see Doctrine\Common\Util\ClassUtils | ||
* | ||
* @author Benjamin Eberlei <kontakt@beberlei.de> | ||
* @author Johannes Schmitt <schmittjoh@gmail.com> | ||
*/ | ||
class ClassUtils | ||
{ | ||
/** | ||
* Marker for Proxy class names. | ||
* | ||
* @var string | ||
*/ | ||
const MARKER = '__CG__'; | ||
|
||
/** | ||
* Length of the proxy marker | ||
* | ||
* @var int | ||
*/ | ||
const MARKER_LENGTH = 6; | ||
|
||
/** | ||
* Gets the real class name of a class name that could be a proxy. | ||
* | ||
* @param string|object | ||
* @return string | ||
*/ | ||
public static function getRealClass($object) | ||
{ | ||
$class = is_object($object) ? get_class($object) : $object; | ||
|
||
if (false === $pos = strrpos($class, '\\'.self::MARKER.'\\')) { | ||
return $class; | ||
} | ||
|
||
return substr($class, $pos + self::MARKER_LENGTH + 2); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\Security\Tests\Core\Util | ||
{ | ||
use Symfony\Component\Security\Core\Util\ClassUtils; | ||
|
||
class ClassUtilsTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
static public function dataGetClass() | ||
{ | ||
return array( | ||
array('stdClass', 'stdClass'), | ||
array('Symfony\Component\Security\Core\Util\ClassUtils', 'Symfony\Component\Security\Core\Util\ClassUtils'), | ||
array('MyProject\Proxies\__CG__\stdClass', 'stdClass'), | ||
array('MyProject\Proxies\__CG__\OtherProject\Proxies\__CG__\stdClass', 'stdClass'), | ||
array('MyProject\Proxies\__CG__\Symfony\Component\Security\Tests\Core\Util\ChildObject', 'Symfony\Component\Security\Tests\Core\Util\ChildObject'), | ||
array(new TestObject(), 'Symfony\Component\Security\Tests\Core\Util\TestObject'), | ||
array(new \Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Core\Util\TestObject(), 'Symfony\Component\Security\Tests\Core\Util\TestObject'), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider dataGetClass | ||
*/ | ||
public function testGetRealClass($object, $expectedClassName) | ||
{ | ||
$this->assertEquals($expectedClassName, ClassUtils::getRealClass($object)); | ||
} | ||
} | ||
|
||
class TestObject | ||
{ | ||
} | ||
} | ||
|
||
namespace Acme\DemoBundle\Proxy\__CG__\Symfony\Component\Security\Tests\Core\Util | ||
{ | ||
class TestObject extends \Symfony\Component\Security\Tests\Core\Util\TestObject | ||
{ | ||
} | ||
} |