@Test public void findChangedGroupsPaged_searchFiltersTest() throws Exception { List<LdapGroup> pageOne = new ArrayList<>(); pageOne.add(buildGroup("gnr")); pageOne.add(buildGroup("nirvana")); pageOne.add(buildGroup("eagles")); List<LdapGroup> pageTwo = new ArrayList<>(); pageTwo.add(buildGroup("eagles")); pageTwo.add(buildGroup("fleetwood mac")); pageTwo.add(buildGroup("pink floyd")); syncConfig.setSyncPageSize(3); Capture<String> allChangedGroupsPageFilter1 = Capture.newInstance(); Capture<String> allChangedGroupsPageFilter2 = Capture.newInstance(); Capture<String> allChangedGroupsFilter = Capture.newInstance(); expect(mockLdapTemplate.search( eq(syncConfig.getGroupSearchBase()), capture(allChangedGroupsFilter), anyObject(SearchControls.class), anyObject(AcmGroupContextMapper.class), anyObject(AggregateDirContextProcessor.class))).andReturn(pageOne); expect(mockLdapTemplate.search( eq(syncConfig.getGroupSearchBase()), capture(allChangedGroupsPageFilter1), anyObject(SearchControls.class), anyObject(AcmGroupContextMapper.class), anyObject(AggregateDirContextProcessor.class))).andReturn(pageTwo); expect(mockLdapTemplate.search( eq(syncConfig.getGroupSearchBase()), capture(allChangedGroupsPageFilter2), anyObject(SearchControls.class), anyObject(AcmGroupContextMapper.class), anyObject(AggregateDirContextProcessor.class))).andReturn(new ArrayList<>()); replayAll(); String ldapLastSyncDateTimestamp = ZonedDateTime.now(ZoneOffset.UTC).minusDays(1).toString(); List<LdapGroup> found = unit.findGroupsPaged(mockLdapTemplate, syncConfig, Optional.of(ldapLastSyncDateTimestamp)); verifyAll(); assertEquals(pageOne.size() + pageTwo.size() - 1, found.size()); String actualChangedGroupsFilter = allChangedGroupsFilter.getValue(); String actualChangedGroupsPageFilter1 = allChangedGroupsPageFilter1.getValue(); String actualChangedGroupsPageFilter2 = allChangedGroupsPageFilter2.getValue(); ldapLastSyncDateTimestamp = Directory.valueOf(syncConfig.getDirectoryType()) .convertToDirectorySpecificTimestamp(ldapLastSyncDateTimestamp); String expectedChangedGroupsFilter = String.format(syncConfig.getChangedGroupSearchFilter(), ldapLastSyncDateTimestamp); String expectedChangedGroupsPageFilter1 = String.format(syncConfig.getChangedGroupSearchPageFilter(), "eagles", ldapLastSyncDateTimestamp); String expectedChangedGroupsPageFilter2 = String.format(syncConfig.getChangedGroupSearchPageFilter(), "pink floyd", ldapLastSyncDateTimestamp); assertEquals(expectedChangedGroupsFilter, actualChangedGroupsFilter); assertEquals(expectedChangedGroupsPageFilter1, actualChangedGroupsPageFilter1); assertEquals(expectedChangedGroupsPageFilter2, actualChangedGroupsPageFilter2); }
@Override public List<LdapGroup> findGroupsPaged(LdapTemplate template, AcmLdapSyncConfig config, Optional<String> ldapLastSyncDate) { SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); searchControls.setReturningAttributes(new String[] { "cn", "member", "displayName" }); AggregateDirContextProcessor sortedAndPaged = buildSortedAndPagesProcessor(config, config.getGroupsSortingAttribute()); AcmGroupContextMapper acmGroupContextMapper = new AcmGroupContextMapper(config, template); boolean searchGroups = true; boolean skipFirst = false; Optional<String> lastSyncTimestamp = ldapLastSyncDate .map(it -> convertToDirectorySpecificTimestamp(it, config.getDirectoryType())); String searchFilter = buildGroupSearchFilter(config, lastSyncTimestamp); List<LdapGroup> ldapGroups = new ArrayList<>(); while (searchGroups) { log.debug("search filter: [{}]", searchFilter); List<LdapGroup> found = template.search(config.getGroupSearchBase(), searchFilter, searchControls, acmGroupContextMapper, sortedAndPaged); if (skipFirst && !found.isEmpty()) { ldapGroups.addAll(found.subList(1, found.size())); } else { ldapGroups.addAll(found); } log.debug("Groups found: [{}]", found.size()); searchGroups = config.getSyncPageSize() == found.size(); if (searchGroups) { skipFirst = true; LdapGroup lastFound = found.get(found.size() - 1); searchFilter = buildPagedGroupsSearchFilter(config, lastFound.getSortableValue(), lastSyncTimestamp); sortedAndPaged = buildSortedAndPagesProcessor(config, config.getGroupsSortingAttribute()); log.trace("Search filter now: [{}]", searchFilter); } } log.info("LDAP sync number of groups: [{}]", ldapGroups.size()); return ldapGroups; }
CustomPagedLdapDao implements SpringLdapDao { @Override public List<LdapGroup> findGroupsPaged(LdapTemplate template, AcmLdapSyncConfig config, Optional<String> ldapLastSyncDate) { SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); searchControls.setReturningAttributes(new String[] { "cn", "member", "displayName" }); AggregateDirContextProcessor sortedAndPaged = buildSortedAndPagesProcessor(config, config.getGroupsSortingAttribute()); AcmGroupContextMapper acmGroupContextMapper = new AcmGroupContextMapper(config, template); boolean searchGroups = true; boolean skipFirst = false; Optional<String> lastSyncTimestamp = ldapLastSyncDate .map(it -> convertToDirectorySpecificTimestamp(it, config.getDirectoryType())); String searchFilter = buildGroupSearchFilter(config, lastSyncTimestamp); List<LdapGroup> ldapGroups = new ArrayList<>(); while (searchGroups) { log.debug("search filter: [{}]", searchFilter); List<LdapGroup> found = template.search(config.getGroupSearchBase(), searchFilter, searchControls, acmGroupContextMapper, sortedAndPaged); if (skipFirst && !found.isEmpty()) { ldapGroups.addAll(found.subList(1, found.size())); } else { ldapGroups.addAll(found); } log.debug("Groups found: [{}]", found.size()); searchGroups = config.getSyncPageSize() == found.size(); if (searchGroups) { skipFirst = true; LdapGroup lastFound = found.get(found.size() - 1); searchFilter = buildPagedGroupsSearchFilter(config, lastFound.getSortableValue(), lastSyncTimestamp); sortedAndPaged = buildSortedAndPagesProcessor(config, config.getGroupsSortingAttribute()); log.trace("Search filter now: [{}]", searchFilter); } } log.info("LDAP sync number of groups: [{}]", ldapGroups.size()); return ldapGroups; } }
CustomPagedLdapDao implements SpringLdapDao { @Override public List<LdapGroup> findGroupsPaged(LdapTemplate template, AcmLdapSyncConfig config, Optional<String> ldapLastSyncDate) { SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); searchControls.setReturningAttributes(new String[] { "cn", "member", "displayName" }); AggregateDirContextProcessor sortedAndPaged = buildSortedAndPagesProcessor(config, config.getGroupsSortingAttribute()); AcmGroupContextMapper acmGroupContextMapper = new AcmGroupContextMapper(config, template); boolean searchGroups = true; boolean skipFirst = false; Optional<String> lastSyncTimestamp = ldapLastSyncDate .map(it -> convertToDirectorySpecificTimestamp(it, config.getDirectoryType())); String searchFilter = buildGroupSearchFilter(config, lastSyncTimestamp); List<LdapGroup> ldapGroups = new ArrayList<>(); while (searchGroups) { log.debug("search filter: [{}]", searchFilter); List<LdapGroup> found = template.search(config.getGroupSearchBase(), searchFilter, searchControls, acmGroupContextMapper, sortedAndPaged); if (skipFirst && !found.isEmpty()) { ldapGroups.addAll(found.subList(1, found.size())); } else { ldapGroups.addAll(found); } log.debug("Groups found: [{}]", found.size()); searchGroups = config.getSyncPageSize() == found.size(); if (searchGroups) { skipFirst = true; LdapGroup lastFound = found.get(found.size() - 1); searchFilter = buildPagedGroupsSearchFilter(config, lastFound.getSortableValue(), lastSyncTimestamp); sortedAndPaged = buildSortedAndPagesProcessor(config, config.getGroupsSortingAttribute()); log.trace("Search filter now: [{}]", searchFilter); } } log.info("LDAP sync number of groups: [{}]", ldapGroups.size()); return ldapGroups; }  }
CustomPagedLdapDao implements SpringLdapDao { @Override public List<LdapGroup> findGroupsPaged(LdapTemplate template, AcmLdapSyncConfig config, Optional<String> ldapLastSyncDate) { SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); searchControls.setReturningAttributes(new String[] { "cn", "member", "displayName" }); AggregateDirContextProcessor sortedAndPaged = buildSortedAndPagesProcessor(config, config.getGroupsSortingAttribute()); AcmGroupContextMapper acmGroupContextMapper = new AcmGroupContextMapper(config, template); boolean searchGroups = true; boolean skipFirst = false; Optional<String> lastSyncTimestamp = ldapLastSyncDate .map(it -> convertToDirectorySpecificTimestamp(it, config.getDirectoryType())); String searchFilter = buildGroupSearchFilter(config, lastSyncTimestamp); List<LdapGroup> ldapGroups = new ArrayList<>(); while (searchGroups) { log.debug("search filter: [{}]", searchFilter); List<LdapGroup> found = template.search(config.getGroupSearchBase(), searchFilter, searchControls, acmGroupContextMapper, sortedAndPaged); if (skipFirst && !found.isEmpty()) { ldapGroups.addAll(found.subList(1, found.size())); } else { ldapGroups.addAll(found); } log.debug("Groups found: [{}]", found.size()); searchGroups = config.getSyncPageSize() == found.size(); if (searchGroups) { skipFirst = true; LdapGroup lastFound = found.get(found.size() - 1); searchFilter = buildPagedGroupsSearchFilter(config, lastFound.getSortableValue(), lastSyncTimestamp); sortedAndPaged = buildSortedAndPagesProcessor(config, config.getGroupsSortingAttribute()); log.trace("Search filter now: [{}]", searchFilter); } } log.info("LDAP sync number of groups: [{}]", ldapGroups.size()); return ldapGroups; }  @Override List<LdapUser> findUsersPaged(LdapTemplate template, AcmLdapSyncConfig syncConfig, Optional<String> ldapLastSyncDate); List<LdapUser> findUsers(LdapTemplate template, AcmLdapSyncConfig syncConfig,
            String[] attributes, Optional<String> ldapLastSyncDate); @Override List<LdapGroup> findGroupsPaged(LdapTemplate template, AcmLdapSyncConfig config, Optional<String> ldapLastSyncDate); }
