Zend_ACL with a modular structure?

I created MVC with Zend by reading http://framework.zend.com/manual/en/zend.controller.modular.html .

The problem is that I cannot find a way to use Zend_ACL with a modular structure. Zend_Acl simply does not have a method for adding modules. This allows me to add a controller and action.

How to use Zend_Acl with a modular structure? Is this possible with the current version of Zend Framework?

+3
source share
3 answers

This is absolutely true. This is what we do in our project. We authenticating the way the URI ( $request->getPathInfo()), for example /admin/user/edit. Here, “admin” is the module, “user” is the controller, and “edit” is the action. And we have an access plugin:

class Our_Application_Plugin_Access extends Zend_Controller_Plugin_Abstract {
    public function preDispatch(Zend_Controller_Request_Abstract $request) {
        foreach (self::current_roles() as $role) {
            if (
                Zend_Registry::get('bootstrap')->siteacl->isAllowed(
                    $role,
                    $request->getPathInfo()
                )
            ) return;
        }

        $this->not_allowed($request);
    }

   ...
}

Registered in application.ini:

resources.frontController.plugins.access = "Our_Application_Plugin_Access"
+2
source

Another option for Ivan is to install resources that are in the system of only the "controller" on sth. as a "controller module".

+1
source

, . , , Zend_Acl, - (), . "", , "". "login-button", "logout-button", Zend_Navigation.

In your case, you should define the resource (in acl) as some string that can be displayed on the module / controller layout. For example, for the foo module and control panel, specify the resource "foo.bar". Then, in the access control procedure, you will read the name of the module and the controller and combine them into a string to obtain a resource.

In an example example:

class Application_Plugin_AccessCheck extends Zend_Controller_Plugin_Abstract {

...

public function preDispatch(Zend_Controller_Request_Abstract $request){
    $module = $request->getModuleName();
    $controller = $request->getControllerName();
    $action = $request->getActionName();

...

   $resource = $module . '.' . $controller; //we create the custom resource according to the model we have defined
...

    $role=NULL;
    if($this->_auth->hasIdentity()){
        $identity = $this->_auth->getStorage()->read(); //depending on your implementation
        $role = $identity->role; //depending on your implementation
    }
...

  if(!$this->_acl->isAllowed($role, $resource, $action)){
        //deny access       
    }
    //allow access
}
}
+1
source

Source: https://habr.com/ru/post/1724673/


All Articles