我正在使用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] => Array ( [Controller.initialize] => beforeFilter ) [_config] => Array ( [roleField] => role_id [Authorizer] = > 数组 ( [roleField] => role_id ) ) )
而且我认为 Authorizer 组件正在运行beforeFilter
而不是isAuthorized
. 难道我做错了什么 ?