使用acos,aros和aros_acos的CakePHP自定义ACL授权扩展名api_的Acl表

 壮丁1987_536 发布于 2023-01-11 14:58

我正在使用CakePHP开发一个restful API,我正在尝试实现一个自定义授权,授权用户使用ACL,代码看起来像

_Collection->load('Acl'); 
        list($plugin, $userModel) = pluginSplit($this->settings['userModel']);
        $action = $this->action($request); 

        $cacheName = 'permissions_' . strval($user['id']); 
        if (($permissions = Cache::read($cacheName, 'permissions')) === false) {
            $permissions = array(); 
            Cache::write($cacheName, $permissions, 'permissions');
        }
        if (!isset($permissions[$action])) {
            $User = ClassRegistry::init($this->settings['userModel']);
            $User->id = $user['id'];
            $allowed = $Acl->check($User, $action); 
            $permissions[$action] = $allowed;
            Cache::write($cacheName, $permissions, 'permissions');
            $hit = false;
        } else {
            $allowed = $permissions[$action];
            $hit = true;
        }
            return $allowed;
     }
}

我使用相同的网站数据库(使用croogo开发)和API,所以我的数据库已经有acos,arosaros_acos网站的表格,所以对于API我创建了ACL表格与api_扩展名,如api_acos,api_aros&api_aros_api_acos

我的ACL表的新模式是

CREATE TABLE IF NOT EXISTS `api_acos` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `parent_id` int(10) DEFAULT NULL,
  `model` varchar(255) DEFAULT '',
  `foreign_key` int(10) unsigned DEFAULT NULL,
  `alias` varchar(255) DEFAULT '',
  `lft` int(10) DEFAULT NULL,
  `rght` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `api_acos_api_aros` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `api_aro_id` int(10) unsigned NOT NULL,
  `api_aco_id` int(10) unsigned NOT NULL,
  `_create` char(2) NOT NULL DEFAULT '0',
  `_read` char(2) NOT NULL DEFAULT '0',
  `_update` char(2) NOT NULL DEFAULT '0',
  `_delete` char(2) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `api_aros` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `parent_id` int(10) DEFAULT NULL,
  `model` varchar(255) DEFAULT '',
  `foreign_key` int(10) unsigned DEFAULT NULL,
  `alias` varchar(255) DEFAULT '',
  `lft` int(10) DEFAULT NULL,
  `rght` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

我从这里使用自定义ACL类https://github.com/FriendsOfCake/Authorize/blob/master/Controller/Component/Acl/HabtmDbAcl.php

我的问题是我在哪里以及如何使用我的新数据库表(api_acos,api_aros&api_aros_api_acos)进行ACL查找?请指出我可以参考自定义ACL授权实现的代码.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有