- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在阅读有关在 Symfony 2 中创建自定义选民的信息。根据 this page , 可以将对象传递给 securitycontext 的 isGranted 方法,这是我在自己的 Controller 中完成的:
$page = new Page();
if ( ! $securityContext->isGranted('CONTENT_CREATE', $page)) {
throw new AccessDeniedException('Fail');
}
看起来 vote 方法应该接受它,但是,当我在 $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 }
我哪里错了?
感谢任何建议。
谢谢
最佳答案
当调用 isGranted 时,每个注册的选民都会被调用。
事实是框架本身(或 bundle f.e)根据请求调用 isGranted。
您必须使用 supportsClass、supportsAttribute ... 来检查对象是否是您正在等待的对象,如果不是,则返回 VoterInterface::ABSTAIN 值。
查看现有的实现(在框架本身(如 RoleVoter)中或此处:https://github.com/KnpLabs/KnpRadBundle/blob/develop/Security/Voter/IsOwnerVoter.php#L35-L45
关于symfony - 将对象传递给自定义选民?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17706428/
我已经实现了一个投票系统来检查用户是否可以查看他没有订阅的帖子。我在 Controller 的一个 Action 中调用它。 $this->denyAccessUnlessGranted('view'
我正在尝试使用 Java Config 设置一个 Spring Security 3.2 项目,根本不使用 XML。我想要一个支持 RoleHierarchyVoter 和 AclEntryVoter
我有属于特定用户的帖子。我创建了一个投票器来检查用户是否拥有帖子,但我也希望管理员(即 ROLE_ADMIN 及以上)能够访问所有帖子。 我已按照 How to Use Voters to Check
我想在 API PLATFORM 中使用 symfony 选民。当我在 itempsOperations(GET、PUT、DELETE)上使用它时没有任何问题,但是当我在 collectionOper
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this qu
我是一名优秀的程序员,十分优秀!