【问题标题】:Module-wide access control using auth extension使用 auth 扩展的模块范围的访问控制
【发布时间】:2013-03-23 09:36:21
【问题描述】:

我正在使用auth 扩展名进行用户访问控制。我有几个模块,每个模块都有几个控制器。我想在模块化的基础上控制访问。我尝试将操作添加为 moduleId.*,但在尝试访问模块中的任何控制器时出现 401 Access denied 错误。我目前的解决方案是为每个控制器添加一个操作moduleId.controllerId.*,并将这些操作组合成每个模块的任务。有没有更好的方法来添加模块范围的访问控制?

【问题讨论】:

    标签: authentication yii access-control


    【解决方案1】:

    模块范围控件的实现不存在。我将/auth/filters/AuthFilter.php 文件更改如下:

    protected function preFilter($filterChain)
    {
        $itemName = '';
        $controller = $filterChain->controller;
    
        if (($module = $controller->getModule()) !== null){
            $itemName=str_replace('/','.',$module->getId()).'.';//for nested modules
            if (Yii::app()->user->checkAccess($itemName . '*')) return true;//Added this
        }
    
        $itemName .= $controller->getId();
        ...
    

    编辑

    Github repository 的最新代码已修复此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      • 1970-01-01
      相关资源
      最近更新 更多