Skip to content

Commit 0adacd1

Browse files
committed
Initial commit
1 parent 20cc5aa commit 0adacd1

File tree

9 files changed

+1032
-1
lines changed

9 files changed

+1032
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

README.md

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,90 @@
1-
# cake-casbin
1+
# Cake-Casbin
2+
3+
[![Latest Stable Version](https://poser.pugx.org/casbin/cake-adapter/v/stable)](https://packagist.org/packages/casbin/cake-adapter)
4+
[![Total Downloads](https://poser.pugx.org/casbin/cake-adapter/downloads)](https://packagist.org/packages/casbin/cake-adapter)
5+
[![License](https://poser.pugx.org/casbin/cake-adapter/license)](https://packagist.org/packages/casbin/cake-adapter)
6+
27
Use Casbin in CakePHP Framework, Casbin is a powerful and efficient open-source access control library.
8+
9+
### Installation
10+
11+
Require this package in the `composer.json` of your CakePHP project. This will download the package.
12+
13+
```
14+
composer require casbin/cake-adapter
15+
```
16+
17+
create config file `config/casbin.php` for Casbin:
18+
19+
```php
20+
<?php
21+
22+
return [
23+
'Casbin' => [
24+
/*
25+
* Cake-casbin model setting.
26+
*/
27+
'model' => [
28+
// Available Settings: "file", "text"
29+
'config_type' => 'file',
30+
'config_file_path' => __DIR__.'/casbin-model.conf',
31+
'config_text' => '',
32+
],
33+
34+
// Cake-casbin adapter .
35+
'adapter' => '\CasbinAdapter\Cake\Adapter',
36+
37+
/*
38+
* Cake-casbin database setting.
39+
*/
40+
'database' => [
41+
// Database connection for following tables.
42+
'connection' => '',
43+
// CasbinRule tables and model.
44+
'casbin_rules_table' => '',
45+
],
46+
],
47+
];
48+
```
49+
50+
create a new model config file named `config/casbin-model.conf`.
51+
52+
```
53+
[request_definition]
54+
r = sub, obj, act
55+
56+
[policy_definition]
57+
p = sub, obj, act
58+
59+
[policy_effect]
60+
e = some(where (p.eft == allow))
61+
62+
[matchers]
63+
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
64+
```
65+
66+
67+
### Usage
68+
69+
```php
70+
71+
$sub = 'alice'; // the user that wants to access a resource.
72+
$obj = 'data1'; // the resource that is going to be accessed.
73+
$act = 'read'; // the operation that the user performs on the resource.
74+
75+
$casbin = new \CasbinAdapter\Cake\Casbin();
76+
77+
if (true === $casbin->enforce($sub, $obj, $act)) {
78+
// permit alice to read data1
79+
} else {
80+
// deny the request, show an error
81+
}
82+
```
83+
84+
### Define your own model.conf
85+
86+
You can modify the config file named `config/casbin-model.conf`
87+
88+
### Learning Casbin
89+
90+
You can find the full documentation of Casbin [on the website](https://casbin.org/).

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "casbin/cake-adapter",
3+
"keywords": ["casbin", "cakephp", "casbin-adapter", "database"],
4+
"description": "Use casbin in CakePHP. ",
5+
"authors": [
6+
{
7+
"name": "TechLee",
8+
"email": "[email protected]"
9+
}
10+
],
11+
"license": "Apache-2.0",
12+
"require": {
13+
"cakephp/cakephp": "3.*",
14+
"casbin/casbin": "0.*"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"CasbinAdapter\\Cake\\": "src/"
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)