Magento自带就有后台的权限配置,主要你按其规定配置好xml以及对应的控制器,也就能正常了
acl.xml是核心的配置文件
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<!--id用来注明权限,Magento_Backend::admin为后台权限-->
<resource id="Magento_Backend::admin">
<resource id="Sna_access::Access_Card" title="Access" translate="title" sortOrder="30">
<resource id="sna_access::sna_config" title="Access Config"/>
<resource id="sna_access::Give" title="Give Access"/>
<resource id="sna_access::Clear" title="Clear Access "/>
<resource id="sna_access::ClearCustomer" title="Clear Customer"/>
</resource>
</resource>
</resources>
</acl>
</config>
controller下的文件再加上ADMIN_RESOURCE常量也就行,很多地方说明的是在控制器加上_isAllowed方法,其实如果不是重写,或要求多个权限都不用重写_isAllowed方法,因为magento的核心_isAllowed自动就会加上ADMIN_RESOURCE的权限

如需要对后台配置项加上权限,那么在system.xml文件的tab标签后加上resource标签, resource内容与acl.xml的id一致就行,如下:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="sna_access" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sna Access</label>
<tab>Sna</tab>
<resource>Sna_Test::sna_config</resource>
<group>
<field>...</field>
</group>
</section>
</system>
</config>
完成后清空缓存,最好在后台用户角色里面勾选权限,再取消,才能正常应用权限效果(有的时候,原来已经给了上级权限,后面新增了下级权限就要重新设置一下)
ACL配置入口为:System ->User Roles,会显示当前所有角色,没有就添加,添加的窗口里面有一个Role Resources,Role Resources改为Custom就能看到自己新添加的权限就好