我正在尝试将我的php代码移至adldap2,因为它应该更简单,但是在分组搜索用户时遇到了问题。基本上,我要完成的工作是...如果用户在组中,请进行身份验证。
我已经将代码分解为试图在AD中搜索用户,但是由于某种原因,它返回了
object(Adldap \ Query \ Collection)#17(1){[“ items”:protected] => array(0){}}
<?php
include "includes/functions.inc.php";
require __DIR__ . '/vendor/autoload.php';
$ad = new \Adldap\Adldap();
// Create a configuration array.
$config = [
// An array of your LDAP hosts. You can use either
// the host name or the IP address of your host.
'hosts' => ['ad.test.local'],
// The base distinguished name of your domain to perform searches upon.
'base_dn' => 'dc=test,dc=local',
// The account to use for querying / modifying LDAP records. This
// does not need to be an admin account. This can also
// be a full distinguished name of the user account.
'username' => 'USERNAME',
'password' => 'PASSWORD',
];
$ad->addProvider($config);
try {
// If a successful connection is made to your server, the provider will be returned.
$provider = $ad->connect();
$search = $provider->search();
$query = $provider->search()->newQuery();
$results = $query->andFilter(function (Adldap\Query\Builder $q) {
$q->where('samaccountname', '=', 'USER')
->where('memberof', '=', 'testgroup');
})->get();
var_dump($results);
} catch (\Adldap\Auth\BindException $e) {
echo "Issue with LDAP";
}
?>