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

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