【问题标题】:Authorization and ACL in cakephp 3cakephp 3中的授权和ACL
【发布时间】:2015-01-01 06:35:14
【问题描述】:

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

【问题讨论】:

    标签: authorization acl cakephp-3.0


    【解决方案1】:

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

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

    ACL 相关类已移至单独的插件。密码哈希, 身份验证和授权提供程序移至 \Cake\Auth 命名空间。您需要移动您的提供者和 散列到 App\Auth 命名空间。

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

    【讨论】:

      【解决方案2】:

      好问题,正如 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;
          }
      

      如果用户/动作/控制器位可以更好地清理,比我更聪明的人会更清楚。有很多关于这个插件的稳定性的警告,以及在性能方面的 acl 上的“陷阱”。

      我正在从 1.3 实现切换,添加来自 http://book.cakephp.org/3.0/en/controllers/components/authentication.html 的 AppController 'initialize' 信息很有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-09-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-04-17
        • 2018-02-09
        相关资源
        最近更新 更多