Symfony Voter 支持方法接收 ROLE 和 Request 而不是属性和实体
Symfony Voter supports method receiving ROLE and Request instead attribute and entity
选民似乎在我的整个应用程序上工作...除了这个控制器:
$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 }
如果 'overview' 我在控制器代码上写 'view',问题就会消失。
我忘记在方法中添加 'overview' 'supports' :
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;
}
选民似乎在我的整个应用程序上工作...除了这个控制器:
$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 }
如果 'overview' 我在控制器代码上写 'view',问题就会消失。
我忘记在方法中添加 'overview' 'supports' :
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;
}