cakephp 3 中的授权和 ACL

Authorization and ACL in cakephp 3

我搜索了文档,但没有找到任何关于 cakephp 3 中 ACL 实现的信息。 如何在cakephp 3中使用ACL实现授权?

ACL 不像在 CakePHP 2 中那样内置在 CakePHP 3 中。它现在可以作为单独的插件使用。

Quote from http://book.cakephp.org/3.0/en/appendices/3-0-migration-guide.html

ACL related classes were moved to a separate plugin. Password hashers, Authentication and Authorization providers where moved to the \Cake\Auth namespace. You are required to move your providers and hashers to the App\Auth namespace as well.

您可以在 https://github.com/cakephp/acl 找到该插件,但请注意它还不稳定。

问得好,正如 Daniel Castro 所说,插件位于 https://github.com/cakephp/acl

缺少的部分是用类似以下内容覆盖 'AppController.php' 中的 'isAuthorized':

...
use Acl\Controller\Component\AclComponent;
use Cake\Controller\ComponentRegistry;
...



public function isAuthorized($user){
      $Collection = new ComponentRegistry();
      $acl= new AclComponent($Collection);
      $username=$user['username'];
      $controller=$this->request->controller;
      $action=$this->request->action;
      $check=$acl->check($user['username'],"$controller/$action");
      return $check;
    }

比我聪明的人会更清楚 user/action/controller 位是否可以更好地清理。关于此插件的稳定性和性能方面的 acl 'gotchas' 有很多警告。

我正在从 1.3 实现中删除,添加来自 http://book.cakephp.org/3.0/en/controllers/components/authentication.html

的 AppController 'initialize' 信息很有帮助