【问题标题】:CakePHP Authenticate with LDAPCakePHP 使用 LDAP 进行身份验证
【发布时间】:2013-10-24 13:58:05
【问题描述】:

我在 CakePHP 中扩展了 BaseAuthorise 并创建了一个名为 LdapAuthenticate 的新类,它位于我的 /app/Controller/Component/Auth/LdapAuthenticate 中,目前看起来像这样

<?php

App::uses('BaseAuthorize', 'Controller/Component/Auth');

class LdapAuthenticate extends BaseAuthorize {
    public function authenticate(CakeRequest $request, CakeResponse $response) {
        // Do things for ldap here.

        echo "Running...";

    }
}

在我的 AppControl 中

public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home'),
            'authenticate' => array('Ldap')
        )
    );

然后在我的登录方法中,我有

public function login() {
    if ($this->request->is('post')) {

        $this->Auth->authorize();

    }
}

但是我得到了错误

Error: Class LdapAuthenticate contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (BaseAuthorize::authorize)  

但是在 CakePHP 文档和说明书中,它指示我设置它的方式,我让 LdapAuthetnticate 扩展 BaseAuthorise 并带有一个用于身份验证的函数,该函数可以根据用户是否登录返回一个 false 对象。

谁能指出为什么会产生这个错误?

【问题讨论】:

标签: php cakephp authentication ldap cakephp-2.0


【解决方案1】:

您已经扩展了一个抽象类 - 因此您必须提供自己的抽象方法实现 - 在这种情况下您必须实现:

authorize ( array $user , CakeRequest $request )

【讨论】:

    【解决方案2】:

    正如 ndm 所说,您正在扩展 BaseAuthorize,但您想要的是 BaseAuthenticate

    class LdapAuthenticate extends BaseAuthenticate
    {
    
        public function authenticate(CakeRequest $request, CakeResponse $response)
        {
            // ....
            return $userData;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-28
      • 2015-10-03
      • 2014-03-08
      • 2014-08-09
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多