Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix/role security identity #5171

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

Closed
wants to merge 3 commits into from
Closed
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
14 changes: 10 additions & 4 deletions src/Symfony/Component/Security/Acl/Domain/RoleSecurityIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down