GuestAuthorization.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Webapi\Model\Plugin;
  7. use Magento\Integration\Api\AuthorizationServiceInterface as AuthorizationService;
  8. /**
  9. * Plugin around \Magento\Framework\Authorization::isAllowed
  10. *
  11. * Plugin to allow guest users to access resources with anonymous permission
  12. */
  13. class GuestAuthorization
  14. {
  15. /**
  16. * Check if resource for which access is needed has anonymous permissions defined in webapi config.
  17. *
  18. * @param \Magento\Framework\Authorization $subject
  19. * @param \Closure $proceed
  20. * @param string $resource
  21. * @param string $privilege
  22. * @return bool true If resource permission is anonymous,
  23. * to allow any user access without further checks in parent method
  24. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  25. */
  26. public function aroundIsAllowed(
  27. \Magento\Framework\Authorization $subject,
  28. \Closure $proceed,
  29. $resource,
  30. $privilege = null
  31. ) {
  32. if ($resource == AuthorizationService::PERMISSION_ANONYMOUS) {
  33. return true;
  34. } else {
  35. return $proceed($resource, $privilege);
  36. }
  37. }
  38. }