php - Symfony2 : ClassACE and ObjectACE

标签 php symfony acl

ACL 类对该类的所有对象都有权限吗? 或者只拥有自身的权限而没有对象的权限? 让我解释一下 Symfony2:

我有一个实体订单和 5 个已创建的订单。如果我向类 Order 授予所有者权限,我是否有权编辑所有对象?

$objectIdentity = new ObjectIdentity('class', 'Acme\DemoBundle\Entity\Order');
$securityIdentity = new RoleSecurityIdentity($role->getRole());
$acl = $aclProvider->createAcl($objectIdentity);
$acl->insertClassAce($securityIdentity, MaskBuilder::MASK_OWNER);
$aclProvider->updateAcl($acl);

编辑 实际上我有两个问题:

第一个问题: 我遇到的问题是当我使用 RoleSecurityIdentity 时。它对我不起作用。如果我使用 UserSecurityIdentity 对于每个对象都可以完美工作。 这个例子运行良好:

    foreach($orders as $order) {
        $objectIdentity = ObjectIdentity::fromDomainObject($salesOrder);
        $acl = $aclProvider->createAcl($objectIdentity);
        $securityIdentity = new UserSecurityIdentity(
          'admin', 
          'Acme\CoreBundle\Entity\User');
        $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER);
        $aclProvider->updateAcl($acl);
    }

用户管理员拥有所有者授予权!

这个例子不起作用:

    foreach($orders as $order) {
        $objectIdentity = ObjectIdentity::fromDomainObject($salesOrder);
        $acl = $aclProvider->createAcl($objectIdentity);
        $securityIdentity = new RoleSecurityIdentity('ROLE_ADMIN');
        $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER);
        $aclProvider->updateAcl($acl);
    }

拥有 ROLE_ADMIN 的用户没有对象授权!

第二个问题: 如果我将 OWNER 授予应用于类 Order,我没有授予访问实体的权限:让我解释一下:

    $objectIdentity = new ObjectIdentity('class', 'Neventum\PaymentBundle\Entity\SalesOrder');
    $acl = $aclProvider->createAcl($objectIdentity);
    $securityIdentity = UserSecurityIdentity::fromAccount($admin);
    $acl->insertClassAce($securityIdentity, MaskBuilder::MASK_OWNER);
    $aclProvider->updateAcl($acl);

我需要管理员用户始终有权访问订单实体的所有对象。

最佳答案

我已经修好了!

问题出在用户实体的 getRoles 方法上。

之前是这样的:

function getRoles() {
    return $this->roles->toArray();
}

我已更改为:

function getRoles()
{
    $roles = array();
    foreach($this->userRoles as $userRole) {
        $roles[] = $userRole->getRole();
    }
    return $roles;
}

如果有人知道为什么我会感激

关于php - Symfony2 : ClassACE and ObjectACE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12260048/

相关文章:

php - 使用PHP从多个表中获取具有相同名称的列

php - www 和 https 的 htaccess 重定向问题

php - 如何将 Laravel 用户名添加到 nginx 的访问日志中?

php - 如何摆脱 "Uncaught SoapFault exception: [Client] looks like we got no XML document in..."错误

Symfony2 createQuery 按字段排序

基于 Django 角色的 View ?

php - Symfony/学说 : How to make Doctrine working with Unix socket?

php - Symfony2 电子邮件主题翻译。命令和 Controller 之间的区别

acl - Azure Databricks 创建的 Azure ADLS Gen2 文件不继承 ACL

ElasticSearch 内容 ACL 过滤性能