php - Using Zend_Auth to secure all controllers -


how globally secure controllers (except login controller) ensure application secure @ points (no hidden backdoor ajax calls, etc). thought might put in bootstrap file, doesn't feel right? i'm trying avoid adding code each controller.

suggestions?

edit: complement of @singles response.

you must understand there 2 different things. auth , acl. auth tells user, , can example redirect user having no auth login controller, , set auth identity after login. acl system take yes/no decisions based on auth data (could user id or role, stored in auth storage.

on nice solution have 2 controllers plugins (registered in order on bootstrap, auth acl). if not use controller plugins you'll have call acl check in each controller, when needed. if need it, use plugins.

implement predispatch() in auth plugin set example anonymous identity if have no identity return zend_auth. code snippet of real one:

public function predispatch(zend_controller_request_abstract $request) {     $module = $request->getmodulename();     $controller = $request->getcontrollername();     $action = $request->getactionname();     $auth = zend_auth::getinstance();     if (!$auth->hasidentity()) {         // set default anonymous identity         $auth->getstorage()->write(array('name' => 'anonymous','role' => 1,));     } (...) 

and acl controller plugin task in predispatch(). can launch acl check each requested url (so each user request, ajax). here's partial snippet, example of how handle things:

public function predispatch(zend_controller_request_abstract $request) {     $controller = $request->controller;     $module = $request->module;     $action = $request->action;     // here should code nice retrieving zend_acl object     // caching options maybe, building roles, ressources, etc     $this->_acl = $this->getacl();      if (!$this->_acl->iscurrentuserallowed($module,'see')) {         $auth = zend_auth::getinstance();     $identity  = $auth->hasidentity('identity')? $auth->getidentity() : null;     if(isset($identity)) {             if($identity['name'] == 'anonymous') {                 // warning: avoid infinite redirect loops on login page                 if (!($request->getcontrollername() == 'login'                      && $request->getactionname()=='login'                      && $request->getmodulename() == 'default')) {                         $request->setcontrollername('login')                ->setactionname('login')                ->setmodulename('default');             return; (...) 

and in system last important part logincontroller in case of succesful login should initate identity record:

(...) $auth = zend_auth::getinstance(); zend_session::regenerateid(); $storage = $auth->getstorage(); $rowobject = $authadapter->getresultrowobject(null,'passwd'); $storage->write((array)$rowobject); (...) 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -