【发布时间】:2017-03-25 03:12:13
【问题描述】:
我在这里使用在线 LDAP 测试服务器:http://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/ 来测试一些基本的 LDAP 代码。
我需要对用户进行身份验证并检索一些用户信息。
如果我正确理解了有关测试服务器的信息,我应该能够与属于各个组的用户绑定。使用下面的代码“AS IS”,我可以绑定到未注释的 $dn,但如果我使用任何其他 $dn 进行身份验证,则绑定失败。
我不明白什么?
例如,tesla 应该属于 'ou=scientists,dc=example,dc=com' 但我无法在该 DN 上对 tesla 进行身份验证,因此我无法搜索相关信息。
$dn = 'dc=example,dc=com';
// $dn = 'ou=mathematicians,dc=example,dc=com';
// $dn = 'ou=scientists,dc=example,dc=com';
$username = 'tesla';
$password = 'password';
$filter = "(uid=" . $username . ")";
$ldapDN = 'uid=' . $username . ',' . $dn;
$ldapCONN = ldap_connect("ldap.forumsys.com") or die("Could not connect to LDAP server.");
if ($ldapCONN)
{
ldap_set_option($ldapCONN, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldapBIND = @ldap_bind($ldapCONN, $ldapDN, $password);
if ( $ldapBIND )
{
$result = ldap_search($ldapCONN, $dn, $filter) or die ("Error: ".ldap_error($ldapCONN));
$data = ldap_get_entries($ldapCONN, $result);
echo '<pre>';
print_r($data);
echo '</pre>';
}
else
{
echo "LDAP bind failed...";
}
}
【问题讨论】:
标签: php authentication active-directory ldap