php - cakephp 2.0 中的 LdapAuth

标签 php cakephp cakephp-2.0

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

相关文章:

php - 从需要登录的网站上抓取?

php - 如何在cakephp2中运行普通的sql查询并获取结果

php - 当电子邮件和密码位于单独的表 cakephp 中时验证用户

php - 从 mysql 获取数据并以周为单位进行分组并显示日期

CakePHP - 如何实现密码的河豚散列?

php - 加密数据库

php - 通过url中的特定字段从MySQL数据库表中获取数据

php - CakePHP:在 View 和元素中嵌入 CTP 文件名和路径

cakephp - 在 CakePHP 2.0 中使用 SQLite3

javascript - 由于某种原因, document.getElementById().innerHTML 不起作用?