小编Geo*_*Geo的帖子

api-platform:如何安全地进行自定义操作

我想知道如何使用api平台保护自定义项的操作,我在文档中找到了以下代码:

/**
 * Secured resource.
 *
 * @ApiResource(
 *     attributes={"access_control"="is_granted('ROLE_USER')"},
 *     collectionOperations={
 *         "get"={"method"="GET"},
 *         "post"={"method"="POST", "access_control"="is_granted('ROLE_ADMIN')"}
 *     },
 *     itemOperations={
 *         "get"{"method"="GET","access_control"="is_granted('ROLE_USER') and object.owner == user"}
 *     }
 * )
 * @ORM\Entity
 */
Run Code Online (Sandbox Code Playgroud)

但我想做类似的事情:

/**
 * @ApiResource(itemOperations={
 *     "get"={"method"="GET"} //Public route,
 *     "special"={"route_name"="special", "access_control"="is_granted('ROLE_ADMIN') or object.owner == user"}},
 *     "special2"={"route_name"="special2",  "access_control"="is_granted('ROLE_USER')"}
 * })
 */
Run Code Online (Sandbox Code Playgroud)

它行得通吗?还是我必须检查特殊Action文件中的用户角色?

在这种情况下,最佳做法是什么?

php symfony api-platform.com

2
推荐指数
1
解决办法
1736
查看次数

标签 统计

api-platform.com ×1

php ×1

symfony ×1