SPRING LDAP - 超出ODManager查询返回大小限制

时间:2014-03-26 20:55:34

标签: java spring ldap

我正在尝试使用Spring LDAP 1.3.2查询Microsoft Active Directory应用程序模式(ADAM)。我正在使用ODMManager来搜索ADAM。我收到了错误

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)

从文档中我不清楚如何使用PagedResultsDirContextProcessor来处理ODMManager搜索。非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我设法使用Spring LDAP 2.0.1.RELEASE来实现这一点。现在,对象目录映射器在LdapTemplate中进行管理。我使用自定义ContextMapper在目录上执行搜索。映射器和方法如下所示。

  1. 创建自定义ContextMapper类。

    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. 创建一个创建LdapOperationsCallback并将结果分页的方法

    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;
            }
        });
    }