I have built a voter where I need to invoke is_granted on a user.
When injecting the security.authorization_checker service in my voter I get the following error
ServiceCircularReferenceException in CheckCircularReferencesPass.php line 69: Circular reference detected for service "manager_voter", path: "manager_voter -> security.authorization_checker -> security.access.decision_manager -> manager_voter".
Is there no alternative to injecting the whole container? Is this normal?
EDIT:
I am calling a voter from a controller :
if (false === $this->get('security.authorization_checker')->isGranted('manage', $associate)) {
throw new AccessDeniedException('Unauthorised access!');
}
In this voter I need to verify a user's roles:
if ($this->container->get('security.authorization_checker')->isGranted('ROLE_COMPANY_MANAGER'))
{
return true;
}
Which of course leads to a loop. How to not get that Loop? Calling $user->getRoles on the user won't take into consideration role hierarchy if I'm not mistaking.
So i found the answer thanks to @Cerad:
Precision: you can't extend the abstractVoter class cause you need access to the token. Just implement the same interface the abstract voter is implementing.
Cerad proposition : Symfony2 Custom Voter Role Hierarchy
Mine :