Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 52965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:59:22+00:00 2026-05-10T16:59:22+00:00

I’m struggling to implement ACL in CakePHP. After reading the documentation in the cake

  • 0

I’m struggling to implement ACL in CakePHP. After reading the documentation in the cake manual as well as several other tutorials, blog posts etc, I found Aran Johnson’s excellent tutorial which has helped fill in many of the gaps. His examples seem to conflict with others I’ve seen though in a few places – specifically in the ARO tree structure he uses.

In his examples his user groups are set up as a cascading tree, with the most general user type being at the top of the tree, and its children branching off for each more restricted access type. Elsewhere I’ve usually seen each user type as a child of the same generic user type.

How do you set up your AROs and ACOs in CakePHP? Any and all tips appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T16:59:22+00:00Added an answer on May 10, 2026 at 4:59 pm

    CakePHP’s built-in ACL system is really powerful, but poorly documented in terms of actual implementation details. A system that we’ve used with some success in a number of CakePHP-based projects is as follows.

    It’s a modification of some group-level access systems that have been documented elsewhere. Our system’s aims are to have a simple system where users are authorised on a group-level, but they can have specific additional rights on items that were created by them, or on a per-user basis. We wanted to avoid having to create a specific entry for each user (or, more specifically for each ARO) in the aros_acos table.

    We have a Users table, and a Roles table.

    Users

    user_id, user_name, role_id

    Roles

    id, role_name

    Create the ARO tree for each role (we usually have 4 roles – Unauthorised Guest (id 1), Authorised User (id 2), Site Moderator (id 3) and Administrator (id 4)) :

    cake acl create aro / Role.1

    cake acl create aro 1 Role.2 ... etc ...

    After this, you have to use SQL or phpMyAdmin or similar to add aliases for all of these, as the cake command line tool doesn’t do it. We use ‘Role-{id}’ and ‘User-{id}’ for all of ours.

    We then create a ROOT ACO –

    cake acl create aco / 'ROOT'

    and then create ACOs for all the controllers under this ROOT one:

    cake acl create aco 'ROOT' 'MyController' ... etc ...

    So far so normal. We add an additional field in the aros_acos table called _editown which we can use as an additional action in the ACL component’s actionMap.

    CREATE TABLE IF NOT EXISTS `aros_acos` ( `id` int(11) NOT NULL auto_increment, `aro_id` int(11) default NULL, `aco_id` int(11) default NULL, `_create` int(11) NOT NULL default '0', `_read` int(11) NOT NULL default '0', `_update` int(11) NOT NULL default '0', `_delete` int(11) NOT NULL default '0', `_editown` int(11) NOT NULL default '0', PRIMARY KEY  (`id`), KEY `acl` (`aro_id`,`aco_id`) ) ENGINE=InnoDB  DEFAULT CHARSET=utf8; 

    We can then setup the Auth component to use the ‘crud’ method, which validates the requested controller/action against an AclComponent::check(). In the app_controller we have something along the lines of:

    private function setupAuth() {     if(isset($this->Auth)) {         ....         $this->Auth->authorize = 'crud';         $this->Auth->actionMap = array( 'index'     => 'read',                         'add'       => 'create',                         'edit'      => 'update'                         'editMine'  => 'editown',                         'view'      => 'read'                         ... etc ...                         );         ... etc ...     } } 

    Again, this is fairly standard CakePHP stuff. We then have a checkAccess method in the AppController that adds in the group-level stuff to check whether to check a group ARO or a user ARO for access:

    private function checkAccess() {     if(!$user = $this->Auth->user()) {         $role_alias = 'Role-1';         $user_alias = null;     } else {         $role_alias = 'Role-' . $user['User']['role_id'];         $user_alias = 'User-' . $user['User']['id'];     }      // do we have an aro for this user?     if($user_alias && ($user_aro = $this->User->Aro->findByAlias($user_alias))) {         $aro_alias = $user_alias;     } else {         $aro_alias = $role_alias;     }      if ('editown' == $this->Auth->actionMap[$this->action]) {         if($this->Acl->check($aro_alias, $this->name, 'editown') and $this->isMine()) {             $this->Auth->allow();         } else {             $this->Auth->authorize = 'controller';             $this->Auth->deny('*');         }     } else {         // check this user-level aro for access         if($this->Acl->check($aro_alias, $this->name, $this->Auth->actionMap[$this->action])) {             $this->Auth->allow();         } else {             $this->Auth->authorize = 'controller';             $this->Auth->deny('*');         }     } } 

    The setupAuth() and checkAccess() methods are called in the AppController‘s beforeFilter() callback. There’s an isMine method in the AppControler too (see below) that just checks that the user_id of the requested item is the same as the currently authenticated user. I’ve left this out for clarity.

    That’s really all there is to it. You can then allow / deny particular groups access to specific acos –

    cake acl grant 'Role-2' 'MyController' 'read'

    cake acl grant 'Role-2' 'MyController' 'editown'

    cake acl deny 'Role-2' 'MyController' 'update'

    cake acl deny 'Role-2' 'MyController' 'delete'

    I’m sure you get the picture.

    Anyway, this answer’s way longer than I intended it to be, and it probably makes next to no sense, but I hope it’s some help to you …

    — edit —

    As requested, here’s an edited (purely for clarity – there’s a lot of stuff in our boilerplate code that’s meaningless here) isMine() method that we have in our AppController. I’ve removed a lot of error checking stuff too, but this is the essence of it:

    function isMine($model=null, $id=null, $usermodel='User', $foreignkey='user_id') {     if(empty($model)) {         // default model is first item in $this->uses array         $model = $this->uses[0];     }      if(empty($id)) {         if(!empty($this->passedArgs['id'])) {         $id = $this->passedArgs['id'];         } elseif(!empty($this->passedArgs[0])) {             $id = $this->passedArgs[0];         }     }      if(is_array($id)) {         foreach($id as $i) {             if(!$this->_isMine($model, $i, $usermodel, $foreignkey)) {                 return false;             }         }          return true;     }      return $this->_isMine($model, $id, $usermodel, $foreignkey); }   function _isMine($model, $id, $usermodel='User', $foreignkey='user_id') {     $user = Configure::read('curr.loggedinuser'); // this is set in the UsersController on successful login      if(isset($this->$model)) {         $model = $this->$model;     } else {         $model = ClassRegistry::init($model);     }      //read model     if(!($record = $model->read(null, $id))) {         return false;     }      //get foreign key     if($usermodel == $model->alias) {         if($record[$model->alias][$model->primaryKey] == $user['User']['id']) {             return true;         }     } elseif($record[$model->alias][$foreignkey] == $user['User']['id']) {         return true;     }      return false; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer To only check for updates hourly (for example) use this… May 12, 2026 at 12:53 am
  • Editorial Team
    Editorial Team added an answer The formal way of controlling use of your object is… May 12, 2026 at 12:53 am
  • Editorial Team
    Editorial Team added an answer Have a google for "Role Based Access Control" and "Domain-Based… May 12, 2026 at 12:53 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.