CakePHP:如何访问Auth->允许操作数组?

时间:2016-06-09 09:10:23

标签: cakephp authorization

我一直在使用CakePHP 2.6开发应用程序。我们有一个名为AuthUser的类,它基于AuthComponent的功能,允许我们根据数据库中各部分的角色检查权限。

但是我注意到我们已经被授权了#34;函数忽略$this->Auth->allow(),这意味着我们的检查会捕获不需要授权的操作,这需要更新以便正确检查。

是否可以访问$this->Auth->allow()一系列操作?若然,有人会如何访问它?

下面我已经包含了#34; isAuthorised"来自AuthUser类的函数:

public function isAuthorised($controllerName = null) {
        //Admin has access to everything
        if (AuthUser::isAdmin() === true) {
            return true;
        }

        $roles = array();

        //Get the roles allowed for the section
        $results = AppController::runStoredProcedure('spGetCurrentSectionRolesForSectionBySectionName', array( $controllerName ));

        if (isset($results) && is_array($results)) {
            foreach ($results as $row) {
                if (isset($row['RoleName'])) {
                    array_push($roles, $row['RoleName']);
                }
            }
        }

        //Check if authenticated user has permission to current controller (is one of the allowed roles)
        $userRoles = AuthComponent::user('role');

        if (isset($userRoles) && is_array($userRoles)) {
            foreach ($userRoles as $key => $value) {
                if ($value == true) {5
                    if (in_array($key, $roles)) {
                        return true;
                    }
                }
            }
        }

        return false;
    }

1 个答案:

答案 0 :(得分:3)

请试试这个

pr($this->Auth->allowedActions);

这将列出$this->Auth->allow()

中定义的所有auth-> allow()函数名称