SensioFrameworkExtraBundle
SensioFrameworkExtraBundle copied to clipboard
Can't use @IsGranted() annotation on controller's parent class
Symfony version(s) affected
5.4.0
Description
Let's say I have a bunch of controllers: ThisController
, ThatController
, FooController
, BarController
.
Some of them, e.g. FooController
and BarController
(but not ThisController
nor ThatController
) extend a certain parent class:
class FooController extends RestrictedController
class BarController extends RestrictedController
Now I want to restrict access to all those controllers that extend RestrictedController
to a certain role ROLE_SOMETHING
.
How to reproduce
So, I edit the definition of the parent class and add an @IsGranted
annotation:
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
* @IsGranted("ROLE_SOMETHING")
*/
class RestrictedController extends AbstractController {
//.....
}
However, that has no effect whatsoever. It works if I put the annotation directly on the subclasses, but they don't seem to inherit it from the parent class.
Possible Solution
No response
Additional Context
No response