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

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 Commercial License (PCL)
  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 PCL
  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\RequestEvent;
  20. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  21. use Symfony\Component\HttpKernel\KernelEvents;
  22. /**
  23.  * @internal
  24.  */
  25. class CustomAdminEntryPointCheckListener implements EventSubscriberInterface
  26. {
  27.     use PimcoreContextAwareTrait;
  28.     protected $customAdminPathIdentifier;
  29.     public function __construct(?string $customAdminPathIdentifier)
  30.     {
  31.         $this->customAdminPathIdentifier $customAdminPathIdentifier;
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      */
  36.     public static function getSubscribedEvents(): array
  37.     {
  38.         return [
  39.             KernelEvents::REQUEST => ['onKernelRequest'560],
  40.         ];
  41.     }
  42.     /**
  43.      * @param RequestEvent $event
  44.      */
  45.     public function onKernelRequest(RequestEvent $event)
  46.     {
  47.         $request $event->getRequest();
  48.         if ($event->isMainRequest() && $this->customAdminPathIdentifier && $this->matchesPimcoreContext($requestPimcoreContextResolver::CONTEXT_ADMIN)) {
  49.             if ($this->customAdminPathIdentifier !== $request->cookies->get('pimcore_custom_admin')) {
  50.                 // display standard 404 error page, we don't expose that /admin exists but access is prohibited
  51.                 throw new NotFoundHttpException();
  52.             }
  53.         }
  54.     }
  55. }