2013-01-08 60 views
0

我有一個外部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,但是無法找到一個簡單的腳本來設置測試,如果它沒有工作,沒有花很多時間到最後。

+1

你有防火牆規則檢查? Ping(ICMP)與LDAP連接沒有實際關係(特別是,防火牆可能允許某些連接,但不一定通過端口636從外部服務器接收連接)。 – ig0774

+0

考慮使用已知良好的客戶端ldapsearch來驗證客戶端是否可以連接到服務器。在執行指定代碼的相同主機上運行ldapsearch,並使用相同的參數。另請參閱[使用ldapsearch](http://ff1959.wordpress.com/2011/07/27/mastering-ldapsearch/)。 –

回答

1

當連接到使用LDAPS從Linux箱AD,我總是不得不添加行

TLS_REQCERT never 

在/etc/ldap.conf中用或同等學歷(可能需要一個Apache重新啓動 - 不當然)。您也可以嘗試主機的格式「ldaps://server.domain.tld:636」,但我不認爲這是問題。

我在http://en.gentoo-wiki.com/wiki/Active_Directory_Authentication_using_LDAP找到了一些不錯的文檔,雖然現在看起來很糟糕。谷歌的緩存版本:http://webcache.googleusercontent.com/search?q=cache:http://en.gentoo-wiki.com/wiki/Active_Directory_Authentication_using_LDAP

+0

感謝您的回答,dearbry。我使用的外部Linux服務器是不允許訪問ldap.conf文件的網格服務。我已經通讀了你建議的鏈接,並且設置了一個專門的盒子來嘗試TLS_REQCERT從來沒有。如果這有效,我會告訴你。 :) –

+0

就是這樣,它也將cn加入到basedn中。非常感謝! –

+0

沒問題 - 很高興它的工作! – dearlbry

0

您是否檢查過它是否爲SSL證書錯誤?你正在使用自簽名證書還是正式證書?

「如果您使用的是SSL(例如ldaps)並且ldap_bind正在拋出'Unable to bind to server:'錯誤,請檢查ldap_connect中使用的主機名是否與LDAP服務器上的SSL證書中的'CN'匹配「Source

+0

感謝您的評論。內部服務器上的SSL證書是正式且正常工作的,因此如上所述,目前與Attask一起使用的連接和驗證。我甚至不知道除了端口之外還有什麼區別LDAPS和LDAP,並且可能在主機IP前面添加LDAPS://。 –

相關問題