授权人没有执行isAuthozed方法

时间:2016-05-22 11:36:37

标签: cakephp authorization cakephp-3.2

我使用Cakemanager Authorizer,但注意Authorizer未运行isAuthorized()方法。我的配置如下:

$this->loadComponent('Auth', [
        'authenticate' => [
            'Form' => [
                'fields' => ['username' => 'email', 'password' => 'password']
            ],
            'ADmad/HybridAuth.HybridAuth'
        ],
        'loginRedirect' => [
            'plugin' => FALSE,
            'controller' => 'Pages',
            'action' => 'display',
            'home'
        ],
        'logoutRedirect' => [
            'controller' => 'Pages',
            'action' => 'display',
            'home'
        ],
        'authorize' => 'Controller'

    ]);
    $this->loadComponent('Utils.Authorizer');

isAuthorized中的PagesController方法:

public function isAuthorized($user)
{

    $this->Authorizer->action(['display', 'contact', 'about', 'tips', 'terms'], function($auth) {
        $auth->allowRole(['*']);
    });

    return $this->Authorizer->authorize();
}

但是当访问任何列出的操作时,我被重定向到登录页面。我试试这个\Cake\Log\Log::info($this->Authorizer);并得到以下日志输出:

  

Utils \ Controller \ Component \ AuthorizerComponent对象([components] => Array()[implementedEvents] =>数组([Controller.initialize] => beforeFilter)[_ config] =>数组([roleField] => role_id [Authorizer] =>数组([roleField] => role_id)))

我认为授权组件正在运行beforeFilter而不是isAuthorized。我做错了吗?

0 个答案:

没有答案
相关问题