我刚刚使用 LDAP,因此请告诉我我是否以完全错误的方式执行此操作。
我正在使用 bhLDAPAuthPlugin 插件使用 Symfony 1.4
我正在使用 LDAP 验证用户登录。但是,LDAP 表中有更多数据,我想使用用户名查询。所以我正在编写这个搜索函数来根据用户名过滤结果:
function user_values($username) {
if (!$username) {
die ("Username is not there man!");
}
if (!$this->_conn) {
die ("No Connection.");
}
if (!$this->_base_dn) {
die ("No Base.");
}
$filter="samaccountname=".$username;
$attributes_ad = array("name");
$result = ldap_search($this->_conn, $this->_base_dn, $filter, $attributes_ad)
or die ("Error in search query");
$entries = ldap_get_entries($this->_conn, $result);
return($entries);
}
我收到错误:
警告:ldap_search():搜索:/... 中的搜索过滤器错误 搜索查询错误
当我运行查询时。
前三个“如果”只是为了确保我获得正确的搜索参数。该条件在实际搜索中失败。
有什么建议么?
UPDATE
用户名变量是 jtesting
在将 $username 放入搜索参数之前,我从函数中提取了 $username 。它实际上是(jtesting)。我将删除括号,看看是否可以解决问题。
为了在过滤器的断言值中使用括号,必须对括号进行转义。断言值为的搜索过滤器samAccountName=(jtesting)
应编码为samAccountName=\28jtesting\29
。整个断言值可以括在未转义的括号中,在这种情况下,过滤器变为(samAccountName=\28jtesting\29)
.
更多信息
- LDAP:搜索过滤器 http://www.ldapguru.info/ldap/mastering-ldap-search-filters.html
- 搜索过滤器的字符串表示形式 https://www.rfc-editor.org/rfc/rfc4515#section-3
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)