Joseph Crawford Using wordpress because he is lazy

12Nov/1061

CakePHP ACL Management

ACL Management Plugin ScreenshotRecently I was working on a post for setting up the CakePHP Acl Component and was just walking through Mark Story's tutorial in the documentation to see what people were starting from. For basic ACLs it is pretty much the only way to go. Although many situations will require some tweeking. I realized the main thing lacking from all of the documentation I've read is a way to manage the stupid things. I've seen one or two in the past but if you could get them to work it was a miracle and even then they were not very friendly to use. So I began working on a plugin to manage ACOs and ACLs for the CakePHP AclComponent based on a set up that my friend Kenny Austin built at work. This plugin assumes that you were following the tutorial in the CakePHP documentation and even includes Mark Story's build_acl() function built into a component. I didn't include a way to manage AROs because those are created automatically for your users and groups. If you want help with managing those see my recent Auth Component tutorial. The code from it should work with a few minor changes to the models. Also keep in mind that this plugin (and the tutorial in the book) assumes that your users only belong to one group. If this plugin fits your need feel free to try it out.

Download

To use just extract the contents to your plugins directory and access it by going to http://yoursite/acls. You may need to initially rebuild the ACOs but there is a button for that. Then grant yourself access to the plugin's ACOs and remove the $this->Auth->allow('*'); line from the beforeFilter of the 3 controllers. Please drop a comment with any feedback.

Comments (61) Trackbacks (1)
  1. Hello Joseph,

    Thank you for the great plugin. I have the problem with “Rebuild ACO” it leads to a 404 Error, page not found.

    After installing the plugin, I wanted to rebuild the ACOs so that I create permission for accessing the plugin ACLS to admins only.

    Thank you for the help

  2. Do you have a solution for users with multiple groups? I have 3 groups and from what I understand, this plugin will only work for users with one group.

    • I have set up multiple group permissions before on a site but was not able to do it with the Cake ACL component. The way I did it was to just use the Auth component and then created my own ACL component that would check permissions in the same tables the Cake’s acl component uses. It has been a while since then and so I don’t remember specifically what problem I had with it or even if they have fixed it by now. All I know is at the time it was really just made for a user belongs to one group set up.

  3. I decided to man up and create my first plugin, please welcome, the ACL management plugin. I know this has been done before, but I haven’t seen anything lately that works with CakePHP 1.2. Plus, I used AJAX to make working with trees easier and faster. This way I dont have to load the whole tree on startup.
    Everyone is more than welcome to share in the fun

  4. Hi,
    I tried to install this in 1.3.13 after going through the official manual and it gives me this error:
    “The AuthComponent actionPath variable is not set in your AppController.”
    Although in my AppController I have this:

    function beforeFilter() {
    //Configure AuthComponent
    $this->Auth->authorize = ‘actions’;
    $this->Auth->loginAction = array(‘controller’ => ‘users’, ‘action’ => ‘login’);
    $this->Auth->logoutRedirect = array(‘controller’ => ‘users’, ‘action’ => ‘logout’);
    $this->Auth->loginRedirect = array(‘controller’ => ‘posts’, ‘action’ => ‘add’);
    $this->Auth->actionPath = ‘controllers/’;
    $this->Auth->allowedActions = array(‘display’);
    }

    Any idea how to solve this?

    Regards,

    Luc

  5. I get the same problem as Luc. This is AppController::beforeFilter()

    function beforeFilter()
    {
    parent::beforeFilter();
    $this->Auth->loginRedirect = array(‘controller’ => ‘main’, ‘action’ => ‘index’);
    $this->Auth->actionPath = ‘controllers/’;
    //$this->Auth->authorize = ‘actions’;
    }

    actionPath is clearly defined.

    Thanks for any help you can offer on this.

  6. I fixed this by removing the definition of the Auth component from beforeFilter and creating it as a class property like so:

    public $components = array(
    ‘Acl’,
    ‘Session’,
    ‘Auth’ => array(
    ‘loginRedirect’ => array(‘controller’ => ‘main’, ‘action’ => ‘index’),
    ‘actionPath’ => ‘controllers/’
    )
    );

  7. Hi JB, I’ve updated this plugin to 2.0 and made a git repo for this plugin here https://github.com/bmilesp/Acls. Thanks for the great plugin, and if you would rather be owner of the repo, please let me know!


Leave a comment

(required)