1

I've been working on a project and the first thing I did was adding the Authentication and Authorization plugins. I did not used AuthComponent at all since its deprecated.

Now I want to add extra logic on the database and installed the ACL Plugin. I haven't managed to find documentation and all the examples on the internet implement the plugin using the old AuthComponent.

What I need is find a way to make for the ACL to use the new Authentication plugin

This is my AppController.php:

    public function initialize(): void
    {
        parent::initialize();

        $this->loadComponent('RequestHandler');
        $this->loadComponent('Flash');

        // Add this line to check authentication result and lock your site
        $this->loadComponent('Authentication.Authentication');
        $this->loadComponent('Authorization.Authorization');

        $this->loadComponent('Acl', [
            'className' => 'Acl.Acl'
        ]);

        $this->loadComponent('Auth', [
            'authorize' => [
                'Acl.Actions' => [
                    'actionPath' => 'controllers/',
                    'userModel' => 'Users'
                ]
            ],
            'authenticate' => [
                'Form' => [
                    'fields' => ['username' => 'email'],
                    'userModel' => 'Users'
                ],
            ],
            'loginAction' => [
                'plugin' => false,
                'controller' => 'Users',
                'action' => 'login'
            ],
            'loginRedirect' => [
                'plugin' => null,
                'controller' => 'Users',
                'action' => 'index'
            ],
            'logoutRedirect' => [
                'plugin' => null,
                'controller' => 'Users',
                'action' => 'login'
            ],
            'unauthorizedRedirect' => [
                'controller' => null,
                'action' => 'login',
                'prefix' => false
            ],
            'authError' => 'You are not authorized to access that location.',
            'flash' => [
                'element' => 'error'
            ]
        ]);
        /*

Found on stackoverflow that "These two plugins are not ment to work together, cakephp/acl is strictly ment for use with the deprecated auth component. If you want ACLs for cakephp/authorization, then you need to implement that yourself".

I have no idea how to do that, so Im still listening if anyone has any idea on how to do that or what could be another solution.

pkdpqowjodiv
  • 123
  • 1
  • 7
  • @OP were you able to achieve this? If yes, how? I'd be very interested in a solution as I have the same problem. – mrodo May 31 '22 at 15:06
  • Sadly, no. I started using both: the Authentication plugin and the Authcomponent. Also included some awful code to avoid some redirection loops. After a while I ended up removing the ACL plugin and writing it myself on my RequestPolicy file https://book.cakephp.org/authorization/1/en/request-authorization-middleware.html – pkdpqowjodiv May 31 '22 at 16:49

0 Answers0