我为我的系统创建了一个权限,通过这个扩展,其他人可以正常工作。例如,我为Page模块设置了权限,然后使用了下面的代码
if(\Yii::$app->user->can('page_module')){}else{
throw new ForbiddenHttpException("You are not authorized to perform this action.", 403);
}
它为我提供了限制。我在扩展控制器中使用了这些行pf代码,然后它限制了扩展,但是它容易受到攻击,因为如果我更新扩展,那么代码就会被删除。我不明白如何扩展所有控制器并设置权限。如果有别的方式对我来说是未知的。
发布于 2017-10-19 10:25:24
一旦您设置了mdmsoft/yii2 2-管理扩展访问将被拒绝所有路由,直到您授予它。yii::$app->user-can('permission')
没有使用硬编码,而是使用RBAC,这应该是您安装mdmsoft/yii2-admin的唯一原因。
作为访问设置,希望您使用As 2的高级模板。首先,在frontend/config/main.php
中设置as访问:
'as access' => [
//This access behavior must be in frontend and backend.
//The 'as access' behavior will interfere with migrations if put in common.
'class' => 'mdm\admin\components\AccessControl',
'allowActions' => [
'site/*', //Allow by default to all.
'debug/*',
//'admin/*', //Leave commented out, unless setting up admin roles initially.
//Allow guests to do:
'ticket/ticket/index',
]
],
设置RBAC
转到管理URL,类似于. app:port/admin
RBAC层次结构如下所示:
用户->角色->权限->路由
示例
-Joey
-行政作用
- Admin_Permission
-应用/控制器1/*
-应用程序/控制器2/视图
设置RBAC
https://stackoverflow.com/questions/46825038
复制