项目作者: zunnu

项目描述 :
Enforcer is a simple lightweight ACL plugin for CakePHP 3
高级语言: PHP
项目地址: git://github.com/zunnu/enforcer.git
创建时间: 2020-08-17T15:36:08Z
项目社区:https://github.com/zunnu/enforcer

开源协议:

下载


Enforcer

Enforcer is a simple lightweight acl plugin for CakePHP 3.x

Requirements

  • CakePHP 3.x
  • PHP 7.2 >

Installing Using Composer

cd to the root of your app folder (where the composer.json file is) and run the following command:

  1. composer require zunnu/enforcer

Then load the plugin by using CakePHP’s console:

  1. ./bin/cake plugin load Enforcer

Next create the tables:

  1. ./bin/cake migrations migrate -p Enforcer

Usage

You will need to modify your src/Controller/AppController.php and load the Enforcer component in the initialize() function

  1. $this->loadComponent('Enforcer.Enforcer', [
  2. 'unauthorizedRedirect' => [
  3. 'plugin' => false,
  4. 'controller' => 'Users',
  5. 'action' => 'login',
  6. 'prefix' => false
  7. ],
  8. 'protectionMode' => 'everything' // everything | filters
  9. ]);

The unauthorizedRedirect will tell Enforcer where to redirect if the user has permission error.
The protectionMode will tell Enforcer how to handle permissions.

protectionModes README
everything Enforcer will automaticly try to protect all public controller function
filters Enforcer will protect the controllers where the protection is called from the beforeFilter()

If the protectionMode filters is enabled you need to add the

  1. public function beforeFilter(Event $event) {
  2. parent::beforeFilter($event);
  3. // permission load
  4. return $this->Enforcer->hasAccess($this->request, $this->Auth->user());
  5. }

Permissions

The migrations will create tree different groups.
You can add, modify or delete groups by going to
http://app-address/enforcer/admin/groups/index

Groups README
admin All powerfull
user Default user group
guest Site visitors

The default admin group should be able to access the permissions page.
You should be able to access the page using this url
http://app-url/enforcer/admin/permissions
Enforcer permissions


Enforcer permissions

If the request is ajax the permission error will look like this:
Enforcer permissions

Todos

  • User specific permissions
  • Groupped controllers. Like the user only has access to billing

License

Licensed under The MIT License.