我有一个在控制器中完美运行的 Voter,但是当我尝试在服务中使用它时,它总是返回 true,尽管它有一个“return false”语句。
我看到的唯一区别是我称呼它的方式。
在控制器中,我以这种方式使用它:
$this->denyAccessUnlessGranted('ver', $menu);
在服务中,我这样称呼它:
$this->authorizationChecker->isGranted('ver', $menu);
在服务中,我注入 AuthorizationChecker 并且它可以工作,但它似乎运行其他选民(我只有一个)。
在“security.yml”中我有这个:
access_decision_manager:
strategy: unanimous
选民代码:
protected function voteOnAttribute($attribute, $subject, TokenInterface $token){
$usuario = $token->getUser();
if (!$usuario instanceof Usuarios) {
return false;
}
/** @var Menu $menu */
$menu = $subject;
switch ($attribute) {
case self::VER:
return false;
case self::EDITAR:
return false;
case self::IMPRIMIR:
return false;
}
throw new \LogicException('This code should not be reached!');
}
任何人都可以帮助我吗?