使用Microsoft Active Directory和Unboundid SDK,並且有> 29k成員的組。檢索大AD組的所有成員
我想利用範圍值來獲得所有的組,但不能確定何時達到了結束。
我使用這種方法:(已更新爲工作代碼)
public static List<String> getAttributeRangeBasedSearch(LDAPConnection ldc, String basedn, String filter, int step, String return_attribute) throws LDAPException
{
List<String> allValues = new ArrayList<String>();
// initialize counter to total the group members and range values
int allvalues = 0;
int start = 0;
// int step = 1000;
int finish = step - 1;
boolean finallyFinished = false;
String range;
// loop through the query until we have all the results
while (!finallyFinished)
{
range = start + "-" + finish;
String currentRange = return_attribute + ";Range=" + range;
String range_returnedAtts[] = { currentRange };
SearchRequest searchRequest = new SearchRequest(basedn, SearchScope.BASE, filter, range_returnedAtts);
List<SearchResultEntry> rangedEntries = ldc.search(searchRequest).getSearchEntries();
for (Iterator<SearchResultEntry> iterator = rangedEntries.iterator(); iterator.hasNext();)
{
SearchResultEntry searchResultEntry = iterator.next();
Collection<Attribute> allAttribute = searchResultEntry.getAttributes();
for (Iterator<Attribute> attributeIterator = allAttribute.iterator(); attributeIterator.hasNext();)
{
Attribute attribute = attributeIterator.next();
log.debug("---> " + allvalues + ": " + attribute.getName());
if (attribute.getName().endsWith("*"))
{
currentRange = attribute.getName();
finallyFinished = true;
}
String[] attributeBatch = searchResultEntry.getAttributeValues(currentRange);
for (int i = 0; i < attributeBatch.length; i++)
{
allValues.add(attributeBatch[i]);
log.debug("-- " + allvalues++ + " " + attribute.getName() + ":" + attributeBatch[i]);
}
}
}// for SearchResultEntry
start = start + step;
finish = finish + step;
}// finallyFinished
return allValues;
}
任何想法?
感謝 -Jim
AD,在默認情況下,只存儲最大每屬性5000個條目的;如果有更多的屬性被分成幾個「塊」 - 「member0-4999;」member5000-9999;'等。你可以將它們合併得到完整的列表嗎?或者,您可以執行分頁搜索,以詢問其memberOf屬性包含組的可分辨名稱的所有用戶,但與以前的方法相比,這會比較慢。 –
問題不是條目,而是由MaxValRange確定的值,對於每個屬性,該值爲1,500。我得到的所有結果,但當我要求的最後一組值,它是一個像member28131部分大小 - ?????到一些價值,我不知道是什麼。那麼如何告訴每個結果中範圍的返回值。謝謝-jim – jwilleke
實際上現在我記得分號恰好在屬性名稱後面,所以只需遍歷所有檢索到的屬性,在分號上分割它們的名稱並將任意相同名稱的屬性合併在一起。 –