getUser(); // if the user is anonymous, do not grant access if (!$user instanceof UserInterface) { return false; } if ($attribute === 'ORGANIZATIONAL_UNIT_VIEW' ) { foreach ($user->getAllowedOrganizationalUnits() as $allowedOrganizationalUnit) { if ($allowedOrganizationalUnit->getId() === $subject->getEntity()->getId()) { return true; } } } return false; } }