1

Symfony2 ACLを使い始めたばかりですが、割り当てられたユーザーでオブジェクトにアクセスできません。説明させてください:

一部のオブジェクトの特定のユーザーにアクセス許可を割り当てます。私はロードデータフィクスチャでそれを行います:

    // creating the ACL
    $aclProvider = $this->container->get('security.acl.provider');
    $objectIdentity = ObjectIdentity::fromDomainObject($order); //entity

    try {
        $acl = $aclProvider->findAcl($objectIdentity);
    } catch (\Symfony\Component\Security\Acl\Exception\Exception $e) {
        $acl = $aclProvider->createAcl($objectIdentity);
    }

    // retrieving the security identity of the currently logged-in user
    $securityIdentity = UserSecurityIdentity::fromAccount($user);

    // grant owner access
    $acl->insertObjectAce($securityIdentity, MaskBuilder::MASK_OWNER);
    $aclProvider->updateAcl($acl);

また、クラスのすべてのオブジェクトへのアクセス許可を役割ADMINに割り当てたいので、次のコマンドを使用します。

    $output->writeln('<info>Adding Order OWNER ACE to role ROLE_ADMIN</info>');

    $aclProvider = $this->getContainer()->get('security.acl.provider');
    $objectIdentity = new ObjectIdentity('class', 'VendorName\XXXBundle\Entity\Order');

    try {
        $acl = $aclProvider->findAcl($objectIdentity);
    } catch (\Symfony\Component\Security\Acl\Exception\Exception $e) {
        $acl = $aclProvider->createAcl($objectIdentity);
    }

    $em = $entityManager = $this->getContainer()->get('doctrine')->getEntityManager();
    $role = $em->getRepository('VendorNameXXXBundle:Role')->findOneByRole('ROLE_ADMIN');

    $securityIdentity = new RoleSecurityIdentity($role->getRole());
    $acl->insertClassAce($securityIdentity, MaskBuilder::MASK_OWNER);
    $aclProvider->updateAcl($acl);

Symfony2がこれらのパーミッションを検出するようにできません。2人のユーザーと接続し、Twigから接続する場合:

    {% if is_granted('VIEW', entity) %}
    <tr>
        <td colspan="12">Authorized!</td>
    </tr>
    {% else %}
    <tr>
        <td colspan="12">You are not authorized</td>
    </tr>
    {% endif %}

私はいつも「あなたは許可されていません」と言います。

コントローラからも試しましたが、同じ結果になりました。

    $securityContext = $this->get('security.context');

    if (false === $securityContext->isGranted('EDIT', $entity))
    {
        throw new \Symfony\Component\Security\Core\Exception\AccessDeniedException;
    }

    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Order entity.');
    }
4

0 に答える 0