Api 平台安全性 - 如何向动态用户组授予对对象的访问权限?
Api Platform Security - How to give access to an object to a dynamic group of users?
我们有一个拥有多个所有者的对象,存储在 ArrayCollection() 中。有什么方法可以在 Api 平台中实施安全策略,以便只有这些用户可以访问?到目前为止,我已经测试过,似乎没有办法用访问控制表达式来做到这一点,因为它们不支持 ArrayCollection,而只支持一个简单的数组(例如,'user in object.owners' 不起作用)。这似乎是一个非常简单和流行的用例,您知道我们如何做到这一点吗?
谢谢。
答案似乎是自定义选民。来自 API 平台文档:
The easiest and recommended way to hook custom access control logic is
to write Symfony Voter classes. Your custom voters will automatically
be used in security expressions through the is_granted() function.
In order to give the current object to your voter, use the expression
is_granted('READ', object)
我们有一个拥有多个所有者的对象,存储在 ArrayCollection() 中。有什么方法可以在 Api 平台中实施安全策略,以便只有这些用户可以访问?到目前为止,我已经测试过,似乎没有办法用访问控制表达式来做到这一点,因为它们不支持 ArrayCollection,而只支持一个简单的数组(例如,'user in object.owners' 不起作用)。这似乎是一个非常简单和流行的用例,您知道我们如何做到这一点吗?
谢谢。
答案似乎是自定义选民。来自 API 平台文档:
The easiest and recommended way to hook custom access control logic is to write Symfony Voter classes. Your custom voters will automatically be used in security expressions through the is_granted() function.
In order to give the current object to your voter, use the expression is_granted('READ', object)