Last active
August 29, 2015 14:08
-
-
Save andrebian/fbcd0b674680e65621b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//core.php | |
Configure::write('Acl.classname', 'PhpAcl'); | |
// acl.php | |
$config['map'] = array( | |
'User' => 'User/username', | |
'Role' => 'User/role_id', | |
); | |
$config['alias'] = array( | |
'Role/1' => 'Role/equipe-x', | |
'Role/2' => 'Role/validador-x', | |
'Role/3' => 'Role/validador-y', | |
'Role/4' => 'Role/validador-z', | |
'Role/5' => 'Role/gestor', | |
'Role/6' => 'Role/geral', | |
'Role/7' => 'Role/nao-cadastrado', | |
); | |
/** | |
* role configuration | |
*/ | |
$config['roles'] = array( | |
'Role/equipe-x' => null, | |
'Role/validador-x' => null, | |
'Role/validador-y' => null, | |
'Role/validador-z' => null, | |
'Role/gestor' => null, | |
'Role/geral' => null, | |
'Role/nao-cadastrado' => null, | |
); | |
/** | |
* rule configuration | |
*/ | |
$config['rules'] = array( | |
'allow' => array( | |
//liberando tudo à todos | |
'*' => 'Role/equipe-x, Role/validador-x, Role/validador-y, Role/validador-z, Role/gestor, Role/geral, Role/nao-cadastrado', | |
), | |
'deny' => array( | |
// bloqueando somente as poucas actions que nem todos tem acesso | |
'controllers/users/(add|edit|delete)' => 'Role/validador-y', | |
), | |
); | |
// AppController | |
public $components = array('Acl', 'Auth' => array('authorize' => 'Controller'), 'Session'); | |
public function beforeFilter() | |
{ | |
//... | |
if( !$this->isAuthorized() ) { | |
$this->Session->setFlash($this->Auth->authError); | |
$this->redirect($this->Auth->redirectUrl()); | |
} | |
//... | |
} | |
protected function isAuthorized() | |
{ | |
$aco = 'controllers/'.$this->params['controller']; | |
$aro = $this->Auth->user('role_id'); | |
return $this->Acl->check($aro, $aco, $this->params['action']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment