ACLに問題があります。SYMFONY2:ACL、ロール、ClassScope
私は、クラスのスコープを使用してロールの権限を与えます。
これはClassAceを宣言するために私のコードです:私は、ログ内のメッセージで、AccessDeniedExeptionを受け取る
$securityContext = $this->get('security.context');
$oid = new \Symfony\Component\Security\Acl\Domain\ObjectIdentity('class', 'Complete\\Class\\Name');
if (false === $securityContext->isGranted('EDIT', $oid))
{
throw new \Symfony\Component\Security\Core\Exception\AccessDeniedException();
}
:「いいえ
$objectIdentity = new \Symfony\Component\Security\Acl\Domain\ObjectIdentity('class', 'Complete\\Class\\Name');
try
{
$acl = $aclProvider->findAcl($objectIdentity);
}
catch (\Symfony\Component\Security\Acl\Exception\Exception $e)
{
$acl = $aclProvider->createAcl($objectIdentity);
}
// retrieving the security identity of the currently role
$securityIdentity = new \Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity($role);
// grant owner access
$acl->insertClassAce($securityIdentity, \Symfony\Component\Security\Acl\Permission\MaskBuilder::MASK_OWNER);
$aclProvider->updateAcl($acl);
そして、これは、アクセスをチェックするために私のコードです オブジェクトIDのACLが見つかりました。アクセスを拒否する投票です。
私は RoleSecurityIdentity
の対等機能を変更することでこの問題を解決することができ、元の関数が
public function equals(SecurityIdentityInterface $sid)
{
if (!$sid instanceof RoleSecurityIdentity) {
return false;
}
return $this->role === $sid->getRole();
}
である。しかし、私は
public function equals(SecurityIdentityInterface $sid)
{
if (!$sid instanceof RoleSecurityIdentity) {
return false;
}
return $this->role == $sid->getRole();
}
ことによってそれを変更する場合、それは動作します...
自分の役割クラスを使用していますm?
回答ありがとうございます。
こんにちは@anithalyは、その役割クラスの教義のエンティティクラスですか?私はあなたのデータベースにあなたの役割を保存しているのですか?私はここで同じ問題を抱えていますが、とにかく私の役割をデータベースに保存しようとしますが、ここで感謝を助けることができれば、私はうんざりします。 – metalvarez
symfonyのドキュメントでは、データベースにロールを保存する方法について説明し、Symfony \ Component \ Security \ Core \ Role \ Roleを拡張する必要があることも説明しています。データベース](http://symfony.com/doc/current/cookbook/security/entity_provider.html#managing-roles-in-the-database) – metalvarez