private static List<UserIdentity> readAllUsersFromLdap( final PwmApplication pwmApplication, final String searchFilter, final int maxResults) throws ChaiUnavailableException, ChaiOperationException, PwmUnrecoverableException, PwmOperationalException { final UserSearchEngine userSearchEngine = new UserSearchEngine(pwmApplication, null); final UserSearchEngine.SearchConfiguration searchConfiguration = new UserSearchEngine.SearchConfiguration(); searchConfiguration.setEnableValueEscaping(false); searchConfiguration.setSearchTimeout( Long.parseLong( pwmApplication.getConfig().readAppProperty(AppProperty.REPORTING_LDAP_SEARCH_TIMEOUT))); if (searchFilter == null) { searchConfiguration.setUsername("*"); } else { searchConfiguration.setFilter(searchFilter); } LOGGER.debug( PwmConstants.REPORTING_SESSION_LABEL, "beginning UserReportService user search using parameters: " + (JsonUtil.serialize(searchConfiguration))); final Map<UserIdentity, Map<String, String>> searchResults = userSearchEngine.performMultiUserSearch( searchConfiguration, maxResults, Collections.<String>emptyList()); LOGGER.debug( PwmConstants.REPORTING_SESSION_LABEL, "user search found " + searchResults.size() + " users for reporting"); final List<UserIdentity> returnList = new ArrayList<>(searchResults.keySet()); Collections.shuffle(returnList); return returnList; }
@Override void doCommand() throws Exception { final PwmApplication pwmApplication = cliEnvironment.getPwmApplication(); final File outputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_NEW_OUTPUT_FILE.getName()); Helper.pause(2000); final long startTime = System.currentTimeMillis(); final UserSearchEngine userSearchEngine = new UserSearchEngine(pwmApplication, SessionLabel.SYSTEM_LABEL); final UserSearchEngine.SearchConfiguration searchConfiguration = new UserSearchEngine.SearchConfiguration(); searchConfiguration.setEnableValueEscaping(false); searchConfiguration.setUsername("*"); final String systemRecordDelimiter = System.getProperty("line.separator"); final Writer writer = new BufferedWriter(new PrintWriter(outputFile, PwmConstants.DEFAULT_CHARSET.toString())); final Map<UserIdentity, Map<String, String>> results = userSearchEngine.performMultiUserSearch( searchConfiguration, Integer.MAX_VALUE, Collections.<String>emptyList()); out( "searching " + results.size() + " users for stored responses to write to " + outputFile.getAbsolutePath() + "...."); int counter = 0; for (final UserIdentity identity : results.keySet()) { final ChaiUser user = pwmApplication.getProxiedChaiUser(identity); final ResponseSet responseSet = pwmApplication.getCrService().readUserResponseSet(null, identity, user); if (responseSet != null) { counter++; out("found responses for '" + user + "', writing to output."); final RestChallengesServer.JsonChallengesData outputData = new RestChallengesServer.JsonChallengesData(); outputData.challenges = responseSet.asChallengeBeans(true); outputData.helpdeskChallenges = responseSet.asHelpdeskChallengeBeans(true); outputData.minimumRandoms = responseSet.getChallengeSet().minimumResponses(); outputData.username = identity.toDelimitedKey(); writer.write(JsonUtil.serialize(outputData)); writer.write(systemRecordDelimiter); } else { out("skipping '" + user.toString() + "', no stored responses."); } } writer.close(); out( "output complete, " + counter + " responses exported in " + TimeDuration.fromCurrent(startTime).asCompactString()); }