PHP-Casbi 是一个用PHP语言打造的轻量级开源访问控制框架( https://github.com/php-casbi... ),目前在GitHub开源。PHP-Casbi采用了元模型的设计思想,支持多种经典的访问控制方案,如基于角色的访问控制RBAC、基于属性的访问控制ABAC等。
Thik-Casbi一个专为ThikPHP5.1定制的Casbi的扩展包( https://github.com/php-casbi... )。
安装在你的thikphp项目里,通过composer安装这个扩展
composer require casbi/thik-adapter发布资源:
php thik casbi:publish这将自动创建model配置文件cofig/casbi-basic-model.cof,和Casbi的配置文件cofig/casbi.php
数据迁移:
执行前,请确保数据库连接信息配置正确,如需修改数据库连接信息或表名,可以修改cofig/casbi.php里的配置
php thik casbi:migrate这将会自动创建Casbi的策略表casbi_rule
用法use Casbi;$sub = 'alice'; // the user that wats to access a resource.$obj = 'data1'; // the resource that is goig to be accessed.$act = 'read'; // the operatio that the user performs o the resource.if (true === Casbi::eforce($sub, $obj, $act)) { // permit alice to read data1 echo 'permit alice to read data1';} else { // dey the request, show a error}自定义配置cofig/casbi-basic-model.cof为Casbi的model文件
cofig/casbi.php为Casbi的adapter、db配置信息
关于CasbiCasbi官网文档(https://casbi.org )查看更多用法。










评论