簡體   English   中英

CakePHP使用LDAP進行身份驗證

[英]CakePHP Authenticate with LDAP

我在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對象,具體取決於用戶是否登錄。

有人可以建議為什么會產生此錯誤嗎?

您已經擴展了抽象類-因此您必須提供自己的抽象方法實現-在這種情況下,您必須實現:

authorize ( array $user , CakeRequest $request )

正如ndm所說,您正在擴展BaseAuthorize但您想要的是BaseAuthenticate

class LdapAuthenticate extends BaseAuthenticate
{

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM