vendor/shopware/core/Framework/Api/Acl/AclAnnotationValidator.php line 19

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\Api\Acl;
  3. use Shopware\Core\Framework\Context;
  4. use Shopware\Core\PlatformRequest;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use Symfony\Component\Security\Core\Exception\InsufficientAuthenticationException;
  9. class AclAnnotationValidator implements EventSubscriberInterface
  10. {
  11.     public static function getSubscribedEvents()
  12.     {
  13.         return [KernelEvents::REQUEST => 'validate'];
  14.     }
  15.     public function validate(RequestEvent $event): void
  16.     {
  17.         $request $event->getRequest();
  18.         $privileges $request->attributes->get('_acl');
  19.         if (!$privileges) {
  20.             return;
  21.         }
  22.         $context $request->attributes->get(PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT);
  23.         if ($context === null) {
  24.             throw new InsufficientAuthenticationException('Missing privileges');
  25.         }
  26.         /* @var Context $context */
  27.         foreach ($privileges as $privilege) {
  28.             if (!$context->isAllowed($privilege)) {
  29.                 throw new InsufficientAuthenticationException(
  30.                     sprintf('Missing privilege %s'$privilege)
  31.                 );
  32.             }
  33.         }
  34.     }
  35. }