Dan Barber
Dan Barber

Reputation: 579

SPRING LDAP - ODManager query returning size limit exceeded

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.

Upvotes: 2

Views: 2692

Answers (2)

Antony Glim
Antony Glim

Reputation: 89

Do all like in answer from Dan Barber and got exception.

PartialResultException: Unprocessed Continuation Reference(s)] with root cause

To fix it, just add ignorePartialResultException to doWithSingleContext method.

public static <T> T doWithSingleContext(ContextSource contextSource,
                                            LdapOperationsCallback<T> callback,
                                            boolean useReadOnly,
                                            boolean ignorePartialResultException,
                                            boolean ignoreNameNotFoundException)

Upvotes: 0

Dan Barber
Dan Barber

Reputation: 579

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.

  1. 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;
        }
    } 
    
  2. 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;
            }
        });
    }
    

Upvotes: 1

Related Questions