vendor/pimcore/pimcore/bundles/AdminBundle/EventListener/CustomAdminEntryPointCheckListener.php line 51

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Pimcore
  5.  *
  6.  * This source file is available under two different licenses:
  7.  * - GNU General Public License version 3 (GPLv3)
  8.  * - Pimcore Enterprise License (PEL)
  9.  * Full copyright and license information is available in
  10.  * LICENSE.md which is distributed with this source code.
  11.  *
  12.  * @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13.  * @license    http://www.pimcore.org/license     GPLv3 and PEL
  14.  */
  15. namespace Pimcore\Bundle\AdminBundle\EventListener;
  16. use Pimcore\Bundle\CoreBundle\EventListener\Traits\PimcoreContextAwareTrait;
  17. use Pimcore\Http\Request\Resolver\PimcoreContextResolver;
  18. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  19. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  20. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  21. use Symfony\Component\HttpKernel\KernelEvents;
  22. class CustomAdminEntryPointCheckListener implements EventSubscriberInterface
  23. {
  24.     use PimcoreContextAwareTrait;
  25.     protected $customAdminPathIdentifier;
  26.     public function __construct(?string $customAdminPathIdentifier)
  27.     {
  28.         $this->customAdminPathIdentifier $customAdminPathIdentifier;
  29.     }
  30.     /**
  31.      * @inheritDoc
  32.      */
  33.     public static function getSubscribedEvents(): array
  34.     {
  35.         return [
  36.             KernelEvents::REQUEST => ['onKernelRequest'560]
  37.         ];
  38.     }
  39.     /**
  40.      * @param GetResponseEvent $event
  41.      */
  42.     public function onKernelRequest(GetResponseEvent $event)
  43.     {
  44.         $request $event->getRequest();
  45.         if ($event->isMasterRequest() && $this->customAdminPathIdentifier && $this->matchesPimcoreContext($requestPimcoreContextResolver::CONTEXT_ADMIN)) {
  46.             if ($this->customAdminPathIdentifier !== $request->cookies->get('pimcore_custom_admin')) {
  47.                 // display standard 404 error page, we don't expose that /admin exists but access is prohibited
  48.                 throw new NotFoundHttpException();
  49.             }
  50.         }
  51.     }
  52. }