【问题标题】:How to give node referance to check cakephp 2.3 ACL permission如何给节点引用以检查 cakephp 2.3 ACL 权限
【发布时间】:2013-05-26 13:19:17
【问题描述】:

我正在使用 cakephp 2.3.0 并使用 ACL。我授予以下组的权限:

$group->id = 2;
$this->Acl->deny($group, 'controllers');
$this->Acl->allow($group, 'controllers/Posts');

现在如何检查 $group->id = 2 是否允许来自同一控制器的“控制器/帖子”?

我在努力

$this->Acl->check('controllers/Posts', '2');

但它总是返回 false 并生成警告:

Failed ARO/ACO node lookup in permissions check. Node references:
Aro: controllers/Pages
Aco: Data entry operator

请帮助我。谢谢。

【问题讨论】:

    标签: php cakephp acl user-permissions cakephp-2.3


    【解决方案1】:

    检查节点权限与设置该权限非常相似,即

    $group->id = 2;
     $this->Acl->check($group, 'controllers/Posts');
    

    【讨论】:

      【解决方案2】:

      语法

      $this->Acl->check(array(
          'model' => 'ModelName',       # The name of the Model to check agains
          'foreign_key' => $foreign_key # The foreign key the Model is bind to
      ), 'Controller/action');          # The controller and action to check the permissions for
      

      这会导致以下调用:

      作为用户

      $this->Acl->check(array(
          'model' => 'User',
          'foreign_key' => $userId
      ), 'Posts/index');
      

      作为一个群体

      $this->Acl->check(array(
          'model' => 'Group',
          'foreign_key' => $groupId
      ), 'Posts/index');
      

      为了便于阅读,我把它写下来,包括一些换行符。

      更多信息请访问:

      【讨论】:

      • 还有一个问题,$this->Acl->check() 很慢。检查所有资源的时间太长。有什么更快的方法吗?
      • 您可以在 Session 中缓存数组中的每个唯一条目。这样您就不必多次检查它。只需扩展 AuthComponent 并添加一个尝试首先检查会话数据的新方法。 注意:当您更新 ACL 表并且用户没有销毁它的会话时,会话不会知道我,请记住这一点 ;-) 但是不,没有除了缓存之外的任何更快的方法。够难过的。但通常 ACL 表不会经常更改。
      猜你喜欢
      • 2012-09-06
      • 1970-01-01
      • 1970-01-01
      • 2011-09-17
      • 2011-04-29
      • 2020-03-08
      • 1970-01-01
      • 1970-01-01
      • 2012-03-20
      相关资源
      最近更新 更多