There is an undocumented PhpAcl acl PhpAcl that is much easier to use than a database-managed ACL and more dynamic than a variable-access ACL.
In Config/core.php
Configure::write('Acl.classname', 'PhpAcl');
This tells the ACL to use PhpAcl
Then open Config/acl.php
There are good instructions there
Assumption:
- In your application, you created a User model with the following properties: username, group_id, password, email, firstname, lastname, etc.
- You configured AuthComponent to authorize actions through
$this->Auth->authorize = array('Actions' => array('actionPath' => 'controllers/'),...)
Now that the user (i.e. jeff) is successfully authenticated and requests controller actions (i.e. / invoices / deletions) that are not allowed by default (for example, via $ this-> Auth-> allow ('edit ') in the invoice controller), then AuthComponent will request the configured ACL interface if access is granted. Under assumptions 1. and 2. this will be done by calling Acl-> check () with
array('User' => array('username' => 'jeff', 'group_id' => 4, ...))
like aro and
'/controllers/invoices/delete'
like ACO.
I wanted to use static names for groups or roles so that you could add a role field to your user table and then set up $ map as follows:
** * The role map defines how to resolve the user record from your application * to the roles you defined in the roles configuration. */ $config['map'] = array( 'User' => 'User/username', 'Role' => 'User/role', );
For my application, we do not use only the permissions role only for users, so we can remove User from the $ card.
Then you need to configure some roles:
$config['roles'] = array( 'Role/admin' => null, );
Any role not included in this array will receive "Role / default"
Now just configure your permissions, they are pretty clear.
$config['rules'] = array( 'allow' => array( '*' => 'Role/admin', 'controllers/Reports/*' => 'Role/default', 'controllers/EurRates/*' => 'Role/default', 'controllers/Posts/index' => 'Role/default', 'controllers/Users/(edit|index)' => 'Role/default', ), 'deny' => array( 'controllers/ProtectedController/*' => 'Role/default', 'controllers/EurRates/(edit|add|delete)' => 'Role/default', 'controllers/Reports/(edit|add|delete)' => 'Role/default', ), );
To do this, you can now allow or deny permission for role-based actions.