0

我正在为 Symfony 2 使用 Easy Admin Bundle,但在 security.yml 中设置 ACL 时遇到问题。它没有考虑 url 参数,所以我需要重写 URL。

当前的:

.../admin/?entity=User&action=list&menuIndex=0&submenuIndex=-1

这是我需要的:

.../admin/User/?action=list&menuIndex=0&submenuIndex=-1

之后很容易从以下位置设置 ACL:

access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }

类似于:

access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/files/, role: ROLE_USER }
        - { path: ^/admin/user/, role: ROLE_ADMIN }

或者:

access_control:
            - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/admin/, role: ROLE_USER }
            - { path: ^/files/, role: ROLE_USER }
            - { path: ^/user/, role: ROLE_ADMIN }

或者也许有一些不同的方法?

4

1 回答 1

1

好的,这是解决方案:

https://github.com/javiereguiluz/EasyAdminBundle/issues/1076

只需编辑您的 config.yml,就像在示例中一样:

BlogEntry:
            class: AppBundle\Entity\BlogEntry
            permissions:
                list:  ['ROLE_ADMIN', 'ROLE_EDITOR']
                create:  ['ROLE_ADMIN']
                edit:  ['ROLE_ADMIN', 'ROLE_EDITOR']
                delete:  ['ROLE_ADMIN']

然后覆盖 EasyAdmin AdminController 并覆盖 indexAction 方法:

namespace AppBundle\Controller;

use JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController as EasyAdminController;

class AdminController extends EasyAdminController
{
    /**
     * @Route("/", name="easyadmin")
     *
     * @param Request $request
     *
     * @return RedirectResponse|Response
     */
    public function indexAction(Request $request)
    {
        $this->initialize($request);

        if (null === $request->query->get('entity')) {
            return $this->redirectToBackendHomepage();
        }

        $action = $request->query->get('action', 'list');
        if (!$this->isActionAllowed($action)) {
            throw new ForbiddenActionException(array('action' => $action, 'entity' => $this->entity['name']));
        }

        if (isset($this->entity['permissions'][$action])) {
            $this->denyAccessUnlessGranted($this->entity['permissions'][$action]);
        }

        return $this->executeDynamicMethod($action.'<EntityName>Action');
    }
}
于 2017-03-28T08:38:40.593 回答