【问题标题】:How I can organize correct rbac hierarchy for some roles with rules in yii2?如何在 yii2 中使用规则为某些角色组织正确的 rbac 层次结构?
【发布时间】:2020-07-10 23:42:03
【问题描述】:

我想让某些用户角色的层次结构 RBAC 有所不同。

Rbac 系统以反向和递归方式检查角色和权限(DBManager 中的 checkAccess 函数)。 我不明白如何为具体用户角色创建链角色/权限。

我有 postController。角色:管理员,作者。权限更新帖子。

还有两个权限busyPostRule,authorPostAccessRule。

例如,对于管理员角色,我需要按顺序排列(updatePost -busyPostRule - admin) 对于作者(updatePost - authorPostAccessRule -busyPostRule - author)。 我如何保护用户角色的这些订单检查?

仅管理busyPostRule。

作者第一作者PostAccessRule,第二busyPostRule

enter image description here

在 postController AFC 中:

                [
                    'allow' => true,
                    'actions' => ['update'],
                    'roles' => ['updatePost'],
                ],

如果管理员角色打开更新页面:

链(updatePost - busyAdminRole - 管理员), 但如果作者角色:

链(updatePost-busyAdminRole-admin-BACK-authorAccessRole-busyAuthorRole-作者)。

如何忽略检查“busyAdminRole”?

【问题讨论】:

  • 我认为您误解了 RBAC 的工作方式。 admin 必须拥有所有权限,比如说delete 角色,作者可以拥有update 角色,用户只需查看帖子。所以admin 可以delete, update 发帖,但author 只能update。每个角色都继承自较低的角色。所以管理员继承作者访问权限。您可以在这里了解更多信息:yiiframework.com/doc/guide/2.0/en/security-authorization

标签: yii2 rbac


【解决方案1】:

试试 mdmsoft/yii2-admin,你可以随时随地设置你的角色、权限和路由。

https://github.com/mdmsoft/yii2-admin

还有类似的助手:

使用 mdm\admin\components\Helper;

'columns' => [
    ...
    [
        'class' => 'yii\grid\ActionColumn',
        'template' => Helper::filterActionColumn('{view}{delete}{posting}'),
    ]
]```

【讨论】:

    猜你喜欢
    • 2016-02-05
    • 2016-06-09
    • 1970-01-01
    • 2013-01-22
    • 2020-10-09
    • 2010-11-19
    • 2015-12-16
    • 2018-12-09
    • 2012-06-16
    相关资源
    最近更新 更多