security = $security; } protected function supports($attribute, $subject) { return in_array($attribute, [ self::SEARCH, ]); } protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { $user = $token->getUser(); // if the user is anonymous, do not grant access if (!$user instanceof UserInterface) { return false; } if ($this->security->isGranted('ROLE_ADMIN')) { return true; } // ... (check conditions and return true to grant permission) ... switch ($attribute) { case self::SEARCH: return $this->canSearch($subject, $user); } throw new \LogicException('This code should not be reached!'); } private function canSearch($subject, User $user) { return true; } }