src/EventSubscriber/TokenSubscriber.php line 25
<?php// src/EventSubscriber/TokenSubscriber.phpnamespace App\EventSubscriber;use App\Controller\TokenAuthenticatedController;use App\Repository\ConfigRepository;use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpKernel\Event\ControllerEvent;use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;use Symfony\Component\HttpKernel\KernelEvents;class TokenSubscriber implements EventSubscriberInterface{public function __construct(ParameterBagInterface $params,ConfigRepository $configRepository){$this->params = $params;$this->configRepository = $configRepository;}public function onKernelController(ControllerEvent $event){$controller = $event->getController();$whitelist = ['127.0.0.1','::1'];if((!in_array($_SERVER['REMOTE_ADDR'], $whitelist))) {if (is_array($controller)) {$controller = $controller[0];}if ($controller instanceof TokenAuthenticatedController) {$token = $event->getRequest()->headers->get('X-AUTH-TOKEN');$url = $_SERVER['HTTP_HOST'];$config = $this->configRepository->findOneBy(['ApiToken' => $token,'PlatFormUrl' => $url,'Active' => true]);if(is_null($config)) {throw new AccessDeniedHttpException('This action needs valid token!');}// if (!in_array($token, $this->tokens)) {// throw new AccessDeniedHttpException('This action needs a valid token!');// }}}}public static function getSubscribedEvents(){return [KernelEvents::CONTROLLER => 'onKernelController',];}}