我有一個外部Web服務器嘗試通過LDAP在內部服務器上對Active Directory進行驗證。我可以在本地進行連接和身份驗證,但使用相同的代碼(切換出主機和端口)無法對外進行身份驗證。我們有其他能夠連接和驗證的服務,如Attask(http://www.attask.com/)。PHP LDAP連接以從外部服務器對Active Directory進行驗證
外部服務器目前是運行PHP 5.3.15的Media Temple上啓用LDAP支持的Linux(gs)。
內部服務器當前是具有LDAP和Active Directory的Windows Server 2008框。
下面的代碼是我使用的當前PHP能夠在本地連接,但在外部服務器上有問題。它基本上使用PHP的LDAP連接字符串並嘗試綁定。如果失敗,它會嘗試匿名綁定。兩者都不能在外部工作並返回錯誤:無法聯繫LDAP服務器。
<?php
$username = 'username';
$password = 'password';
$ldapconfig['host'] = '00.000.000.000';
$ldapconfig['port'] = '636';
$ldapconfig['basedn'] = 'dc=client,dc=eqc,dc=local';
$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ds, LDAP_OPT_NETWORK_TIMEOUT, 10);
$dn="".$username."";
if ($bind=ldap_bind($ds, $dn, $password)) {
echo("Login correct");
} else {
echo("Unable to bind to server.</br>");
echo("msg:'".ldap_error($ds)."'</br>".ldap_errno($ds)."");
if ($bind=ldap_bind($ds)) {
$filter = "(cn=*)";
if (!([email protected]_search($ds, $ldapconfig['basedn'], $filter))) {
echo("Unable to search ldap server<br>");
echo("msg:'".ldap_error($ds)."'</br>");
} else {
$number_returned = ldap_count_entries($ds,$search);
$info = ldap_get_entries($ds, $search);
echo "The number of entries returned is ". $number_returned."<p>";
for ($i=0; $i<$info["count"]; $i++) {
var_dump($info[$i]);
}
}
} else {
echo("Unable to bind anonymously<br>");
echo("msg:".ldap_error($ds)."<br>");
}
}
?>
的幾個注意事項:
外部LDAP服務器使用LDAPS所以建議主機LDAPS://00.000.000.000端口636
我試着結合'username'以及'[email protected]'已經有
有防火牆,但是,外部服務器可以成功ping內部LDAP服務器所以在這個層面上有連接。
任何幫助將不勝感激。如果有服務器設置或這種性質的東西,很想知道。另外,我已經檢出了ADFS,但是無法找到一個簡單的腳本來設置測試,如果它沒有工作,沒有花很多時間到最後。
你有防火牆規則檢查? Ping(ICMP)與LDAP連接沒有實際關係(特別是,防火牆可能允許某些連接,但不一定通過端口636從外部服務器接收連接)。 – ig0774
考慮使用已知良好的客戶端ldapsearch來驗證客戶端是否可以連接到服務器。在執行指定代碼的相同主機上運行ldapsearch,並使用相同的參數。另請參閱[使用ldapsearch](http://ff1959.wordpress.com/2011/07/27/mastering-ldapsearch/)。 –