Php adLDAP错误 - 无法绑定到服务器:需要强(er)身份验证
我试图使用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
。
我已成功查询此域控制器使用DsQuery
和PowerShell 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
这个答案是关于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
。
Ldap绑定是使用rdn not用户名完成的,尽管服务器可以配置为接受用户名。并检查你的协议版本,有些将需要设置为版本3 – frz3993
@ frz3993请原谅我的新手,这将是一个示例RDN?像'Doman \ username'? –
更像是DN的组件,如'uid = 12345,ou = people'。某些服务器允许域\用户名。但我不认为这是问题 – frz3993