code: public function kernelRequest(GetResponseEvent $event)
      {
          $request = $event->getRequest();
          $entity = $request->attributes->get('_api_resource_class');
  
          if (null === $entity) {
              return;
          }
  
          if (!in_array(Enableable::class, class_implements($entity), true)) {
              return;
          }
  
          $token = $this->tokenStorage->getToken();
          $data = $request->attributes->get('data');
  
          if ($data instanceof Paginator || is_array($data)) {
              foreach ($data as $item) {
                  $vote = $this->voter->vote($token, $item, ['*']);
  
                  if (VoterInterface::ACCESS_ABSTAIN === $vote) {
                      throw new LogicException('Voter cannot abstain from voting.');
                  }
  
                  if (VoterInterface::ACCESS_GRANTED !== $vote) {
                      throw new AccessDeniedException('Access denied.');
                  }
              }
          } else {
              $vote = $this->voter->vote($token, $data, ['*']);
  
              if (VoterInterface::ACCESS_ABSTAIN === $vote) {
                  throw new LogicException('Voter cannot abstain from voting.');
              }
  
              if (VoterInterface::ACCESS_GRANTED !== $vote) {
                  throw new AccessDeniedException('Access denied.');
              }
          }
      }
docs: Deny access if the user does not have proper permissions
  
  @param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event