我正在尝试使用range属性.
为了测试,我使用没有范围的搜索返回3个条目,并且我将范围设置为0-1,这应该仅返回前2个.但是,我得到所有3个结果.
我是这样做的:
String rangeStr = attribute + ";range=0-1";
String returnedAttrs[] = {rangeStr, attribute};
_searchControls.setReturningAttributes(returnedAttrs);
_searchControls.setSearchScope(scope);
NamingEnumeration<SearchResult> answer = _context.search(name, filter, _searchControls);
List<String> result = new LinkedList<String>();
while (answer != null && answer.hasMoreElements())
{
Attribute currentAttr = answer.next().getAttributes().get(attribute);
if (currentAttr == null)
continue;
for (int i=0; i<currentAttr.size(); i++)
{
String val = currentAttr.get(i).toString();
result.add(val);
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我使用的页面大小为1000,但如果我理解正确,那么不应该影响远程搜索(假设页面大小大于请求的范围).那是对的吗?
#!/usr/bin/env python
import ldap
def msad_flatten_ranges(conn, dn, ldap_dict):
for attrname in ldap_dict:
if ';range=' in attrname:
#
# parse range attr
#
actual_attrname, range_stmt = attrname.split(';')
bound_lower, bound_upper = [
int(x) for x in range_stmt.split('=')[1].split('-')
]
step = bound_upper - bound_lower + 1
while True:
attr_next = '%s;range=%d-%d' % (
actual_attrname, bound_lower, bound_upper
)
dn, attrs = conn.search_s(
dn, ldap.SCOPE_BASE, attrlist = [attr_next])[0]
assert len(attrs) == 1
ret_attrname = attrs.keys()[0]
ldap_dict[actual_attrname].extend(attrs[ret_attrname])
if ret_attrname.endswith('-*'):
break
bound_lower = bound_upper + 1
bound_upper += step
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2415 次 |
| 最近记录: |