【问题标题】:LdapAuth in cakephp 2.0cakephp 2.0 中的 LdapAuth
【发布时间】:2012-03-28 08:30:25
【问题描述】:

我尝试编写一个 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 没有使用我的授权功能。

我做错了什么?请帮忙。

【问题讨论】:

    标签: php cakephp cakephp-2.0


    【解决方案1】:

    这是一个适用于 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/

    ** 还有 **

    您的身份验证配置错误 - 授权密钥采用字符串或数组 - 布尔值 true 不会执行任何操作。

    如果您希望它检查控制器中的 isAuthorized 操作 - 像这样设置它:

    <?php
        ...
        public $components = array( 'Auth' => array(
            ...
            'authorize' => array( 'Controller' ),
            ...
        ));
    ?>
    

    您在这里传递了一个布尔参数,并且您的 AppController 中没有 isAuthorized 函数。此外,您正在使用旧的 php4 语法来声明您的成员变量(使用 public、protected 或 private 而不是“var”)

    【讨论】:

    • 您为什么改变主意,认为这是一个可以接受的答案? Auth 类有效,我对您的配置的注释是 100% 准确的。
    • 第二个链接不起作用。 Link
    猜你喜欢
    • 1970-01-01
    • 2019-01-16
    • 2012-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多