我尝试编写 LdapAuthentication 程序,但需要一些帮助。
首先我需要在/app/Controller/中配置“$components” 组件/AppController.php
<?php
class AppController extends Controller {
var $components = array('Auth' => array(
'Ldap',
'authError' => 'Not allowed here',
'authenticate' => array('Form' => array(
'fields' => array(
'username' => 'username',
'password' => 'password',
'domain' => 'domain'
)
)
),
'authorize' => true,
), 'Session');
}
?>
然后我创建一个 LdapAuthorize.php 像 http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#creating-custom-authorize-objects
<?php
App::uses('BaseAuthorize', 'Controller/Component/Auth');
class LdapAuthorize extends BaseAuthorize {
public function authorize($user, CakeRequest $request) {
echo "test";
}
}
?>
但是当我尝试登录时
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Username or password is incorrect'),
'default', array(), 'auth');
}
cakephp 不使用我的授权功能。
我做错了什么?请帮忙。
最佳答案
这是 2.0.x 的有效 Ldap Auth 类
https://github.com/analogrithems/idbroker/tree/dev_cake2.0
这里有一篇详细介绍的博客文章:
http://www.analogrithems.com/rant/2012/01/03/cakephp-2-0-ldapauth/
** 还有 **
您的身份验证配置错误 - 授权 key 采用字符串或数组 - bool 值 true 不会执行任何操作。
如果您希望它检查 Controller 中的 isAuthorized 操作 - 如下设置:
<?php
...
public $components = array( 'Auth' => array(
...
'authorize' => array( 'Controller' ),
...
));
?>
您在此处传递一个 bool 参数,并且 AppController 中没有 isAuthorized 函数。另外,您正在使用旧的 php4 语法来声明成员变量(使用 public、protected 或 private 而不是“var”)
关于php - cakephp 2.0 中的 LdapAuth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9903787/