2012-03-28 66 views
2

我嘗試編程一個LdapAuthentication,我需要一些幫助。在cakephp 2.0中的LdapAuth

首先我需要配置 「$組件」 在/ app /控制器/ 組件/ 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'); 
        } 
         ?> 

然後,我創建像 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"; 
       } 
       } 

       ?> 

一個LdapAuthorize.php但當我嘗試登錄

  if ($this->Auth->login()) { 
      return $this->redirect($this->Auth->redirect()); 
      } else { 
       $this->Session->setFlash(__('Username or password is incorrect'), 
      'default', array(), 'auth'); 
       } 

cakephp不使用我的授權功能。

我做錯了什麼?請幫忙。

回答

3

這裏是一個工作的Ldap驗證類的2.0.x

https://github.com/analogrithems/idbroker/tree/dev_cake2.0

在這裏博客文章詳細介紹吧:

http://www.analogrithems.com/rant/2012/01/03/cakephp-2-0-ldapauth/

** ** ALSO

您的身份驗證配置不正確 - 授權密鑰需要一個字符串或數組 - 布爾值true不會執行任何操作。

如果你想它來檢查控制器的isAuthorized動作 - 設置它像這樣:

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

您在這裏傳遞一個布爾參數,並在你的AppController沒有isAuthorized功能。此外,您正在使用舊的php4語法來聲明您的成員變量(使用public,protected或private而不是「var」)

+0

爲什麼您改變主意瞭解這是一個可以接受的答案? Auth類的工作原理和我關於你的配置的說明是100%準確的。 – 2012-07-18 15:51:24

+0

Seconde鏈接不起作用。 [鏈接](http://www.analogrithems.com/rant/cakephp-2-0-ldapauth/) – 2017-12-11 14:04:01