我使用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
。我做错了吗?