Control access level for the module in zend framework

Is there a method of deviating acl order for a module. Do I always need to add a controller and index? I have an admin module and a default module that has a dozen controllers and three dozen actions for them, and it's really tedious

My code is like this

class Management_Access extends Zend_Controller_Plugin_Abstract{ public function preDispatch(Zend_Controller_Request_Abstract $request) { // set up acl $acl = new Zend_Acl(); // add the roles $acl->addRole(new Zend_Acl_Role('guest')); $acl->addRole(new Zend_Acl_Role('administrator'), 'guest'); // add the resources $acl->add(new Zend_Acl_Resource('index')); $acl->add(new Zend_Acl_Resource('error')); $acl->add(new Zend_Acl_Resource('login')); //admin resources $acl->add(new Zend_Acl_Resource('destination')); $acl->add(new Zend_Acl_Resource('home')); $acl->add(new Zend_Acl_Resource('page')); $acl->add(new Zend_Acl_Resource('tour')); $acl->add(new Zend_Acl_Resource('hotel')); 

no way to check if a resource is registered in acl?

UPDATE :: I have eight controllers in my default module and nine controllers in the "admin" module.

I have an index controller in the admin module as well as in the default module. if I add allow guest index, the guest will also be able to access the index page in the admin module. Administrative module is installed only for the administrator

+4
source share
3 answers

Two possible solutions:

  • check the current module in the controller plugin ( $request->getModuleName() )
  • implement the logic in the bootstrap module (only for the required module).

Change after update:

You just need to consider modules + controllers as resources and actions as privileges:

 $acl->deny('guest', 'adminmodulename:controllername', array('tour', 'hotel')); 

or for everyone:

 $acl->deny('guest', 'adminmodulename:controllername'); 

no way to check if a resource is registered in acl?

$ acl-> has ($ resource)

+4
source

This is not a very specific question :)

In any case ... You may have to implement your own user management for ZF. But fear not, there are tons of online tutorials! ( e.g. here )

What do you mean by "always need to add a controller and index?"

+1
source

I understand your question. I suggest you make your application modular. For an ACL, just move it (and also make your modules resources)!

eg.

 // ROLES $this->addRole(new Zend_Acl_Role('guest')); // default $this->addRole(new Zend_Acl_Role('Marketing'), 'guest'); // 15 // RESOURCES (MY MODULES) $this->add(new Zend_Acl_Resource('auth')); $this->add(new Zend_Acl_Resource('takeon')); // PRIVILEGES // // default $this->deny(); // // guest $this->allow('guest', 'auth'); // 15 Marketing $this->allow('Marketing', 'default'); $this->allow('Marketing', 'takeon', array('index', 'ben10cards')); 

Then in your plugin use:

 // OBTAIN CONTROL LIST $acl = new Auth_Model_Acl(); // OBTAIN RESOURCE $module = $request->getModuleName(); $controller = $request->getControllerName(); // VALIDATE if ($acl->isAllowed($role, $module, $controller)) { $allowed = true; 

Then you may not have resources for action, but better for me :)

0
source

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


All Articles