简体   繁体   English

PHP LDAP连接可从外部服务器对Active Directory进行身份验证

[英]PHP LDAP Connection to Authenticate against Active Directory from External Server

I have an external web server trying to authenticate against Active Directory on an internal server via LDAP. 我有一个外部Web服务器试图通过LDAP对内部服务器上的Active Directory进行身份验证。 I am able to connect and authenticate locally, though using the same code (switching out host and port) am not able to authenticate externally. 我可以在本地进行连接和身份验证,尽管使用相同的代码(切换主机和端口)无法在外部进行身份验证。 We have other services that are able to connect and authenticate such as Attask (http://www.attask.com/). 我们还有其他能够连接和认证的服务,例如Attask(http://www.attask.com/)。

The external server is currently a Linux (gs) on Media Temple running PHP 5.3.15 with LDAP support enabled. 外部服务器当前是Media Temple上的Linux(gs),运行PHP 5.3.15,并且已启用LDAP支持。

The internal server is currently a Windows Server 2008 box with LDAP and Active Directory. 内部服务器当前是带有LDAP和Active Directory的Windows Server 2008。

The code below is the current PHP I am using that was able to connect locally, but having problems on the external server. 下面的代码是我正在使用的当前PHP,该PHP能够在本地连接,但是在外部服务器上有问题。 It basically uses the PHP LDAP connection string and tries to bind. 它基本上使用PHP LDAP连接字符串并尝试进行绑定。 If it fails, it tries to bind anonymously. 如果失败,它将尝试匿名绑定。 Both of which aren't working externally and returns the error: Can't contact LDAP server. 两者都无法在外部工作,并返回错误:无法联系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 (!($search=@ldap_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>");
  }
}
?>

A few notes: 一些注意事项:

  • The external LDAP server is using LDAPS so the suggested host is ldaps://00.000.000.000 on port 636 外部LDAP服务器正在使用LDAPS,因此建议的主机在端口636上为ldaps://00.000.000.000

  • I've tried binding with 'username' as well as 'username@00.000.000.000' already 我已经尝试与“用户名”以及“用户名@ 00.000.000.000”绑定

  • There is a firewall, however, the external server can successfully ping the internal LDAP server so there is connection taking place on that level. 有一个防火墙,但是,外部服务器可以成功ping通内部LDAP服务器,因此在该级别上进行连接。

Any help would be greatly appreciated. 任何帮助将不胜感激。 If there are server settings or things of that nature, would love to know. 如果有服务器设置或类似性质的事情,不妨了解一下。 Also, I've checked out ADFS though could not find a simple script to setup to test without spending a lot time to no end if it didn't work. 另外,我已经检查了ADFS,虽然找不到一个简单的脚本来进行测试,但是如果不起作用,则会花费大量时间无休止地进行测试。

When connecting to AD using LDAPS from a Linux box, I've always had to add the line 从Linux机器使用LDAPS连接到AD时,我总是不得不添加该行

TLS_REQCERT never

in /etc/ldap.conf or equivalent (might require an apache restart - not sure). 在/etc/ldap.conf或等效文件中(可能需要重新启动apache-不确定)。 You can also try the format "ldaps://server.domain.tld:636" for the host, though I don't think that's the issue. 您也可以为主机尝试格式“ ldaps://server.domain.tld:636”,尽管我认为这不是问题。

I found some decent documentation at http://en.gentoo-wiki.com/wiki/Active_Directory_Authentication_using_LDAP , though it appears to be down at the moment. 我在http://en.gentoo-wiki.com/wiki/Active_Directory_Authentication_using_LDAP中找到了一些不错的文档,尽管目前看来该文档已经不存在了。 Google's cached version: http://webcache.googleusercontent.com/search?q=cache:http://en.gentoo-wiki.com/wiki/Active_Directory_Authentication_using_LDAP Google的缓存版本: http : //webcache.googleusercontent.com/search? q=cache: http : //en.gentoo-wiki.com/wiki/Active_Directory_Authentication_using_LDAP

Have you checked if it is an SSL certificate error? 您是否检查过SSL证书错误? Are you using a self signed cert or an official one? 您使用的是自签名证书还是正式证书?

"If you're using SSL (eg ldaps) and ldap_bind is throwing 'Unable to bind to server:' errors, check that the hostname used in the ldap_connect matches the 'CN' in the SSL certificate on the LDAP server" Source “如果你正在使用SSL(如LDAPS)和的ldap_bind抛出‘无法绑定到服务器:’错误,请检查在ldap_connect使用的主机名的SSL证书中相匹配的‘CN’的LDAP服务器” 来源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用php ldap对活动目录进行身份验证时收到错误 - getting error when authenticate against active directory with php ldap 在使用IE / Firefox时使用PHP,活动目录对ldap进行身份验证 - Authenticate against ldap using PHP, active directory, while using IE/Firefox PHP-针对Windows 2003 Active Directory的LDAP身份验证(用户名不同于名字和姓氏) - PHP - LDAP authentication against Windows 2003 Active Directory (User ID different from First Name and Last Name) 无法通过 SSL 在 php 中针对 Active Directory LDAP 进行绑定? - Can't bind in php against Active Directory LDAP over SSL? 如何使用php和CodeIgniter对Active Directory进行身份验证? - How do I authenticate against Active Directory using php and CodeIgniter? PHP / ldap_bind Active Directory无法对OU进行身份验证,但可以使用默认用户组进行身份验证 - PHP/ldap_bind Active Directory can't authenticate OU, but can authenticate with default user group 使用SSL验证LDAP / Active Directory登录 - Using SSL to Authenticate LDAP/Active Directory Login 使用 Azure Active Directory 连接对 PHP 应用程序进行身份验证 - Authenticate a PHP application using Azure Active Directory connection 从IE抓取用户名,以针对LDAP进行身份验证 - Grab username from IE, to authenticate against LDAP ldap活动目录PHP过滤器 - ldap active directory PHP filter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM