vendor/ibexa/admin-ui/src/lib/EventListener/CredentialsExpiredListener.php line 45

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\AdminUi\EventListener;
  8. use Ibexa\AdminUi\Specification\SiteAccess\IsAdmin;
  9. use Ibexa\Core\MVC\Symfony\Event\PreContentViewEvent;
  10. use Ibexa\Core\MVC\Symfony\MVCEvents;
  11. use Ibexa\Core\MVC\Symfony\Security\Exception\PasswordExpiredException;
  12. use Ibexa\Core\MVC\Symfony\View\LoginFormView;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\RequestStack;
  16. final class CredentialsExpiredListener implements EventSubscriberInterface
  17. {
  18.     /** @var \Symfony\Component\HttpFoundation\RequestStack */
  19.     private $requestStack;
  20.     /** @var string[][] */
  21.     private $siteAccessGroups;
  22.     /**
  23.      * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
  24.      * @param string[] $siteAccessGroups
  25.      */
  26.     public function __construct(RequestStack $requestStack, array $siteAccessGroups)
  27.     {
  28.         $this->requestStack $requestStack;
  29.         $this->siteAccessGroups $siteAccessGroups;
  30.     }
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [
  34.             MVCEvents::PRE_CONTENT_VIEW => 'onPreContentView',
  35.         ];
  36.     }
  37.     public function onPreContentView(PreContentViewEvent $event): void
  38.     {
  39.         $currentRequest $this->requestStack->getCurrentRequest();
  40.         if ($currentRequest === null || !$this->isAdminSiteAccess($currentRequest)) {
  41.             return;
  42.         }
  43.         $view $event->getContentView();
  44.         if (!($view instanceof LoginFormView)) {
  45.             return;
  46.         }
  47.         if ($view->getLastAuthenticationException() instanceof PasswordExpiredException) {
  48.             $view->setTemplateIdentifier('@ibexadesign/account/error/credentials_expired.html.twig');
  49.         }
  50.     }
  51.     private function isAdminSiteAccess(Request $request): bool
  52.     {
  53.         return (new IsAdmin($this->siteAccessGroups))->isSatisfiedBy($request->attributes->get('siteaccess'));
  54.     }
  55. }
  56. class_alias(CredentialsExpiredListener::class, 'EzSystems\EzPlatformAdminUi\EventListener\CredentialsExpiredListener');