2012-04-20 14 views
2

私は数日間無駄に作業してきました。モジュールとコントローラのアクセスに関する問題を伴うZend ACL

ZF Boilerplateを使用して、モジュールを含むACLを設定しようとしています(アーキテクチャに同じ名前のコントローラがあり、変更できません)。 私はこれがうまく動作していて、アクセスが処理されないことに気がつきました。何か不足していると思いますが、何がわかりません。ここで

は私のセットがアップしている:ライブラリ/アプリケーション/アクション/ヘルパー/ PrivilegesManage.php

ヘルパー

<?php 
class App_Action_Helpers_PrivilegesManage extends Zend_Controller_Action_Helper_Abstract 
{ 
//the acl object 
public $acl; 
//the constructor of the our ACL 
public function __construct() 
{ 
    $this->acl = new Zend_Acl(); 
} 

//function that sets roles for the people 
public function setRoles() 
{ 
    $this->acl->addRole(new Zend_Acl_Role('guest')); 
    $this->acl->addRole(new Zend_Acl_Role('crew')); 
    $this->acl->addRole(new Zend_Acl_Role('client')); 
    $this->acl->addRole(new Zend_Acl_Role('admin')); 
} 

//function that set the resources to be accessed on the site 
public function setResources() 
{ 
    $this->acl->add(new Zend_Acl_Resource('site:error')); 
    $this->acl->add(new Zend_Acl_Resource('site:index')); 
    //me 
    $this->acl->add(new Zend_Acl_Resource('me:clients')); 
    $this->acl->add(new Zend_Acl_Resource('me:crew')); 
    $this->acl->add(new Zend_Acl_Resource('me:error')); 
    $this->acl->add(new Zend_Acl_Resource('me:index')); 
    $this->acl->add(new Zend_Acl_Resource('me:jobs')); 
    $this->acl->add(new Zend_Acl_Resource('me:people')); 
    $this->acl->add(new Zend_Acl_Resource('me:system')); 
    //admin 
    $this->acl->add(new Zend_Acl_Resource('admin:clients')); 
    $this->acl->add(new Zend_Acl_Resource('admin:crew')); 
    $this->acl->add(new Zend_Acl_Resource('admin:error')); 
    $this->acl->add(new Zend_Acl_Resource('admin:index')); 
    $this->acl->add(new Zend_Acl_Resource('admin:jobs')); 
    $this->acl->add(new Zend_Acl_Resource('admin:people')); 
    $this->acl->add(new Zend_Acl_Resource('admin:system')); 
} 

//function that sets the privileges for the different roles 
public function setPrivileges() 
{ 
    $this->acl->allow('guest', 'site:error', 'index'); 
    $this->acl->deny('guest', 'site:index', 'index'); 

    $this->acl->allow('crew', 'site:index'); 
    $this->acl->allow('crew', 'site:error'); 
    $this->acl->allow('crew', 'me:crew');  
    $this->acl->allow('client', 'me:clients'); 
    $this->acl->allow('client', 'site:index', array('logout')); 
    $this->acl->deny('client', 'me:crew'); 
    $this->acl->deny('guest', 'admin:crew', array('add')); 

} 

public function setAcl() 
{ 
    Zend_Registry::set('acl', $this->acl); 
} 
?> 

それから私はまた、アプリケーション/プラグイン/ Acl.php でプラグインを持っています

<?php 
class App_Plugin_Acl extends Zend_Controller_Plugin_Abstract 
{ 
/** 
* 
* @var Zend_Auth 
*/ 
protected $_auth; //Zend_Auth instance for user access 

protected $_acl; //Zend_Acl instance for user privileges 
protected $_module; 
protected $_action; 
protected $_controller; 
protected $_currentRole; 
protected $_resource; 

public function __construct(Zend_Acl $acl, array $options = array()) { 
    $this->_auth = Zend_Auth::getInstance(); 
    $this->_acl = $acl; 

} 

public function preDispatch(Zend_Controller_Request_Abstract $request) { 

    $this->_init($request); 

    if ($this->_acl->has($this->_resource)) { 
     // if the current user role is not allowed to do something 
     if (!$this->_acl->isAllowed($this->_currentRole, $this->_resource, $this->_action)) { 

      if ('guest' == $this->_currentRole) { 
       $request->setModuleName('site'); 
       $request->setControllerName('index'); 
       $request->setActionName('login'); 
      } 
      else { 
       $request->setModuleName('site'); 
       $request->setControllerName('error'); 
       $request->setActionName('denied'); 

      } 
     } 
    } 
} 

protected function _init($request) 
{ 
    $this->_module = $request->getModuleName(); 
    $this->_action = $request->getActionName(); 
    $this->_controller = $request->getControllerName(); 
    $this->_currentRole = $this->_getCurrentUserRole(); 
    $this->_resource = $this->_module . ':' . $this->_controller; 
} 

protected function _getCurrentUserRole() 
{  

    if($this->_auth->hasIdentity()) { 
     $authData = $this->_auth->getIdentity(); 
     //$role = isset($authData->myType())?strtolower($authData->property->privilage): 'guest'; 
     //retrieving the UserType 
      $authTypeCheck = $authData->myType(); 
     if(isset($authTypeCheck)){ 
      $role = strtolower($authData->myType()); 
     } 
    } else { 
     $role = 'guest'; 
    } 
    return $role; 
} 
} 
?> 

は今ここにその$ ACLが、私はいくつかのリソースを得るか、ACL、私は$の内容をプリントアウトするすべてのリソースを持っていたことがないと思われる[EDITED]。

は最終的に私が持っているブートストラップで:

protected function _initAclControllerPlugin() { 

    $this->bootstrap('frontcontroller'); 


    $front = Zend_Controller_Front::getInstance(); 
    $aclhelper= new App_Action_Helpers_PrivilegesManage(); 
    $aclhelper->setRoles(); 
    $aclhelper->setResources(); 
    $aclhelper->setPrivileges(); 
    $aclhelper->setAcl(); 

    $aclPlugin = new App_Plugin_Acl($aclhelper->acl); 
    $front->registerPlugin($aclPlugin); 
} 

私は、Zend、特にACLに非常に新しいですので、任意のアドバイスやヘルプは非常に歓迎されるでしょう。

protected function _getCurrentUserRole() 
{  

    if($this->_auth->hasIdentity()) { 
     $authData = $this->_auth->getIdentity(); 
     //$role = isset($authData->myType())?strtolower($authData->property->privilage): 'guest'; 
     //retrieving the UserType 
      $authTypeCheck = $authData->myType(); 
     if(isset($authTypeCheck)){ 
      $role = strtolower($authData->myType()); 
     } 
    } else { 
     $role = 'guest'; 
    } 
    return $role; 
} 

$ authTypeCheckが設定されていない場合は、役割があるように見えます:

答えて

3

あなたがあなたのリソースを定義していませんが、あなたのACLプラグイン

protected function _init($request) 
{ 

    $this->_module = $request->getModuleName(); 
    $this->_action = $request->getActionName(); 
    $this->_controller = $request->getControllerName(); 
    $this->_currentRole = $this->_getCurrentUserRole(); 
    $this->_resource = $this->_module . ':' . $this->_controller; // <----- 
} 
+0

u_uばかげて私は愚かにこの行を削除する必要があります、私はそのショットを与える!どうもありがとう! EDIT: これはうまくいきましたが、setPrivilegesで設定されたルールはまったく問題にはなりません... – AKFourSeven

1

にこの方法に関連している可能性があり、これを行います定義されていません。まさに$ authData-> myType()が何をしているのかよくわかりませんが、それが原因かもしれません。

if(isset($ authTypeCheck)){else}を{$ role = 'guest';}に追加できます。 }

これに類似したコードをよく見ることは、コメント行の1つで行われました。

ご迷惑をおかけしても、私の使用事例と比べると、かなり複雑なアプローチがとられています。おそらく多くの問題を排除するAcl Plugin Predispatchメソッドにそのコードをすべてラップすることができます。

関連する問題