diff --git a/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php b/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php index 0d3d0d2ca2b14..41b9af1882944 100644 --- a/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php +++ b/src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Security\Acl\Domain; use Symfony\Component\Security\Acl\Model\SecurityIdentityInterface; -use Symfony\Component\Security\Core\Role\Role; +use Symfony\Component\Security\Core\Role\RoleInterface; /** * A SecurityIdentity implementation for roles @@ -26,14 +26,20 @@ final class RoleSecurityIdentity implements SecurityIdentityInterface /** * Constructor * - * @param mixed $role a Role instance, or its string representation + * @param mixed $role an object implementing RoleInterface, or its string representation */ public function __construct($role) { - if ($role instanceof Role) { + if (!is_string($role) && !($role instanceof RoleInterface)) { + throw new \InvalidArgumentException('$role must be a string or object implementing RoleInterface.'); + } + if ($role instanceof RoleInterface) { $role = $role->getRole(); } - + if (empty($role)) { + throw new \InvalidArgumentException('$role must not be empty.'); + } + $this->role = $role; } diff --git a/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php b/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php index 341f33ca48167..9da4129428d0c 100644 --- a/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php +++ b/src/Symfony/Component/Security/Tests/Acl/Domain/RoleSecurityIdentityTest.php @@ -30,7 +30,23 @@ public function testConstructorWithRoleInstance() $this->assertEquals('ROLE_FOO', $id->getRole()); } - + + /** + * @expectedException \InvalidArgumentException + */ + public function testInvalidParameterThrowsException() + { + $id = new RoleSecurityIdentity(0); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testEmptyParameterThrowsException() + { + $id = new RoleSecurityIdentity(''); + } + /** * @dataProvider getCompareData */