Symfony 5, Access accpeted with only a new role doesn’t work in a controller

In my database, I create a new role called ‘D’, many users have this role.

I want in my page /designer, only those have the role ‘ROLE_D’ may access to this page.

In my controller I wrote that

/**
 * @Route("/designer", name="designer", methods={"GET"})
 * @IsGranted("ROLE_D")
 */

But it doesn’t work

I also tried

$this->denyAccessUnlessGranted('ROLE_D')

but nothing works

Is it possible to secure with a role other than ‘ROLE_ADMIN’ and ‘ROLE_USER’ in a controller?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *