CakePHP使用LDAP进行身份验证

时间:2013-10-23 19:20:37

标签: php cakephp authentication ldap cakephp-2.0

我在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文档和cookbook中,它指示我按照LdapAuthetnticate的方式设置它,使用一个authenticate函数扩展BaseAuthorise,该函数可以返回false对象,具体取决于用户是否登录。

有人能说出为什么会产生这个错误吗?

2 个答案:

答案 0 :(得分:0)

你扩展了一个抽象类 - 所以你必须提供自己的抽象方法实现 - 在这种情况下你必须实现:

authorize ( array $user , CakeRequest $request )

答案 1 :(得分:0)

正如ndm所说你正在推广BaseAuthorize,但你想要的是BaseAuthenticate

class LdapAuthenticate extends BaseAuthenticate
{

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