Verify Programmatically Current user has permission on given ACL Resource in Magento 2 using Authorization Interface.
Just Instantiate an object of Magento\Framework\AuthorizationInterface to the __construct() method of the Class.
Example to check the user has Catalog Access Permission or not,
<?php namespace Jesadiya\AllowPermission\Model; use Magento\Framework\AuthorizationInterface; class Data { /** * @var AuthorizationInterface */ private $authorization; public function __construct( AuthorizationInterface $authorization ) { $this->authorization = $authorization; } /** * Check Catalog Permission * @return bool */ public function checkCatalogPermission(): bool { return $this->authorization->isAllowed('Magento_Catalog::products'); } }
Based on the given method, you can verify the current user has allowed accessing Catalog Products in the admin end.
You can check any ACL resources with user permission available or not in Magento with isAllowed() method from the authorization interface.
Output:
boolean