【发布时间】:2015-09-15 23:57:57
【问题描述】:
我正在将 LDAP 身份验证集成到我的项目中。我按照 CakePHP 官方网站上的教程指导如何在应用程序 src 路径中创建自定义对象并在 AuthController 中使用这些自定义对象。
所以我在 src 中创建了一个名为 Auth 的文件夹,文件名为 LdapAuthorize.php。路径看起来像这样 src/Auth/LdapAuthorize.php
这是我的 LdapAuthorize.php 代码:
namespace App\Auth;
use Cake\Auth\BaseAuthorize;
use Cake\Network\Request;
class LdapAuthorize extends BaseAuthorize {
public function authorize($user, Request $request) {
if ($user == 'username') { // where username is logged on ldap user on a computer.
return true;
}
}
}
我还调用了 AppController.php 文件中的对象。这是我的代码:
public function initialize()
{
parent::initialize();
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'loginRedirect' => [
'controller' => 'Customers',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Pages',
'action' => 'display',
'home'
]
]);
$this->Auth->config('authenticate', [
'Ldap'
]);
}
所以当我访问网址http://localhost/AppPath/Dashboard/index 时,我得到Authentication adapter "Ldap" was not found.
由于这是我第一次使用 CakePHP,我无法在网上找到那么多有助于解决任何问题的解决方案。
为 LdapAuthenticate.php 添加附加代码:
namespace App\Auth;
use Cake\Auth\BaseAuthenticate;
use Cake\Network\Request;
use Cake\Network\Response;
class OpenidAuthenticate extends BaseAuthenticate
{
public function authenticate(Request $request, Response $response)
{
$users = ["john", "ray"];
return $users;
}
}
【问题讨论】:
标签: php cakephp authentication cakephp-3.0