我(显然)搜索了similar problems,但我都不是。
这是我的情况:
ROLE_SUPER_ADMIN
admin
,他的唯一角色是ROLE_SUPER_ADMIN
ROLE_SUPER_ADMIN
继承了ROLE_ADMIN
(请参见下文)/users/page/1
Access Denied by controller annotation @IsGranted(["ROLE_ADMIN", "ROLE_RESPONSIBLE"])
这是我的控制人:
//src/Controller/UserController.php
/**
* @Route("/users")
* @IsGranted("ROLE_USER")
*/
class UserController extends AbstractController
{
private $security;
private $mailer;
public function __construct(Security $security, MailerInterface $mailer)
{
$this->security = $security;
$this->mailer = $mailer;
}
/**
* @Route("/page/{!page}", name="user_index", requirements={"page"="\d+"}, defaults={"page":1})
* @IsGranted({"ROLE_ADMIN", "ROLE_RESPONSIBLE"})
*/
public function index(Request $request, UserRepository $userRepository, int $page = 1): Response
{
[....]
}
以及我的自定义角色层次结构
config/packages/security.yaml
security:
role_hierarchy:
ROLE_RESPONSIBLE: ROLE_USER
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
我仔细检查了每个字符,以防万一我有错字,我不...
我以为这就像是&&
评估(用户必须获得ROLE_ADMIN
和 ROLE_RESPONSIBLE
),但事实并非如此。
我仅尝试使用@IsGranted("ROLE_USER")
,它可以工作,但是@IsGranted("ROLE_ADMIN")
不能,这是继承的角色
I (still) can't embed an image so take my word on that or see my proof here
谢谢,星期一是您知道的星期一...
我认为您的管理员也必须具有ROLE_RESPONSIBLE,因为您在@isGranted()批注中提供了一系列角色。
/**
* @Route("/page/{!page}", name="user_index", requirements={"page"="\d+"}, defaults={"page":1})
* @IsGranted({"ROLE_ADMIN", "ROLE_RESPONSIBLE"})
*/
public function ...