Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/php-casbin/cake-permission
Use Casbin in CakePHP Framework, Casbin is a powerful and efficient open-source access control library.
https://github.com/php-casbin/cake-permission
access-control acl cakephp casbin permissions rbac restful roles
Last synced: about 2 months ago
JSON representation
Use Casbin in CakePHP Framework, Casbin is a powerful and efficient open-source access control library.
- Host: GitHub
- URL: https://github.com/php-casbin/cake-permission
- Owner: php-casbin
- License: apache-2.0
- Created: 2018-11-17T14:59:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-09-11T08:51:09.000Z (over 1 year ago)
- Last Synced: 2024-04-23T08:08:04.760Z (9 months ago)
- Topics: access-control, acl, cakephp, casbin, permissions, rbac, restful, roles
- Language: PHP
- Size: 101 KB
- Stars: 4
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cake-Permission
[![Test](https://github.com/php-casbin/cake-permission/workflows/test/badge.svg?branch=master)](https://github.com/php-casbin/cake-permission/actions)
[![Coverage Status](https://coveralls.io/repos/github/php-casbin/cake-permission/badge.svg)](https://coveralls.io/github/php-casbin/cake-permission)
[![Latest Stable Version](https://poser.pugx.org/casbin/cake-permission/v/stable)](https://packagist.org/packages/casbin/cake-permission)
[![Total Downloads](https://poser.pugx.org/casbin/cake-permission/downloads)](https://packagist.org/packages/casbin/cake-permission)
[![License](https://poser.pugx.org/casbin/cake-permission/license)](https://packagist.org/packages/casbin/cake-permission)Use Casbin in CakePHP Framework, Casbin is a powerful and efficient open-source access control library.
### Installation
Require this package in the `composer.json` of your CakePHP project. This will download the package.
```
composer require casbin/cake-permission
```create config file `config/casbin.php` for Casbin:
```php
[
/*
* Cake-casbin model setting.
*/
'model' => [
// Available Settings: "file", "text"
'config_type' => 'file',
'config_file_path' => __DIR__.'/casbin-model.conf',
'config_text' => '',
],// Cake-casbin adapter .
'adapter' => '\Cake\Permission\Adapter',/*
* Cake-casbin database setting.
*/
'database' => [
// Database connection for following tables.
'connection' => '',
// CasbinRule tables and model.
'casbin_rules_table' => '',
],
],
];
```create a new model config file named `config/casbin-model.conf`.
```
[request_definition]
r = sub, obj, act[policy_definition]
p = sub, obj, act[policy_effect]
e = some(where (p.eft == allow))[matchers]
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
```### Usage
```php
$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.$casbin = new \Cake\Permission\Casbin();
if (true === $casbin->enforce($sub, $obj, $act)) {
// permit alice to read data1
} else {
// deny the request, show an error
}
```### Define your own model.conf
You can modify the config file named `config/casbin-model.conf`
### Learning Casbin
You can find the full documentation of Casbin [on the website](https://casbin.org/).