caradrye
caradrye

Reputation: 497

Authorization adapter "Controller)" was not found. in cakephp

I am adding the login/logout ability to my cakephp project and when I log in or out I get the following error:

Error: Authorization adapter "Controller)" was not found. Error: An Internal Error Has Occurred.

Stack Trace CORE\Cake\Controller\Component\AuthComponent.php line 376 → AuthComponent->constructAuthorize() CORE\Cake\Controller\Component\AuthComponent.php line 326 → AuthComponent->isAuthorized(array) [internal function] → AuthComponent->startup(UsersController) CORE\Cake\Utility\ObjectCollection.php line 130 → call_user_func_array(array, array) [internal function] → ObjectCollection->trigger(CakeEvent) CORE\Cake\Event\CakeEventManager.php line 246 → call_user_func(array, CakeEvent) CORE\Cake\Controller\Controller.php line 671 → CakeEventManager->dispatch(CakeEvent) CORE\Cake\Routing\Dispatcher.php line 183 → Controller->startupProcess() CORE\Cake\Routing\Dispatcher.php line 161 → Dispatcher->_invoke(UsersController, CakeRequest, CakeResponse) APP\webroot\index.php line 92 → Dispatcher->dispatch(CakeRequest, CakeResponse)

Here is my AppController.php

class AppController extends Controller {
    public $components = array(
        'Session',
        'Auth'=>array(
            'loginRedirect'=> array('controller'=>'users', 'action'=>'index'),
            'logoutRedirect'=> array('controller'=>'users', 'action'=>'index'),
            'authError' =>"You can't access that page",
            'authorize'=> array('Controller)')
        )

    );
    //determines what logged in users have access to
    public function isAuthorized($user){
        return true;
    }
    //determines what non-logged in users have access to
    public function beforeFilter(){
        $this->Auth->allow('index','view');
        $this->set('logged_in', $this->Auth->loggedIn());
        $this->set('current_user', $this->Auth->user());
    }


}

Here is my UsersController.php

class UsersController extends AppController {
    public $name = 'Users';

    public function beforeFilter(){
        parent::beforeFilter();
        $this->Auth->allow('add');
    }

    public function login(){
        if($this->request->is('post')){
            if($this->Auth->login()){
                $this->redirect($this->Auth->redirect());

            }else{
                $this->Session->setFlash('Your username and/or password is incorrect');
            }
        }
    }

    public function logout(){
        $this->redirect($this->Auth->logoutRedirect());
    }

I noticed a couple similar posts with their same error, but issues involved being a a Linux machine where I am on windows, or calling a function that I am not calling.

Upvotes: 0

Views: 2344

Answers (1)

nappo
nappo

Reputation: 594

You made a mistake in your $components['Auth'] array. You wrote 'Controller)' instead of 'Controller' (the error message tells you). Here's the corrected $components:

public $components = array(
    'Session',
    'Auth'=>array(
        'loginRedirect'=> array('controller'=>'users', 'action'=>'index'),
        'logoutRedirect'=> array('controller'=>'users', 'action'=>'index'),
        'authError' => "You can't access that page",
        'authorize'=> array('Controller')
    )

);

Upvotes: 4

Related Questions