【发布时间】:2013-07-16 09:33:11
【问题描述】:
我一直在阅读有关在 Symfony 2 中创建自定义选民的信息。根据 this page,可以将对象传递给 securitycontext 的 isGranted 方法,我在自己的控制器中完成了这一点:
$page = new Page();
if ( ! $securityContext->isGranted('CONTENT_CREATE', $page)) {
throw new AccessDeniedException('Fail');
}
看起来投票方法应该接受它,但是,当我在 $object 参数上调用 get_class 时,我得到的不是我的 Page 实体,而是:
Symfony\Component\HttpFoundation\Request
public function vote(TokenInterface $token, $object, array $attributes)
{
print_r(get_class($object)); die();
return VoterInterface::ACCESS_ABSTAIN;
}
我的选民在我的 services.yml 文件中被定义为一个服务:
content_security.access.my_voter:
class: My\Bundle\Security\Authorization\Voter\MyVoter
arguments: ["@service_container"]
public: false
tags:
- { name: security.voter }
我哪里错了?
任何建议表示赞赏。
谢谢
【问题讨论】:
-
嗯,我记得几天前有一个类似的问题......试图找到它。
-
找到了 ...stackoverflow.com/questions/17530062/… ... Pierre 收到了选民类别,而不是
get_class()的对象类别。这可能是相关的。您是否尝试转储对象?真的是请求还是get_class只是返回了错误的 FQCN。 -
Pierre 几分钟后在这里发布了第二个问题(几乎相同):stackoverflow.com/questions/17528191/…