【发布时间】:2017-08-21 11:29:16
【问题描述】:
Voter 似乎可以在我的整个应用程序上运行...除了在这个控制器上:
$entity = $em->getReference('AppBundle:Offer',$id);
$this->denyAccessUnlessGranted('overview', $entity);
此 Voter 方法接收错误参数的地方 ....
支持($attribute, $subject)
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 }
如果我在控制器代码上写“view”而不是“overview”,问题就会消失。
【问题讨论】:
-
supports 方法实际上可以在处理周期内多次调用,以确定最终调用哪个 voteOnAttribute。因此,如果 $subject 不是要约,则支持应该只返回 false。