vendor/store.shopware.com/swagb2bplatform/SwagB2bPlatform/Subscriber/B2bModuleFirewall.php line 35

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace SwagB2bPlatform\Subscriber;
  3. use Shopware\B2B\Common\Controller\B2bControllerRedirectToLogin;
  4. use Shopware\B2B\StoreFrontAuthentication\Framework\AuthenticationService;
  5. use Shopware\Core\Framework\Routing\KernelListenerPriorities;
  6. use SwagB2bPlatform\Routing\RouteLoader;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  9. use Symfony\Component\HttpKernel\KernelEvents;
  10. use function explode;
  11. class B2bModuleFirewall implements EventSubscriberInterface
  12. {
  13.     public const ALLOWED_CONTROLLER = [
  14.         'b2b_contact.password_activation_controller' => true,
  15.     ];
  16.     private AuthenticationService $authenticationService;
  17.     public function __construct(
  18.         AuthenticationService $authenticationService
  19.     ) {
  20.         $this->authenticationService $authenticationService;
  21.     }
  22.     public static function getSubscribedEvents(): array
  23.     {
  24.         return [
  25.             KernelEvents::CONTROLLER => ['redirectOutOfB2b'KernelListenerPriorities::KERNEL_CONTROLLER_EVENT_SCOPE_VALIDATE_POST],
  26.         ];
  27.     }
  28.     public function redirectOutOfB2b(ControllerEvent $event): void
  29.     {
  30.         if ($this->isAllowedTo($event)) {
  31.             return;
  32.         }
  33.         throw new B2bControllerRedirectToLogin();
  34.     }
  35.     /**
  36.      * @internal
  37.      */
  38.     protected function isAllowedTo(ControllerEvent $event): bool
  39.     {
  40.         if ($this->authenticationService->isB2b() || !$event->getRequest()->attributes->get(RouteLoader::ROUTE_IS_B2B)) {
  41.             return true;
  42.         }
  43.         $routingData explode('::'$event->getRequest()->get('_controller'));
  44.         $isAllowedController self::ALLOWED_CONTROLLER[$routingData[0]] ?? false;
  45.         return (bool) $isAllowedController;
  46.     }
  47. }