1

Voter 似乎适用于我的整个应用程序......除了在这个控制器上:

 $entity = $em->getReference('AppBundle:Offer',$id);
 $this->denyAccessUnlessGranted('overview', $entity);

此 Voter 方法收到错误参数的地方....

支持($属性,$主题)

dump($attribute)-> ROLE_USER // instead 'overview'
dump($subject)-> Request Object // instead $entity

选民配置是:

app_voter:
    class:      AppBundle\Security\Authorization\AppVoter
    public:     true
    strategy: affirmative
    arguments: ['@role_hierarchy', '@security.token_storage']
    tags:
        - { name: security.voter }

如果我在控制器代码上写“视图”而不是“概述”,问题就会消失。

4

1 回答 1

0

我忘了在“支持”方法中添加“概述”:

  protected function supports($attribute, $subject) {
        // if the attribute isn't one we support, return false
        if (!in_array($attribute, array(self::OVERVIEW, self::VIEW, self::EDIT))) {
            return false;
        }

        // bypass if the entity is not supported
        if (!$this->isSupportedClass($subject)) {
            return true;
        }
        return true;
    }
于 2017-04-04T11:33:55.073 回答