CakePHP 2.x自定义“身份验证适配器"和"LdapAuthorize&"没有找到 [英] CakePHP 2.x custom "Authentication adapter "LdapAuthorize" was not found
问题描述
我正在使用CakePHP构建应用程序,并尝试合并自定义身份验证对象,但似乎无法找到它.尝试登录时出现以下错误:未找到身份验证适配器"LdapAuthorize".我已经使用用于身份验证的代码创建了文件app/Controller/Component/Auth/LdapAuthorize.php.在"AppController.php"顶部附近
I'm building an application using CakePHP and trying to incorporate a custom authentication object but it does not seem to be able to find it. I get the following error when I try to log in: "Authentication adapter "LdapAuthorize" was not found". I have created the file app/Controller/Component/Auth/LdapAuthorize.php with my code for my authentication. Near the top of "AppController.php" I have
App::uses('LdapAuthroize', 'Controller/Component/Auth/LdapAuthorize');
在我拥有的AppController类中
and within the AppController class I have
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'pendings', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authorize' => array('Controller'),
'authenticate' => array('LdapAuthorize')
)
);
,然后在我的UsersController.php中,具有以下登录功能.
and then in my UsersController.php I have the following login function.
public function login() {
if($this->request->is('post')) {
if($this->Auth->login()) {
// My Login stuff...
}
else
$this->redirect(array('controller'=>'someController', 'action'=>'someAction'));
}
}
如果有人知道为什么它似乎无法加载很棒的我的自定义身份验证对象.谢谢!
If anyone has any idea why it can't seem to load my custom authentication object that would be awesome. Thanks!
推荐答案
我将自定义身份验证类放在 Controller/Component/Auth 中.例如,我的班级的名称是 CustomUserAuthenticate ,文件的路径是
I put my custom authentication class inside Controller/Component/Auth. For example, the name of my class is CustomUserAuthenticate and the path to the file is,
控制器/组件/Auth/CustomUserAuthenticate.php.
然后在我的 AppController 中,将以下内容添加到 authenticate
数组
Then in my AppController I added the following to the authenticate
array,
class AppController extends Controller {
public $components = array(
'Auth' => array(
/** Any other configuration like redirects can go here */
'authenticate' => array(
'CustomUser'
)
)
);
}
除了 Authenticate 字以外, authenticate
数组中的字符串必须与类的名称匹配.
The string in the authenticate
array must match the name of the class except for the Authenticate word.
我的 CustomUserAuthenticate 类扩展了CakePHP的 Controller/Component/Auth/BaseAuthenticate ,并覆盖了 authenticate
方法.CakePHP的文档指出,这不是必填.我没有那样尝试.
My CustomUserAuthenticate class extends CakePHP's Controller/Component/Auth/BaseAuthenticate and overrides the authenticate
method. CakePHP's documentation states that this is not required. I haven't tried that way.
这篇关于CakePHP 2.x自定义“身份验证适配器"和"LdapAuthorize&"没有找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!