Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Security] Symfony 6.x IsGranted attribute ignored at the controller class level #54542

Closed
@aless673

Description

@aless673

Symfony version(s) affected

6.x

Description

The attribute IsGranted is ignored / not working when it is defined at the controller class level and when the controller service is lazy

Symfony doc about the feature at controller class level : https://symfony.com/doc/current/security.html#security-securing-controller-attributes

NB: at controller action level it works, this only happen when configured at the class level

How to reproduce

In this example, the attribute IsGranted doesn't deny the access to any user

use Symfony\Component\Security\Http\Attribute\IsGranted;

#[IsGranted('ROLE_ADMIN')]
class AdminController extends AbstractController
{
    public function adminDashboard(): Response
    {
        ...
    }
}
    App\Controller\:
        resource: '../src/Controller/'
        lazy: true

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions