LDIFSearch.java revision b8c6b80da1cb6118167a934daa480eb381c59e0e
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/*
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * CDDL HEADER START
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * The contents of this file are subject to the terms of the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Common Development and Distribution License, Version 1.0 only
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * (the "License"). You may not use this file except in compliance
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * with the License.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * or http://forgerock.org/license/CDDLv1.0.html.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * See the License for the specific language governing permissions
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * and limitations under the License.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * When distributing Covered Code, include this CDDL HEADER in each
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * file and include the License file at legal-notices/CDDLv1_0.txt.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * If applicable, add the following below this CDDL HEADER, with the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * fields enclosed by brackets "[]" replaced with your own identifying
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk * information:
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Portions Copyright [yyyy] [name of copyright owner]
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk * CDDL HEADER END
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Copyright 2006-2008 Sun Microsystems, Inc.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Portions Copyright 2013-2015 ForgeRock AS.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkpackage org.opends.server.tools;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport static com.forgerock.opendj.cli.ArgumentConstants.*;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport static com.forgerock.opendj.cli.Utils.*;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport static org.opends.messages.ToolMessages.*;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport static org.opends.server.util.StaticUtils.*;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport java.io.BufferedReader;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport java.io.FileReader;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport java.io.OutputStream;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport java.io.PrintStream;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport java.util.ArrayList;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport java.util.Iterator;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport java.util.LinkedHashSet;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport java.util.LinkedList;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.forgerock.i18n.LocalizableMessage;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.forgerock.opendj.ldap.SearchScope;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.opends.server.core.DirectoryServer;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.opends.server.extensions.ConfigFileHandler;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.opends.server.loggers.JDKLogging;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.opends.server.protocols.ldap.LDAPResultCode;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.opends.server.types.*;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.opends.server.util.BuildVersion;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.opends.server.util.LDIFException;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.opends.server.util.LDIFReader;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.opends.server.util.LDIFWriter;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport com.forgerock.opendj.cli.*;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * This class provides a program that may be used to search LDIF files. It is
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * modeled after the LDAPSearch tool, with the primary differencing being that
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * all of its data comes from LDIF rather than communicating over LDAP.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * However, it does have a number of differences that allow it to perform
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * multiple operations in a single pass rather than requiring multiple passes
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * through the LDIF.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkpublic class LDIFSearch
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk{
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** The fully-qualified name of this class. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private static final String CLASS_NAME = "org.opends.server.tools.LDIFSearch";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** The search scope string that will be used for baseObject searches. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private static final String SCOPE_STRING_BASE = "base";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** The search scope string that will be used for singleLevel searches. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private static final String SCOPE_STRING_ONE = "one";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** The search scope string that will be used for wholeSubtree searches. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private static final String SCOPE_STRING_SUB = "sub";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /** The search scope string that will be used for subordinateSubtree searches. */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private static final String SCOPE_STRING_SUBORDINATE = "subordinate";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Provides the command line arguments to the <CODE>mainSearch</CODE> method
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * so that they can be processed.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param args The command line arguments provided to this program.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public static void main(String[] args)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int exitCode = mainSearch(args, true, System.out, System.err);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (exitCode != 0)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk System.exit(filterExitCode(exitCode));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Parses the provided command line arguments and performs the appropriate
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * search operation.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param args The command line arguments provided to this
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * program.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param initializeServer True if server initialization should be done.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param outStream The output stream to use for standard output, or
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * {@code null} if standard output is not needed.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param errStream The output stream to use for standard error, or
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * {@code null} if standard error is not needed.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @return The return code for this operation. A value of zero indicates
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * that all processing completed successfully. A nonzero value
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * indicates that some problem occurred during processing.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public static int mainSearch(String[] args, boolean initializeServer,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk OutputStream outStream, OutputStream errStream)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk PrintStream out = NullOutputStream.wrapOrNullStream(outStream);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk PrintStream err = NullOutputStream.wrapOrNullStream(errStream);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk JDKLogging.disableLogging();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LinkedHashSet<String> scopeStrings = new LinkedHashSet<>(4);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk scopeStrings.add(SCOPE_STRING_BASE);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk scopeStrings.add(SCOPE_STRING_ONE);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk scopeStrings.add(SCOPE_STRING_SUB);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk scopeStrings.add(SCOPE_STRING_SUBORDINATE);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk BooleanArgument dontWrap;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk BooleanArgument overwriteExisting;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk BooleanArgument showUsage;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk StringArgument filterFile;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk IntegerArgument sizeLimit;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk IntegerArgument timeLimit;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk MultiChoiceArgument scopeString;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk StringArgument baseDNString;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk StringArgument configClass;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk StringArgument configFile;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk StringArgument ldifFile;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk StringArgument outputFile;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LocalizableMessage toolDescription = INFO_LDIFSEARCH_TOOL_DESCRIPTION.get();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ArgumentParser argParser = new ArgumentParser(CLASS_NAME, toolDescription,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk false, true, 0, 0,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "[filter] [attributes ...]");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.setShortToolDescription(REF_SHORT_DESC_LDIFSEARCH.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.setVersionHandler(new DirectoryServerVersionHandler());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ldifFile = new StringArgument(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "ldiffile", 'l', "ldifFile", false, true,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk true, INFO_LDIFFILE_PLACEHOLDER.get(), null, null,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk INFO_LDIFSEARCH_DESCRIPTION_LDIF_FILE.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(ldifFile);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk baseDNString = new StringArgument(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "basedn", OPTION_SHORT_BASEDN,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk OPTION_LONG_BASEDN, false, true,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk true, INFO_BASEDN_PLACEHOLDER.get(), "", null,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk INFO_LDIFSEARCH_DESCRIPTION_BASEDN.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(baseDNString);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk scopeString = new MultiChoiceArgument(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "scope", 's', "searchScope", false, false,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk true, INFO_SCOPE_PLACEHOLDER.get(), SCOPE_STRING_SUB,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk null, scopeStrings, false,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk INFO_LDIFSEARCH_DESCRIPTION_SCOPE.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(scopeString);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk configFile = new StringArgument(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "configfile", 'c', "configFile", false,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk false, true, INFO_CONFIGFILE_PLACEHOLDER.get(), null, null,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk INFO_DESCRIPTION_CONFIG_FILE.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk configFile.setHidden(true);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(configFile);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk configClass = new StringArgument("configclass", OPTION_SHORT_CONFIG_CLASS,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk OPTION_LONG_CONFIG_CLASS, false,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk false, true, INFO_CONFIGCLASS_PLACEHOLDER.get(),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ConfigFileHandler.class.getName(), null,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk INFO_DESCRIPTION_CONFIG_CLASS.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk configClass.setHidden(true);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(configClass);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk filterFile = new StringArgument("filterfile", 'f', "filterFile", false,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk false, true, INFO_FILTER_FILE_PLACEHOLDER.get(), null, null,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk INFO_LDIFSEARCH_DESCRIPTION_FILTER_FILE.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(filterFile);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk outputFile = new StringArgument(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "outputfile", 'o', "outputFile", false,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk false, true, INFO_OUTPUT_FILE_PLACEHOLDER.get(), null, null,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk INFO_LDIFSEARCH_DESCRIPTION_OUTPUT_FILE.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(outputFile);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk overwriteExisting =
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk new BooleanArgument(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "overwriteexisting", 'O',"overwriteExisting",
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk INFO_LDIFSEARCH_DESCRIPTION_OVERWRITE_EXISTING.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(overwriteExisting);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk dontWrap = new BooleanArgument(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "dontwrap", 'T', "dontWrap",
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk INFO_LDIFSEARCH_DESCRIPTION_DONT_WRAP.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(dontWrap);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk sizeLimit = new IntegerArgument(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "sizelimit", 'z', "sizeLimit", false,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk false, true, INFO_SIZE_LIMIT_PLACEHOLDER.get(), 0, null,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk true, 0, false, 0,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk INFO_LDIFSEARCH_DESCRIPTION_SIZE_LIMIT.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(sizeLimit);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk timeLimit = new IntegerArgument(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk "timelimit", 't', "timeLimit", false,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk false, true, INFO_TIME_LIMIT_PLACEHOLDER.get(), 0, null,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk true, 0, false, 0,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk INFO_LDIFSEARCH_DESCRIPTION_TIME_LIMIT.get());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(timeLimit);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk showUsage = CommonArguments.getShowUsage();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.addArgument(showUsage);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.setUsageArgument(showUsage);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (ArgumentException ae)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LocalizableMessage message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(message);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Parse the command-line arguments provided to the program.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk argParser.parseArguments(args);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (ArgumentException ae)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(message);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(argParser.getUsage());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // If we should just display usage or version information,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // then print it and exit.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (argParser.usageOrVersionDisplayed())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 0;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Checks the version - if upgrade required, the tool is unusable
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk BuildVersion.checkVersionMismatch();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (InitializationException e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(wrapText(e.getMessage(), MAX_LINE_WIDTH));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Make sure that at least one filter was provided. Also get the attribute
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // list at the same time because it may need to be specified in the same
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // way.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean allUserAttrs = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean allOperationalAttrs = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //Return objectclass attribute unless analysis of the arguments determines
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //otherwise.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean includeObjectclassAttrs = true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk final LinkedList<String> attributeNames = new LinkedList<>();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LinkedList<String> objectClassNames = new LinkedList<>();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LinkedList<String> filterStrings = new LinkedList<>();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (filterFile.isPresent())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk BufferedReader in = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String fileNameValue = filterFile.getValue();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk in = new BufferedReader(new FileReader(fileNameValue));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String line = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk while ((line = in.readLine()) != null)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(line.trim().equals(""))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // ignore empty lines.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk continue;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk filterStrings.add(line);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk } catch(Exception e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(wrapText(e.getMessage(), MAX_LINE_WIDTH));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk finally
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk close(in);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ArrayList<String> trailingArguments = argParser.getTrailingArguments();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (trailingArguments != null && !trailingArguments.isEmpty())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (String attributeName : trailingArguments)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String lowerName = toLowerCase(attributeName);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (lowerName.equals("*"))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk allUserAttrs = true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else if (lowerName.equals("+"))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk allOperationalAttrs = true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else if (lowerName.startsWith("@"))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk objectClassNames.add(lowerName.substring(1));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk attributeNames.add(lowerName);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ArrayList<String> trailingArguments = argParser.getTrailingArguments();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if ((trailingArguments == null) || trailingArguments.isEmpty())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LocalizableMessage message = ERR_LDIFSEARCH_NO_FILTER.get();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(message);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Iterator<String> iterator = trailingArguments.iterator();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk filterStrings = new LinkedList<>();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk filterStrings.add(iterator.next());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk while (iterator.hasNext())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String lowerName = toLowerCase(iterator.next());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (lowerName.equals("*"))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk allUserAttrs = true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else if (lowerName.equals("+"))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk allOperationalAttrs = true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else if (lowerName.startsWith("@"))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk objectClassNames.add(lowerName.substring(1));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk attributeNames.add(lowerName);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (attributeNames.isEmpty()
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk && objectClassNames.isEmpty()
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk && !allOperationalAttrs)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // This will be true if no attributes were requested, which is effectively
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // all user attributes. It will also be true if just "*" was included,
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // but the net result will be the same.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk allUserAttrs = true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //Determine if objectclass attribute should be returned.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(!allUserAttrs) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //Single '+', never return objectclass.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(allOperationalAttrs && objectClassNames.isEmpty() &&
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk attributeNames.isEmpty())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk includeObjectclassAttrs=false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //If "objectclass" isn't specified in the attributes to return, then
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk //don't include objectclass attribute.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(!attributeNames.isEmpty() && objectClassNames.isEmpty() &&
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk !attributeNames.contains("objectclass"))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk includeObjectclassAttrs=false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Bootstrap the Directory Server configuration for use as a client.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk DirectoryServer directoryServer = DirectoryServer.getInstance();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // If we're to use the configuration then initialize it, along with the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // schema.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean checkSchema = configFile.isPresent();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(initializeServer) {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk DirectoryServer.bootstrapClient();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (checkSchema)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk DirectoryServer.initializeJMX();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (Exception e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(ERR_LDIFSEARCH_CANNOT_INITIALIZE_JMX.get(configFile.getValue(), e.getMessage()));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk directoryServer.initializeConfiguration(configClass.getValue(),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk configFile.getValue());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (Exception e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(ERR_LDIFSEARCH_CANNOT_INITIALIZE_CONFIG.get(configFile.getValue(), e.getMessage()));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk directoryServer.initializeSchema();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (Exception e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(ERR_LDIFSEARCH_CANNOT_INITIALIZE_SCHEMA.get(configFile.getValue(), e.getMessage()));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Choose the desired search scope.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk SearchScope searchScope;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (scopeString.isPresent())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk String scopeStr = toLowerCase(scopeString.getValue());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (scopeStr.equals(SCOPE_STRING_BASE))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searchScope = SearchScope.BASE_OBJECT;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else if (scopeStr.equals(SCOPE_STRING_ONE))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searchScope = SearchScope.SINGLE_LEVEL;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else if (scopeStr.equals(SCOPE_STRING_SUBORDINATE))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searchScope = SearchScope.SUBORDINATES;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searchScope = SearchScope.WHOLE_SUBTREE;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searchScope = SearchScope.WHOLE_SUBTREE;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Create the list of filters that will be used to process the searches.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LinkedList<SearchFilter> searchFilters = new LinkedList<>();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (String filterString : filterStrings)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk searchFilters.add(SearchFilter.createFilterFromString(filterString));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (Exception e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LocalizableMessage message = ERR_LDIFSEARCH_CANNOT_PARSE_FILTER.get(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk filterString, e.getMessage());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(message);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Transform the attributes to return from strings to attribute types.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LinkedHashSet<AttributeType> userAttributeTypes = new LinkedHashSet<>();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LinkedHashSet<AttributeType> operationalAttributeTypes = new LinkedHashSet<>();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (String attributeName : attributeNames)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk AttributeType t = DirectoryServer.getAttributeType(attributeName, true);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (t.isOperational())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk operationalAttributeTypes.add(t);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk userAttributeTypes.add(t);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (String objectClassName : objectClassNames)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ObjectClass c = DirectoryServer.getObjectClass(objectClassName, true);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (AttributeType t : c.getRequiredAttributeChain())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (t.isOperational())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk operationalAttributeTypes.add(t);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk userAttributeTypes.add(t);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (AttributeType t : c.getOptionalAttributeChain())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (t.isOperational())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk operationalAttributeTypes.add(t);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk userAttributeTypes.add(t);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Set the base DNs for the import config.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LinkedList<DN> baseDNs = new LinkedList<>();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (baseDNString.isPresent())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (String dnString : baseDNString.getValues())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk baseDNs.add(DN.valueOf(dnString));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (Exception e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LocalizableMessage message = ERR_LDIFSEARCH_CANNOT_PARSE_BASE_DN.get(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk dnString, e.getMessage());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(message);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk baseDNs.add(DN.rootDN());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Get the time limit in milliseconds.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk long timeLimitMillis;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (timeLimit.isPresent())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk timeLimitMillis = 1000L * timeLimit.getIntValue();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk timeLimitMillis = 0;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (Exception e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(ERR_LDIFSEARCH_CANNOT_PARSE_TIME_LIMIT.get(e));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Convert the size limit to an integer.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int sizeLimitValue;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (sizeLimit.isPresent())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk sizeLimitValue = sizeLimit.getIntValue();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk sizeLimitValue =0;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (Exception e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(ERR_LDIFSEARCH_CANNOT_PARSE_SIZE_LIMIT.get(e));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Create the LDIF import configuration that will be used to read the source
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // data.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LDIFImportConfig importConfig;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (ldifFile.isPresent())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk importConfig = new LDIFImportConfig(ldifFile.getValues());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk importConfig = new LDIFImportConfig(System.in);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Create the LDIF export configuration that will be used to write the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // matching entries.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LDIFExportConfig exportConfig;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (outputFile.isPresent())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (overwriteExisting.isPresent())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk exportConfig = new LDIFExportConfig(outputFile.getValue(),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ExistingFileBehavior.OVERWRITE);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk exportConfig = new LDIFExportConfig(outputFile.getValue(),
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk ExistingFileBehavior.APPEND);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk exportConfig = new LDIFExportConfig(out);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk exportConfig.setIncludeObjectClasses(includeObjectclassAttrs);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (dontWrap.isPresent())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk exportConfig.setWrapColumn(0);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk exportConfig.setWrapColumn(75);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Create the LDIF reader/writer from the import/export config.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LDIFReader reader;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LDIFWriter writer;
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk reader = new LDIFReader(importConfig);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (Exception e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(ERR_LDIFSEARCH_CANNOT_CREATE_READER.get(e));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk writer = new LDIFWriter(exportConfig);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (Exception e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk close(reader);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(ERR_LDIFSEARCH_CANNOT_CREATE_WRITER.get(e));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return 1;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Start reading data from the LDIF reader.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk long startTime = System.currentTimeMillis();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk long stopTime = startTime + timeLimitMillis;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk long matchCount = 0;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk int resultCode = LDAPResultCode.SUCCESS;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk while (true)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // If the time limit has been reached, then stop now.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if ((timeLimitMillis > 0) && (System.currentTimeMillis() > stopTime))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk resultCode = LDAPResultCode.TIME_LIMIT_EXCEEDED;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LocalizableMessage message = WARN_LDIFSEARCH_TIME_LIMIT_EXCEEDED.get();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(message);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk break;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk try
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Entry entry = reader.readEntry(checkSchema);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (entry == null)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk break;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Check to see if the entry has an acceptable base and scope.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean matchesBaseAndScope = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (DN baseDN : baseDNs)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (entry.matchesBaseAndScope(baseDN, searchScope))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk matchesBaseAndScope = true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk break;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (! matchesBaseAndScope)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk continue;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Check to see if the entry matches any of the filters.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk boolean matchesFilter = false;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (SearchFilter filter : searchFilters)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (filter.matchesEntry(entry))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk matchesFilter = true;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk break;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (! matchesFilter)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk continue;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Prepare the entry to return to the client.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (! allUserAttrs)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Iterator<AttributeType> iterator =
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk entry.getUserAttributes().keySet().iterator();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk while (iterator.hasNext())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (! userAttributeTypes.contains(iterator.next()))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk iterator.remove();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (! allOperationalAttrs)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk Iterator<AttributeType> iterator =
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk entry.getOperationalAttributes().keySet().iterator();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk while (iterator.hasNext())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (! operationalAttributeTypes.contains(iterator.next()))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk iterator.remove();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // Write the entry to the client and increase the count.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // FIXME -- Should we include a comment about which base+filter matched?
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk writer.writeEntry(entry);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk writer.flush();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk matchCount++;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if ((sizeLimitValue > 0) && (matchCount >= sizeLimitValue))
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk resultCode = LDAPResultCode.SIZE_LIMIT_EXCEEDED;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LocalizableMessage message = WARN_LDIFSEARCH_SIZE_LIMIT_EXCEEDED.get();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(message);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk break;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (LDIFException le)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (le.canContinueReading())
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LocalizableMessage message = ERR_LDIFSEARCH_CANNOT_READ_ENTRY_RECOVERABLE.get(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk le.getMessage());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(message);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk else
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk LocalizableMessage message = ERR_LDIFSEARCH_CANNOT_READ_ENTRY_FATAL.get(
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk le.getMessage());
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(message);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk resultCode = LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk break;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk catch (Exception e)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk err.println(ERR_LDIFSEARCH_ERROR_DURING_PROCESSING.get(e));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk resultCode = LDAPResultCode.CLIENT_SIDE_LOCAL_ERROR;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk break;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk close(reader, writer);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return resultCode;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk}
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk