用于区分名称的 ldap 过滤器

ldap filter for distinguishedName(用于区分名称的 ldap 过滤器)
本文介绍了用于区分名称的 ldap 过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码成功地在我们的 Active Directory 中查询用户:

I am successfully querying our Active Directory for a user with the following code:

$filter = (&(objectCategory=person)(samaccountname=someusername));
$fields = array("samaccountname","mail","manager","department","displayname","objectGUID");

$user = ldap_search($ldapconnection, $baseDn, $filter, $fields);

生成的数组为 manager 属性提供此值:

The resulting array gives this value for the manager attribute:

CN=McBossy, Boss,OU=Users,OU=CentralOffice,DC=ds,DC=example,DC=com

对我来说,这看起来像是一个杰出的名字.但是当我尝试查询经理的记录时,

This looks like a distinguishedName to me. But when I try to query for the manager's record,

$filter = (&(objectCategory=person)(dn='CN=McBossy, Boss,OU=Users,OU=CentralOffice,DC=ds,DC=example,DC=com'));

$manager = ldap_search($ldapconnection, $baseDn, $filter, $fields);

查询失败,PHP 警告:ldap_search(): Search: Bad search filter

我尝试了多种可能性,包括不同的引用、更多的括号、使用 distinguishedName 而不是 dn 等.

I've tried a number of possibilities including different quotation, more parentheses, using distinguishedName rather than dn, etc.

我做错了什么,获取经理记录的正确方法是什么?

What am I doing wrong and what is the right way to get the manager's record?

推荐答案

dn 不是属性.过滤器中只能使用属性类型、OID 和名称.

dn is not an attribute. Only attribute types, OIDs, and names can be used in filters.

当您获得 manager 属性时,要获得作为经理的 DN 的属性,请使用 manager 属性的值作为搜索中的基本对象要求.将搜索范围设置为 BASE,将过滤器设置为 (&)(objectClass=*) 并请求所需的属性.然后将搜索请求传输到服务器并解释响应.

When you get the manager attribute, to get the attributes for the DN that is the manager, use the value of the manager attribute as the base object in a search request. Set the scope of the search to BASE, the filter to either (&) or (objectClass=*) and request the attributes required. Then transmit the search request to the server and interpret the response.

这篇关于用于区分名称的 ldap 过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)