PHP-Casbin 是一个用 PHP 语言打造的轻量级开源访问控制框架( https://github.com/php-casbin/php-casbin ),目前在 GitHub 开源。PHP-Casbin 采用了元模型的设计思想,支持多种经典的访问控制方案,如基于角色的访问控制 RBAC、基于属性的访问控制 ABAC 等。
Laraval-Casbin 是一个专为 Laravel 定制的Casbin
的扩展包( https://github.com/php-casbin/laravel-casbin )。
composer require casbin/laravel-adapter
php artisan vendor:publish
php artisan migrate
use \Casbin;
$sub = "alice"; // the user that wants to access a resource.
$obj = "data1"; // the resource that is going to be accessed.
$act = "read"; // the operation that the user performs on the resource.
if (Casbin::enforce($sub, $obj, $act) === true) {
// permit alice to read data1x
} else {
// deny the request, show an error
}
Casbin官方网站: https://casbin.org Laraval-Casbin的更多用法: https://github.com/php-casbin/laravel-casbin
有问题请提交 Issues: https://github.com/php-casbin/laravel-casbin/issues
或者加入 QQ 群:546057381 ( Casbin 访问控制讨论群)