Symfony ACL-如何更新ACL对象?

Symfony ACL-如何更新ACL对象?,symfony,acl,Symfony,Acl,我想更新以前编写的ACL或插入新的ACL(如果不存在)。我想做的不是工作: public function upgradeUser(User $user, Model $model) { $acl = null; $objectIdentity = ObjectIdentity::fromDomainObject($model); $securityIdentity= UserSecurityIdentity::fromAccount($u

我想更新以前编写的ACL或插入新的ACL(如果不存在)。我想做的不是工作:

public function upgradeUser(User $user, Model $model)
    {
        $acl = null;
        $objectIdentity = ObjectIdentity::fromDomainObject($model);
        $securityIdentity= UserSecurityIdentity::fromAccount($user);

        try {
            $acl = $this->aclProvider->findAcl($objectIdentity);

            /** @var Entry[] $aces */
            $aces = $acl->getObjectAces();
            foreach($aces as $i => $ace) {
                if ($securityIdentity->equals($securityIdentity)) {
                    $acl->updateObjectAce($i, $ace->getMask() & MaskBuilder::MASK_OPERATOR);
                }
            }

        } catch (AclNotFoundException $e) {
            $acl = $this->aclProvider->createAcl($objectIdentity);
            $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OPERATOR);
        }

        $this->aclProvider->updateAcl($acl);
    }

问题是因为错误的插入过程。解决方案是在未找到更新的objected时使用InserObjectAcl方法:

protected function addMask(SecurityIdentityInterface $securityIdentity, $mask, $acl, $appendMask = true)
    {
        // flag to determine if mask was really updated or not
        $isUpdated = false;

        // go throw all aces and try to find current user's ace
        foreach ($acl->getObjectAces() as $ace) {
            if (!($ace instanceof Entry) || !$ace->getSecurityIdentity()->equals($securityIdentity))
                continue;

            $maskBuilder = new MaskBuilder($appendMask ? $ace->getMask() : 0);
            $maskBuilder->add($mask);
            $ace->setMask($maskBuilder->get());

            $isUpdated = true;
            break;
        }

        // in the case if object was not found in aces for this user, insert a new ace
        if ($isUpdated === false)
            $acl->insertObjectAce($securityIdentity, $mask);
    }

插入部分不起作用吗?或者两者都起作用?对我来说,插入似乎不应该发生,因为若找不到用户,您永远不会抛出任何异常。它会显示任何消息吗?是否确定使用掩码_运算符生成正确的掩码?是否检查实体是否与自身相同$securityIdentity->equals$securityIdentity@galago对不起,是打字错误。我已经找到了解决方案,请参见下面的答案