2017-04-15 96 views
7

我試圖使用PHP adLDAP version 4.04在公司網絡上進行身份驗證,但沒有成功。Php adLDAP錯誤 - 無法綁定到服務器:需要強(er)身份驗證

PHP Version 5.2.4

我想這個計算器張貼PHP ldap - Strong(er) authentication required,沒有運氣。

我是不是該域控制器上的管理員;我只需要能夠查詢。

我能ping通HOSTNAMEOFDC.domain.location.company.com(我的域控制器的FQDN)

域控制器是Windows Server 2012 R2 Standard

我已成功查詢此域控制器使用DsQueryPowerShell AD Module,沒有問題,也沒有必須手動輸入的身份驗證。

我的代碼:

<?php 
require_once("includes/php/adLDAP/src/adLDAP.php"); 
$username = "domain\\username"; // also tried just "username" 
$password = "somepassword"; 

// All possible settings are listed in this array 
$options = array(
     "account_suffix" => "@domain.location.company.com", 
//  "admin_username" => $username, 
//  "admin_password" => $password, 
//  "ad_port" => "636", 
//  "base_dn" => "DC=domain,DC=location,DC=company,DC=com", 
     "domain_controllers" => array("HOSTNAMEOFDC.domain.location.company.com"), 
//  "real_primarygroup" => "", 
//  "recursive_groups" => "", 
//  "use_ssl" => true 
//  "use_tls" => true 
); 

$adldap = new adLDAP($options); 


// $authUser = $adldap->user()->authenticate($username, $password); 
$authUser = $adldap->user()->authenticate($username,$password); 
if ($authUser) { 
    echo "User authenticated successfully"; 
} else { 
    // getLastError is not needed, but may be helpful for finding out why: 
    echo $adldap->getLastError() . "<br>"; 
    echo "User authentication unsuccessful"; 
} 

// Destroy 
$adldap->close(); 
$adldap->__destruct(); 
?> 

我得到的錯誤:

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Strong(er) authentication required in C:\xampp\htdocs\Workspace\Project\scripts\includes\php\adLDAP\src\adLDAP.php on line 712 
Strong(er) authentication required 
User authentication unsuccessful 

後來,當我取消"use_ssl" => true"我得到這個錯誤:

僅供參考,ssl在我php.ini

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in C:\xampp\htdocs\Workspace\Project\scripts\includes\php\adLDAP\src\adLDAP.php on line 712 
Can't contact LDAP server 
User authentication unsuccessful 

我也試過在取消"use_tls" => true",我得到這個錯誤:

Warning: ldap_start_tls() [function.ldap-start-tls]: Unable to start TLS: Connect error in C:\xampp\htdocs\Workspace\Project\scripts\includes\php\adLDAP\src\adLDAP.php on line 638 

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in C:\xampp\htdocs\Workspace\Project\scripts\includes\php\adLDAP\src\adLDAP.php on line 712 
Can't contact LDAP server 
User authentication unsuccessful 
+0

Ldap綁定是使用rdn not用戶名完成的,儘管服務器可以配置爲接受用戶名。並檢查你的協議版本,有些將需要設置爲版本3 – frz3993

+0

@ frz3993請原諒我的新手,這將是一個示例RDN?像'Doman \ username'? –

+0

更像是DN的組件,如'uid = 12345,ou = people'。某些服務器允許域\用戶名。但我不認爲這是問題 – frz3993

回答

4

這個答案是關於PHP 5.2 -5.3,這個bug已被固定在(可能)新版本

煩人的是,當PHP回吐錯誤無法綁定到服務器:需要強(er)認證 - 它實際上告訴你它需要一個證書或一組證書在本地計算機上並有一個.conf fi le指向他們。

我創建了一個目錄:C:\openldap\sysconf(它以前不存在)。

C:\openldap\sysconf

作出的文件ldap.conf在* nix中,你可能會把它放進/etc或子目錄在那裏,但我沒有測試過呢。

我去了,找到我們的證書的PEM文件,並將其提取到目錄中(PEM文件基本上是一個文件中的整個證書鏈)。

ldap.conf我加了一行:TLS_CACERT C:\openldap\sysconf\Certs.pem

如果你不能得到的PEM證書,您可以使用TLS_REQCERT never來代替。 這樣做時要小心。通過這樣做,你可以將自己暴露給中間人的攻擊。它不會驗證端點。

一旦我這樣做,我成功綁定。

如果這不起作用,請嘗試將ldap.conf放入C:\(根級別);它似乎取決於您使用的PHP版本 - 它決定在不同的地方查找ldap.conf

相關問題