CustomPagedLdapDao implements SpringLdapDao { @Override public List<LdapGroup> findGroupsPaged(LdapTemplate template, AcmLdapSyncConfig config, Optional<String> ldapLastSyncDate) { SearchControls searchControls = new SearchControls(); searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE); searchControls.setReturningAttributes(new String[] { "cn", "member", "displayName" }); AggregateDirContextProcessor sortedAndPaged = buildSortedAndPagesProcessor(config, config.getGroupsSortingAttribute()); AcmGroupContextMapper acmGroupContextMapper = new AcmGroupContextMapper(config, template); boolean searchGroups = true; boolean skipFirst = false; Optional<String> lastSyncTimestamp = ldapLastSyncDate .map(it -> convertToDirectorySpecificTimestamp(it, config.getDirectoryType())); String searchFilter = buildGroupSearchFilter(config, lastSyncTimestamp); List<LdapGroup> ldapGroups = new ArrayList<>(); while (searchGroups) { log.debug("search filter: [{}]", searchFilter); List<LdapGroup> found = template.search(config.getGroupSearchBase(), searchFilter, searchControls, acmGroupContextMapper, sortedAndPaged); if (skipFirst && !found.isEmpty()) { ldapGroups.addAll(found.subList(1, found.size())); } else { ldapGroups.addAll(found); } log.debug("Groups found: [{}]", found.size()); searchGroups = config.getSyncPageSize() == found.size(); if (searchGroups) { skipFirst = true; LdapGroup lastFound = found.get(found.size() - 1); searchFilter = buildPagedGroupsSearchFilter(config, lastFound.getSortableValue(), lastSyncTimestamp); sortedAndPaged = buildSortedAndPagesProcessor(config, config.getGroupsSortingAttribute()); log.trace("Search filter now: [{}]", searchFilter); } } log.info("LDAP sync number of groups: [{}]", ldapGroups.size()); return ldapGroups; }  @Override List<LdapUser> findUsersPaged(LdapTemplate template, AcmLdapSyncConfig syncConfig, Optional<String> ldapLastSyncDate); List<LdapUser> findUsers(LdapTemplate template, AcmLdapSyncConfig syncConfig,
            String[] attributes, Optional<String> ldapLastSyncDate); @Override List<LdapGroup> findGroupsPaged(LdapTemplate template, AcmLdapSyncConfig config, Optional<String> ldapLastSyncDate);  }