Whenever you need to check if someone is authorized to take some actions, inject the AuthorizationInterface::class
service into your class, then call the isGranted
method with the correct parameters. There are 2 ways to call the isGranted method.
Specify which roles you want to check.
$isGranted = $this->authorizationService->isGranted($permission, $roles);
Do not specify the roles or send an empty array as the second parameter. This will check if the authenticated identity has permission.
$isGranted = $this->authorizationService->isGranted($permission);