Fetching all the values (>1000 ) of a multi-value attribute in ADS
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   vinod_kotnala
Posted On:   Monday, December 3, 2001 05:21 AM

I'm using JNDI to talk to Active Directory. If the number of values of a multi-value attribute in Active Directory is greater than 1000 (eg. number of users in a group), the only way to access all its values is to enumerate these using incremental retrievals of data(range retrieval). Say we want to fetch the member attribute of a Group which has about 5000 members ..Then the only way to fetch the values of attribute "member" is using the following: Attribute members = attrs.get("member;range=0-999"); ## We can't use attrs.get("member"), as it returns null ## But this just returns the first 1000   More>>

I'm using JNDI to talk to Active Directory.



If the number of values of a multi-value attribute in Active Directory
is greater than 1000 (eg. number of users in a group), the only way
to access all its values is to enumerate these using incremental
retrievals of data(range retrieval).



Say we want to fetch the member attribute of a Group which has about
5000 members ..Then the only way to fetch the values of attribute
"member" is using the following:



Attribute members = attrs.get("member;range=0-999");



## We can't use attrs.get("member"), as it returns null ##




But this just returns the first 1000 values and I'm unable to fetch
the other 4000 values.



How do I fetch all the remaining values or is there some way to
retrieve all the valuesfor an attribute regardless of number of values
it has?



Thanks,

vinod

   <<Less

Re: Fetching all the values (&gt;1000 ) of a multi-value attribute in ADS

Posted By:   Kullervo_Kala  
Posted On:   Friday, January 25, 2002 05:47 AM


Just found the answer..Here is the sample code...I'll explain further if needed...


You can call the function like:




pagedListMembers(lc,"cn=mygroup,ou=whatever");



void pagedListMembers(LdapContext lc,String groupRDN){
try{
final int pagesize = 1000;
/*
// beware of DSA limiting search results and use range-qualifier
// http://www.ietf.org/internet-drafts/draft-kashi-incremental-00.txt
*/
int pageCount = 0;
int returnedCount = m_PageSize;

while (true){
// create range dynamically
String[] currRange = new String[1];
currRange[0] = "member;Range=" + String.valueOf(pageCount * m_PageSize) + "-" + String.valueOf((pageCount+1) * m_PageSize-1);

Attributes result = lc.getAttributes(groupRDN,currRange );
// Tricky part
NamingEnumeration searchranges = result.getIDs();
String searchrange = searchranges.nextElement().toString();
System.out.println("Handling suggested " + currRange[0] + " with returned " + searchrange);
//
Attribute member = result.get(searchrange);

if (member == null)
return; // no members
returnedCount = member.size();
System.out.println( searchrange + " returned " + returnedCount + " attributes.");
NamingEnumeration results = member.getAll();
while (results != null && results.hasMoreElements()) {
Object o = results.nextElement();
// Actions of your choice
}
results.close();
pageCount++;
}

} catch(Exception e){

System.out.println(e.getMessage());
}

}
About | Sitemap | Contact