loadComponent('FormProtection');` * * @return void */ public function initialize(): void { parent::initialize(); $this->loadComponent('RequestHandler'); $this->loadComponent('Flash'); $this->loadComponent('RestResponse'); $this->loadComponent('Security'); $this->loadComponent('ParamHandler', [ 'request' => $this->request ]); $this->loadComponent('CRUD', [ 'request' => $this->request, 'table' => $this->{$this->modelClass} ]); $this->loadComponent('Authentication.Authentication'); $this->loadComponent('ACL', [ 'request' => $this->request, 'Authentication' => $this->Authentication ]); if (Configure::read('debug')) { Configure::write('DebugKit.panels', ['DebugKit.Packages' => true]); Configure::write('DebugKit.forceEnable', true); } /* * Enable the following component for recommended CakePHP form protection settings. * see https://book.cakephp.org/4/en/controllers/components/form-protection.html */ //$this->loadComponent('FormProtection'); } public function beforeFilter(EventInterface $event) { $this->loadModel('Users'); $this->Users->checkForNewInstance(); $this->authApiUser(); $this->ACL->setPublicInterfaces(); if (!empty($this->request->getAttribute('identity'))) { $user = $this->Users->get($this->request->getAttribute('identity')->getIdentifier(), [ 'contain' => ['Roles', 'Individuals' => 'Organisations'] ]); if (!empty($user['disabled'])) { $this->Authentication->logout(); $this->Flash->error(__('The user account is disabled.')); return $this->redirect(['controller' => 'Users', 'action' => 'login']); } unset($user['password']); $this->ACL->setUser($user); $this->isAdmin = $user['role']['perm_admin']; } else if ($this->ParamHandler->isRest()) { throw new MethodNotAllowedException(__('Invalid user credentials.')); } $this->ACL->checkAccess(); $this->set('menu', $this->{$this->modelClass}->getMenu()); $this->set('ajax', $this->request->is('ajax')); $this->request->getParam('prefix'); } private function authApiUser(): void { if (!empty($_SERVER['HTTP_AUTHORIZATION']) && strlen($_SERVER['HTTP_AUTHORIZATION'])) { $this->loadModel('AuthKeys'); $authKey = $this->AuthKeys->find()->where([ 'authkey' => $_SERVER['HTTP_AUTHORIZATION'], 'OR' => [ 'valid_until' => 0, 'valid_until >' => time() ] ])->first(); if (!empty($authKey)) { $this->loadModel('Users'); $user = $this->Users->get($authKey['user_id']); if (!empty($user)) { $this->Authentication->setIdentity($user); } } } } public function generateUUID() { $uuid = Text::uuid(); return $this->RestResponse->viewData(['uuid' => $uuid], 'json'); } public function checkPermission($perm_flag) { return true; } public function queryACL() { $this->ACL->findMissingFunctionNames(); } }