0

i am creating a acl controller plugin that checks the if the user is authorized to the resource and redirect to the error controller to handle it. how do i go abt doing this?

Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
  • http://framework.zend.com/manual/en/zend.controller.plugins.html Look at Error Controllers. You need to create a ErrorController class and an action with the default name -> errorAction. Then check permission in your ACL plugin and if denied forward to this controller. Theres several ways. – Layke Aug 02 '10 at 12:46

1 Answers1

1

Take a look at this question on SO: Help with Zend ACL.
Another good ACL/Auth tutorial can by found at devzone: Zend_Acl / Zend_Auth Example Scenario (The codelisting is incomplete but have a look at the comment "THE MISSING PIECES")

The important part is in the preDispatch Plugin:

$controller = $request->controller;
$action     = $request->action;
$module     = $request->module;
$resource   = $controller;

if (!$this->_acl->isAllowed($role, $resource, $action)) {
    if (!$this->_auth->hasIdentity()) {
        $module     = 'default';
        $controller = 'login';
        $action     = 'index';
    } else {
        $module     = 'default';
        $controller = 'error';
        $action     = 'privileges';
    }
}

$request->setModuleName($module);
$request->setControllerName($controller);
$request->setActionName($action);

If the is not logged in or has insufficient rights the request will be modified to forward to the Loginpage or the error controller.

Community
  • 1
  • 1
Benjamin Cremer
  • 4,842
  • 1
  • 24
  • 30
  • this is a great answer for my other question :) to redirect from controller plugins. use `Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')`. here, i am wondering how i can edit the error controller to show error messages to the user eg. if they are trying to access an unauthorized resource – Jiew Meng Aug 02 '10 at 14:14