I am attempting to query Microsoft Active Directory Application Mode (ADAM) using Spring LDAP 1.3.2. I am using the ODMManager to search ADAM. I am getting the error
javax.naming.SizeLimitExceededException: [LDAP: error code 4 - Sizelimit Exceeded]; remaining name '/'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3119)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3013)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2820)
It is not clear from the documentation how I can use the PagedResultsDirContextProcessor to process ODMManager searches. Any help greatly appreciated.
I managed to get this working using Spring LDAP 2.0.1.RELEASE. The Object Directory Mapper is now managed within the LdapTemplate. I used the a custom ContextMapper to execute a search on the directory. The mapper and the method are listed below.
Create Custom ContextMapper class.
public class UserContextMapper implements ContextMapper {
private static ApplicationContext appContext = new ClassPathXmlApplicationContext(new String[]{"spring-config.xml"});
public Object mapFromContext(Object ctx) {
Class<User> clazz = User.class;
LdapTemplate ldapTemplate = (LdapTemplate) appContext.getBean("ldapTemplate");
User user = ldapTemplate.getObjectDirectoryMapper().mapFromLdapDataEntry((DirContextOperations) ctx, clazz);
return user;
}
}
Create a method that creates an LdapOperationsCallback and pages the results
public List<User> getLdapQueryResult(final LdapName dn, final Filter filter) throws NamingException {
final PagedResultsDirContextProcessor processor = new PagedResultsDirContextProcessor(getPageSize());
final SearchControls searchControls = new SearchControls();
final UserContextMapper ucm = new UserContextMapper();
searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
return SingleContextSource.doWithSingleContext(
ldapTemplate.getContextSource(), new LdapOperationsCallback<List<User>>() {
@Override
public List<User> doWithLdapOperations(LdapOperations operations) {
List<User> result = new LinkedList<User>();
do {
List<User> oneResult = operations.search(dn, filter.encode(), searchControls, ucm, processor);
result.addAll(oneResult);
} while (processor.hasMore());
return result;
}
});
}