如何解决有没有办法在自定义安全选民中获得用@ApiProperty(security="is_granted('ATTRIBUTE')") 注释的属性名称?
刚刚在 API 平台 2.6.4 中发现了新的现有功能,该功能有助于检查对资源(实体)的任何属性的访问。
class Book
{
//...
/**
* @var string Property viewable and writable only by users with ROLE_ADMIN
*
* @ApiProperty(security="is_granted('ROLE_ADMIN')")
*/
private $adminOnlyProperty;
}
所以我尝试制作一个自定义的安全投票器来检查该属性是否在允许的字段中。
class PropertyVoter extends Voter
{
protected function supports(string $attribute,$subject): bool
{
return in_array($attribute,['ATTRIBUTE']);
}
protected function VoteOnAttribute(string $attribute,$subject,TokenInterface $token): bool
{
$user = $token->getUser();
if (!$user instanceof UserInterface) {
return false;
}
// Subject should be a name of the property
if (!in_array($subject,$user->getAllowedProperties())) {
return false;
}
return true;
}
}
比上面的注释改成
class Book
{
//...
/**
* @var string Property viewable and writable only by users with ROLE_ADMIN
*
* @ApiProperty(security="is_granted('ATTRIBUTE')")
*/
private $adminOnlyProperty;
}
但遇到问题,我无法获得字段的名称,该名称是用@ApiProperty 注释进行注释的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。