gpt4 book ai didi

php - cakephp 2.0 中的 LdapAuth

转载 作者:行者123 更新时间:2023-12-04 05:52:36 25 4
gpt4 key购买 nike

我尝试对 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/

** 还 **

您的 Auth 配置错误 - 授权键采用字符串或数组 - 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com