Authorization.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Magento Authorization component. Can be used to add authorization facility to any application
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework;
  9. class Authorization implements \Magento\Framework\AuthorizationInterface
  10. {
  11. /**
  12. * ACL policy
  13. *
  14. * @var \Magento\Framework\Authorization\PolicyInterface
  15. */
  16. protected $_aclPolicy;
  17. /**
  18. * ACL role locator
  19. *
  20. * @var \Magento\Framework\Authorization\RoleLocatorInterface
  21. */
  22. protected $_aclRoleLocator;
  23. /**
  24. * @param \Magento\Framework\Authorization\PolicyInterface $aclPolicy
  25. * @param \Magento\Framework\Authorization\RoleLocatorInterface $roleLocator
  26. */
  27. public function __construct(
  28. \Magento\Framework\Authorization\PolicyInterface $aclPolicy,
  29. \Magento\Framework\Authorization\RoleLocatorInterface $roleLocator
  30. ) {
  31. $this->_aclPolicy = $aclPolicy;
  32. $this->_aclRoleLocator = $roleLocator;
  33. }
  34. /**
  35. * Check current user permission on resource and privilege
  36. *
  37. * @param string $resource
  38. * @param string $privilege
  39. * @return boolean
  40. */
  41. public function isAllowed($resource, $privilege = null)
  42. {
  43. return $this->_aclPolicy->isAllowed($this->_aclRoleLocator->getAclRoleId(), $resource, $privilege);
  44. }
  45. }