PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 16, 2022

[FIXED] How to use multiple users table in ACL plugin for CakePHP 3.2?

 February 16, 2022     cakephp, model-view-controller, php     No comments   

Issue

I have three different types of users, all stored in different tables. I want to implement ACL to allow/deny certain access to them. The default behavior of cakephp acl plugin uses the "users" table & assigns them in "groups". Is there any way i can customize this to use multiple users table.

Thanks in advance.


Solution

disclaimer: I did not test what I'm going to write

I see that Acl have a userModel parameter that you can config (see here).

So when loading the component you have to set it according to you actual user table

$this->loadComponent('Auth', [
    'authorize' => [
        'Acl.Actions' => [
            'actionPath' => 'controllers', 
            'userModel' => 'Users' // <== you can change this
                                   // i.e. to Guests, Admins...
        ],
    ],

of course you hve to set as requester every Table that can login

 $this->addBehavior('Acl.Acl', ['type' => 'requester']);

The only problem I see here is that you don't know what kind of user you have until he is logged in. So you can set 'userModel' only after login. Maybe this can cause some issue at the login phase, I'm not sure.

Anyway I still believe that the simpler way is to use a single table and different roles.



Answered By - arilia
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing