Problem while using controls with MS ActiveDirectory

Hi ,

I am facing a strange problem while using controls with Active Directory.

I am using a SearchControl to set the total number of users to be returned matching the filter to 800 , and used the PagedResultControl to set the page size as 400 . Here is the the sample code i used

SearchControls controls = new SearchControls();

int pageSize = 400;

controls.setCountLimit(800);

byte[] cookie = null;

Control[] ctls = new Control[]

{

new PagedResultsControl(pageSize)

};

context.setRequestControls(ctls);

do

{

NamingEnumeration result = context.search("",this.getUserObjectclass(),filter,controls);

while (result != null && result.hasMoreElements())

{

resultEnum.add(result.nextElement());

}

// Got the cookie from response controls

cookie = respcontrolobj.getCookie();

//Sending cookie back to the server

context.setRequestControls(new Control[]

{

new PagedResultsControl(pageSize, cookie, Control.CRITICAL)

});

}

while ((cookie != null) && (cookie.length != 0));

But even after returning 800 users the cookie returned form the server

is not null, hence the while loop runs over and over to return all the users matching the filter , ie more than 800.

Please help me to find out where it could have gone wrong . I am using MS Active Directory 2003

[1457 byte] By [Roshitha] at [2007-11-27 10:02:16]
# 1

Not a strange problem, AD is behaving as designed.

There's a good public description of this behaviour at http://blog.joeware.net/2006/09/28/634/

In essence, because each page (in your case 400) is less than the max result set (800) and that each page request is considered a LDAP query, you will never hit the max result set, and all of the results (in your case > 800) will be returned.

Now you may argue that perhaps this may not be how you personally interpret the RFC, but consider this from the perspective of what paged results & max result size are trying to achieve; namely preventing DOS attacks on the server and ensuring good performance on the client.

Paged Results is designed to allow both the client to control the flow of results and to allow the server to effectively manage the query and temporary storage. This makes it possible to return very large result sets to the client without negatively impacting both the client or the server. The design decision was made that if paged results were requested, all of the results would be returned, ignoring both the requested max result size requested by the client and the max result size defined by the domain controller's LDAP Query Policy.

adler_stevena at 2007-7-13 0:36:33 > top of Java-index,Core,Core APIs...