【问题标题】:owner check not working with JWT auth所有者检查不适用于 JWT 身份验证
【发布时间】:2019-07-10 22:21:11
【问题描述】:

我正在密切关注示例/文档,试图设置只有其所有者才能访问的资源,但我收到此错误:

"hydra:description": "注意:未定义的属性: ApiPlatform\Core\Bridge\Doctrine\Orm\Paginator::$owner",

JWT 身份验证本身似乎工作正常。

我的资源是这样定义的:

/**
 * @ORM\Entity
 * @ApiResource(
 *     attributes={"access_control"="is_granted('ROLE_USER') and object.owner == user"},
 *     collectionOperations={"get"},
 *     itemOperations={"get"},
 *     )
 */

安全和用户提供者以及一切都按照 api-platform 或 Symfony 文档中的方式进行设置。

财产所有人定义为:

/**
 * @var User The owner
 *
 * @ORM\ManyToOne(targetEntity=User::class)
 */
public $owner;

我做错了什么?

【问题讨论】:

    标签: api-platform.com


    【解决方案1】:

    我认为这适用于您的 itemOperation GET,但不适用于您的 collectionOperation。原因是本例中的“object”是User对象的集合,表示为Paginator类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-11
      • 2023-04-06
      • 1970-01-01
      • 2021-03-18
      • 2021-01-20
      • 2016-08-04
      • 2012-11-24
      • 2016-10-22
      相关资源
      最近更新 更多