Skip to content
Use Casbin in CakePHP Framework, Casbin is a powerful and efficient open-source access control library.
Branch: master
Clone or download
Latest commit 0adacd1 Jan 7, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config Initial commit Jan 7, 2019
src
.gitignore Initial commit Jan 7, 2019
LICENSE
README.md
composer.json
composer.lock Initial commit Jan 7, 2019

README.md

Cake-Casbin

Latest Stable Version Total Downloads License

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-adapter

create config file config/casbin.php for Casbin:

<?php

return [
    'Casbin' => [
         /*
         * 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' => '\CasbinAdapter\Cake\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


$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 \CasbinAdapter\Cake\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.

You can’t perform that action at this time.