mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Gaetan Boismal
23.46.2016 08a8540072a370b4e7e9604eb97818dcfd4d74c6
opendj-core/src/main/java/org/forgerock/opendj/ldap/Base64.java
@@ -12,7 +12,7 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2006-2009 Sun Microsystems, Inc.
 * Portions copyright 2012-2015 ForgeRock AS.
 * Portions copyright 2012-2016 ForgeRock AS.
 */
package org.forgerock.opendj.ldap;
@@ -34,7 +34,7 @@
 * For example, the JDK encoder does not handle array/offset/len parameters, and
 * the decoder ignores invalid Base64 data.
 */
final class Base64 {
public final class Base64 {
    /**
     * The set of characters that may be used in base64-encoded values.
     */
@@ -53,7 +53,7 @@
     * @throws NullPointerException
     *             If {@code base64} was {@code null}.
     */
    static ByteString decode(final String base64) {
    public static ByteString decode(final String base64) {
        Reject.ifNull(base64);
        // The encoded value must have length that is a multiple of four
@@ -307,7 +307,21 @@
     * @throws NullPointerException
     *             If {@code bytes} was {@code null}.
     */
    static String encode(final ByteSequence bytes) {
    public static String encode(final byte[] bytes) {
        return encode(ByteString.wrap(bytes));
    }
    /**
     * Encodes the provided data as a base64 string.
     *
     * @param bytes
     *            The data to be encoded.
     * @return The base64 encoded representation of {@code bytes}.
     * @throws NullPointerException
     *             If {@code bytes} was {@code null}.
     */
    public static String encode(final ByteSequence bytes) {
        Reject.ifNull(bytes);
        if (bytes.isEmpty()) {
opendj-core/src/test/java/org/forgerock/opendj/ldap/TestBase64.java
New file
@@ -0,0 +1,190 @@
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2016 ForgeRock AS.
 */
package org.forgerock.opendj.ldap;
import static org.fest.assertions.Assertions.*;
import org.forgerock.i18n.LocalizedIllegalArgumentException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/** This class defines a set of tests for the {@link org.forgerock.opendj.ldap.Base64} class. */
public final class TestBase64 extends SdkTestCase {
    /** Look up table for converting hex chars to byte values. */
    private static final byte[] HEX_TO_BYTE = { -1, -1, -1, -1, -1, -1, -1, -1,
                                                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
                                                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
                                                -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1,
                                                -1, -1, -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1,
                                                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
                                                -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 - 1,
                                                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
    /**
     * Base 64 valid test data provider.
     *
     * @return Returns an array of decoded and valid encoded base64 data.
     */
    @DataProvider(name = "validData")
    public Object[][] createValidData() {
        return new Object[][] {
            { "", "" },
            { "00", "AA==" },
            { "01", "AQ==" },
            { "02", "Ag==" },
            { "03", "Aw==" },
            { "04", "BA==" },
            { "05", "BQ==" },
            { "06", "Bg==" },
            { "07", "Bw==" },
            { "0000", "AAA=" },
            { "000000", "AAAA" },
            { "00000000", "AAAAAA==" },
            {
                "000102030405060708090a0b0c0d0e0f"
                    + "101112131415161718191a1b1c1d1e1f"
                    + "202122232425262728292a2b2c2d2e2f"
                    + "303132333435363738393a3b3c3d3e3f"
                    + "404142434445464748494a4b4c4d4e4f"
                    + "505152535455565758595a5b5c5d5e5f"
                    + "606162636465666768696a6b6c6d6e6f"
                    + "707172737475767778797a7b7c7d7e7f"
                    + "808182838485868788898a8b8c8d8e8f"
                    + "909192939495969798999a9b9c9d9e9f"
                    + "a0a1a2a3a4a5a6a7a8a9aaabacadaeaf"
                    + "b0b1b2b3b4b5b6b7b8b9babbbcbdbebf"
                    + "c0c1c2c3c4c5c6c7c8c9cacbcccdcecf"
                    + "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf"
                    + "e0e1e2e3e4e5e6e7e8e9eaebecedeeef"
                    + "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff",
                "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v"
                    + "MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f"
                    + "YGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6P"
                    + "kJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/"
                    + "wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v"
                    + "8PHy8/T19vf4+fr7/P3+/w=="
            },
        };
    }
    /**
     * Base 64 invalid test data provider.
     *
     * @return Returns an array of invalid encoded base64 data.
     */
    @DataProvider(name = "invalidData")
    public Object[][] createInvalidData() {
        // FIXME: fix cases ==== and ==x=
        return new Object[][] { { "=" }, { "==" }, { "===" }, { "A" },
                                { "AA" }, { "AAA" }, { "AA`=" }, { "AA~=" }, { "AA!=" },
                                { "AA@=" }, { "AA#=" }, { "AA$=" }, { "AA%=" }, { "AA^=" },
                                { "AA*=" }, { "AA(=" }, { "AA)=" }, { "AA_=" }, { "AA-=" },
                                { "AA{=" }, { "AA}=" }, { "AA|=" }, { "AA[=" }, { "AA]=" },
                                { "AA\\=" }, { "AA;=" }, { "AA'=" }, { "AA\"=" }, { "AA:=" },
                                { "AA,=" }, { "AA.=" }, { "AA<=" }, { "AA>=" }, { "AA?=" },
                                { "AA;=" } };
    }
    /**
     * Tests the encode method.
     *
     * @param hexData
     *         The decoded hex data.
     * @param encodedData
     *         The encoded data.
     * @throws Exception
     *         If the test failed unexpectedly.
     */
    @Test(dataProvider = "validData")
    public void testEncode(final String hexData, final String encodedData) throws Exception {
        assertThat(Base64.encode(getBytes(hexData))).isEqualTo(encodedData);
    }
    /**
     * Tests the decode method against valid data.
     *
     * @param hexData
     *         The decoded hex data.
     * @param encodedData
     *         The encoded data.
     * @throws Exception
     *         If the test failed unexpectedly.
     */
    @Test(dataProvider = "validData")
    public void testDecodeValidData(final String hexData, final String encodedData) throws Exception {
        assertThat(Base64.decode(encodedData).toByteArray()).isEqualTo(getBytes(hexData));
    }
    /**
     * Tests the decode method against invalid data.
     *
     * @param encodedData
     *         The invalid encoded data.
     * @throws Exception
     *         If the test failed unexpectedly.
     */
    @Test(dataProvider = "invalidData",
          expectedExceptions = LocalizedIllegalArgumentException.class,
          expectedExceptionsMessageRegExp = ".*cannot be base64-decoded.*")
    public void testDecodeInvalidData(String encodedData) throws Exception {
        Base64.decode(encodedData).toByteArray();
    }
    /**
     * Decode a hex string to a byte-array.
     *
     * @param hexData
     *         The string of hex.
     * @return Returns the decoded byte array.
     */
    private byte[] getBytes(String hexData) {
        int sz = hexData.length();
        if (sz % 2 != 0) {
            throw new IllegalArgumentException("Hex string does not contain an even number of hex digits");
        }
        byte[] bytes = new byte[sz / 2];
        for (int i = 0, j = 0; i < sz; i += 2, j++) {
            int c = hexData.codePointAt(i);
            if ((c & 0x7f) != c) {
                throw new IllegalArgumentException("Hex string contains non-hex digits");
            }
            byte b1 = HEX_TO_BYTE[c];
            if (b1 < 0) {
                throw new IllegalArgumentException("Hex string contains non-hex digits");
            }
            c = hexData.codePointAt(i + 1);
            if ((c & 0x7f) != c) {
                throw new IllegalArgumentException("Hex string contains non-hex digits");
            }
            byte b2 = HEX_TO_BYTE[c];
            if (b2 < 0) {
                throw new IllegalArgumentException("Hex string contains non-hex digits");
            }
            bytes[j] = (byte) ((b1 << 4) | b2);
        }
        return bytes;
    }
}
opendj-dsml-servlet/src/main/java/org/opends/dsml/protocol/DSMLServlet.java
@@ -31,7 +31,6 @@
import java.io.OutputStream;
import java.io.StringReader;
import java.net.URL;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
@@ -72,6 +71,8 @@
import javax.xml.validation.SchemaFactory;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizedIllegalArgumentException;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DereferenceAliasesPolicy;
import org.forgerock.opendj.ldap.SearchScope;
@@ -89,7 +90,6 @@
import org.opends.server.tools.SSLConnectionException;
import org.opends.server.tools.SSLConnectionFactory;
import org.opends.server.types.LDAPException;
import org.opends.server.util.Base64;
import org.w3c.dom.Document;
import org.xml.sax.Attributes;
import org.xml.sax.EntityResolver;
@@ -379,7 +379,7 @@
        authenticationInHeader = true;
        String authorization = headerVal.substring(6).trim();
        try {
          String unencoded = new String(Base64.decode(authorization));
          String unencoded = new String(Base64.decode(authorization).toByteArray());
          int colon = unencoded.indexOf(':');
          if (colon > 0) {
            if (useHTTPAuthzID)
@@ -395,7 +395,7 @@
            }
            bindPassword = unencoded.substring(colon + 1);
          }
        } catch (ParseException ex) {
        } catch (final LocalizedIllegalArgumentException ex) {
          // user/DN:password parsing error
          batchResponses.add(
            createErrorResponse(objFactory,
opendj-server-legacy/pom.xml
@@ -105,6 +105,12 @@
    </dependency>
    <dependency>
      <groupId>org.forgerock.opendj</groupId>
      <artifactId>opendj-ldap-toolkit</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>org.forgerock</groupId>
      <artifactId>forgerock-build-tools</artifactId>
    </dependency>
opendj-server-legacy/resource/bin/base64
File was deleted
opendj-server-legacy/resource/bin/base64.bat
File was deleted
opendj-server-legacy/resource/bin/ldapcompare
File was deleted
opendj-server-legacy/resource/bin/ldapcompare.bat
File was deleted
opendj-server-legacy/resource/bin/ldapdelete
File was deleted
opendj-server-legacy/resource/bin/ldapdelete.bat
File was deleted
opendj-server-legacy/resource/bin/ldapmodify
File was deleted
opendj-server-legacy/resource/bin/ldapmodify.bat
File was deleted
opendj-server-legacy/resource/bin/ldappasswordmodify
File was deleted
opendj-server-legacy/resource/bin/ldappasswordmodify.bat
File was deleted
opendj-server-legacy/resource/bin/ldapsearch
File was deleted
opendj-server-legacy/resource/bin/ldapsearch.bat
File was deleted
opendj-server-legacy/resource/bin/ldif-diff
File was deleted
opendj-server-legacy/resource/bin/ldif-diff.bat
File was deleted
opendj-server-legacy/resource/bin/ldifmodify
File was deleted
opendj-server-legacy/resource/bin/ldifmodify.bat
File was deleted
opendj-server-legacy/resource/bin/ldifsearch
File was deleted
opendj-server-legacy/resource/bin/ldifsearch.bat
File was deleted
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/datamodel/BinaryValue.java
@@ -21,7 +21,7 @@
import java.text.ParseException;
import java.util.Objects;
import org.opends.server.util.Base64;
import org.forgerock.opendj.ldap.Base64;
/**
 * Class used to represent Binary Values.  This is required in particular
@@ -123,7 +123,7 @@
  {
    if (bytes == null && base64 != null)
    {
      bytes = Base64.decode(base64);
      bytes = Base64.decode(base64).toByteArray();
    }
    return bytes;
  }
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/task/ResetUserPasswordTask.java
@@ -32,9 +32,14 @@
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.Filter;
import org.forgerock.opendj.ldap.LdapException;
import org.forgerock.opendj.ldap.requests.PasswordModifyExtendedRequest;
import org.forgerock.opendj.ldap.requests.Requests;
import org.forgerock.opendj.ldap.requests.SearchRequest;
import org.forgerock.opendj.ldap.responses.PasswordModifyExtendedResult;
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
import org.forgerock.opendj.ldif.ConnectionEntryReader;
import org.forgerock.util.promise.ExceptionHandler;
import org.forgerock.util.promise.ResultHandler;
import org.opends.admin.ads.util.ConnectionWrapper;
import org.opends.guitools.controlpanel.browser.BrowserController;
import org.opends.guitools.controlpanel.browser.ConnectionWithControls;
@@ -43,7 +48,6 @@
import org.opends.guitools.controlpanel.datamodel.ControlPanelInfo;
import org.opends.guitools.controlpanel.ui.ProgressDialog;
import org.opends.guitools.controlpanel.ui.nodes.BasicNode;
import org.opends.server.tools.LDAPPasswordModify;
/** The task called when we want to reset the password of the user. */
public class ResetUserPasswordTask extends Task
@@ -176,39 +180,61 @@
  {
    state = State.RUNNING;
    lastException = null;
    try
    {
      List<String> arguments = getCommandLineArguments();
      String[] args = arguments.toArray(new String[arguments.size()]);
      returnCode = LDAPPasswordModify.mainPasswordModify(args, false,
            outPrintStream, errorPrintStream);
      if (returnCode != 0)
      final ConnectionWrapper connectionWrapper = useAdminCtx ? getInfo().getConnection()
                                                              : getInfo().getUserDataConnection();
      if (!isServerRunning() || connectionWrapper == null)
      {
        // Fail fast impossible to connect to the server.
        state = State.FINISHED_WITH_ERROR;
      }
      final PasswordModifyExtendedRequest passwordModifyRequest = Requests.newPasswordModifyExtendedRequest();
      if (currentPassword == null)
      {
        passwordModifyRequest.setUserIdentity("dn: " + dn);
      }
      else
      {
        if (lastException == null && currentPassword != null)
        {
          // The connections must be updated, just update the environment, which
          // is what we use to clone connections and to launch scripts.
          // The environment will also be used if we want to reconnect.
          rebind(getInfo().getConnection());
          if (getInfo().getUserDataConnection() != null)
          {
            rebind(getInfo().getUserDataConnection());
          }
        }
        state = State.FINISHED_SUCCESSFULLY;
        passwordModifyRequest.setOldPassword(currentPassword);
      }
    }
    catch (Throwable t)
    {
      lastException = t;
      state = State.FINISHED_WITH_ERROR;
    }
      passwordModifyRequest.setNewPassword(newPassword);
      connectionWrapper.getConnection()
                       .extendedRequestAsync(passwordModifyRequest)
                       .thenOnResultOrException(
                         new ResultHandler<PasswordModifyExtendedResult>()
                         {
                           @Override
                           public void handleResult(final PasswordModifyExtendedResult passwordModifyExtendedResult)
                           {
                             if (lastException == null && currentPassword != null)
                             {
                               try
                               {
                                 // The connections must be updated, just update the environment, which
                                 // is what we use to clone connections and to launch scripts.
                                 // The environment will also be used if we want to reconnect.
                                 rebind(getInfo().getConnection());
                                 if (getInfo().getUserDataConnection() != null)
                                 {
                                   rebind(getInfo().getUserDataConnection());
                                 }
                               }
                               catch (final LdapException e)
                               {
                                 lastException = e;
                                 state = State.FINISHED_WITH_ERROR;
                               }
                             }
                             state = State.FINISHED_SUCCESSFULLY;
                           }
                         },
                         new ExceptionHandler<LdapException>()
                         {
                           @Override
                           public void handleException(final LdapException e)
                           {
                             state = State.FINISHED_WITH_ERROR;
                           }
                         });
  }
  private void rebind(ConnectionWrapper conn) throws LdapException
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/JavaPropertiesPanel.java
@@ -109,14 +109,14 @@
        "list-backends", "manage-account", "manage-tasks", "restore.online",
        "stop-ds", "status", "control-panel", "uninstall", "setup",
        "backup.offline", "encode-password", "export-ldif.offline",
        "ldif-diff", "ldifmodify", "ldifsearch", "makeldif",
        "ldifdiff", "ldifmodify", "ldifsearch", "makeldif",
        "rebuild-index", "restore.offline", "upgrade",
        "verify-index", "backendstat"
      );
  private final Set<String> relevantScriptNames = newHashSet(
        "start-ds", "import-ldif.offline", "backup.offline",
        "export-ldif.offline",
        "ldif-diff", "makeldif", "rebuild-index", "restore.offline",
        "ldifdiff", "makeldif", "rebuild-index", "restore.offline",
        "verify-index", "backendstat"
      );
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
@@ -86,7 +86,6 @@
import org.opends.server.tools.BackendTypeHelper;
import org.opends.server.tools.BackendTypeHelper.BackendTypeUIAdapter;
import org.opends.server.tools.ImportLDIF;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.makeldif.EntryWriter;
import org.opends.server.tools.makeldif.MakeLDIFException;
import org.opends.server.tools.makeldif.TemplateEntry;
@@ -839,7 +838,6 @@
        else
        {
          // If we are not local, we use ldapmodify to update the contents.
          args.add("-a");
          args.add("-f");
          args.add(ldifFile);
        }
@@ -1197,16 +1195,9 @@
        }
        try
        {
          if (isServerRunning())
          if (isServerRunning() && (isLocal() || importLDIF))
          {
            if (isLocal() || importLDIF)
            {
              returnCode = ImportLDIF.mainImportLDIF(args, false, outPrintStream, errorPrintStream);
            }
            else
            {
              returnCode = LDAPModify.mainModify(args, false, outPrintStream, errorPrintStream);
            }
            returnCode = ImportLDIF.mainImportLDIF(args, false, outPrintStream, errorPrintStream);
          }
          else
          {
opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/ViewEntryPanel.java
@@ -38,6 +38,7 @@
import org.forgerock.opendj.ldap.AVA;
import org.forgerock.opendj.ldap.Attribute;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.Entry;
@@ -55,7 +56,6 @@
import org.opends.server.schema.SchemaConstants;
import org.opends.server.types.OpenDsException;
import org.forgerock.opendj.ldap.schema.Schema;
import org.opends.server.util.Base64;
/**
 * Abstract class containing code shared by the different LDAP entry view
opendj-server-legacy/src/main/java/org/opends/server/config/ConfigurationHandler.java
@@ -26,6 +26,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
@@ -36,7 +37,6 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -80,6 +80,8 @@
import org.forgerock.opendj.ldap.schema.Schema;
import org.forgerock.opendj.ldap.schema.SchemaBuilder;
import org.forgerock.opendj.ldif.EntryReader;
import org.forgerock.opendj.ldif.LDIF;
import org.forgerock.opendj.ldif.LDIFChangeRecordReader;
import org.forgerock.opendj.ldif.LDIFEntryReader;
import org.forgerock.opendj.ldif.LDIFEntryWriter;
import org.forgerock.util.Utils;
@@ -89,16 +91,12 @@
import org.opends.server.core.SearchOperation;
import org.opends.server.core.ServerContext;
import org.opends.server.schema.GeneralizedTimeSyntax;
import org.opends.server.tools.LDIFModify;
import org.opends.server.types.DirectoryEnvironmentConfig;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.ExistingFileBehavior;
import org.opends.server.types.InitializationException;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.util.LDIFException;
import org.opends.server.util.LDIFReader;
import org.opends.server.util.LDIFWriter;
import org.opends.server.util.TimeThread;
/**
@@ -1576,33 +1574,17 @@
   */
  private void applyChangesFile(File sourceFile, File changesFile) throws IOException, LDIFException
  {
    // Create the appropriate LDIF readers and writer.
    LDIFImportConfig sourceImportCfg = new LDIFImportConfig(sourceFile.getAbsolutePath());
    sourceImportCfg.setValidateSchema(false);
    LDIFImportConfig changesImportCfg = new LDIFImportConfig(changesFile.getAbsolutePath());
    changesImportCfg.setValidateSchema(false);
    String tempFile = changesFile.getAbsolutePath() + ".tmp";
    LDIFExportConfig exportConfig = new LDIFExportConfig(tempFile, ExistingFileBehavior.OVERWRITE);
    List<LocalizableMessage> errorList = new LinkedList<>();
    boolean successful;
    try (LDIFReader sourceReader = new LDIFReader(sourceImportCfg);
        LDIFReader changesReader = new LDIFReader(changesImportCfg);
        LDIFWriter targetWriter = new LDIFWriter(exportConfig))
    final String tempFilePath = changesFile.getAbsolutePath() + ".tmp";
    try (final LDIFEntryReader sourceReader = new LDIFEntryReader(new FileReader(sourceFile));
         final LDIFChangeRecordReader changeRecordReader = new LDIFChangeRecordReader(new FileReader(changesFile));
         final LDIFEntryWriter ldifWriter = new LDIFEntryWriter(new FileWriter(tempFilePath)))
    {
      // Apply the changes and make sure there were no errors.
      successful = LDIFModify.modifyLDIF(sourceReader, changesReader, targetWriter, errorList);
      LDIF.copyTo(LDIF.patch(sourceReader, changeRecordReader), ldifWriter);
    }
    if (!successful)
    catch (final IOException e)
    {
      for (LocalizableMessage s : errorList)
      {
        logger.error(ERR_CONFIG_ERROR_APPLYING_STARTUP_CHANGE, s);
      }
      throw new LDIFException(ERR_CONFIG_UNABLE_TO_APPLY_CHANGES_FILE.get(Utils.joinAsString("; ", errorList)));
      throw new LDIFException(ERR_CONFIG_UNABLE_TO_APPLY_CHANGES_FILE.get(e.getLocalizedMessage()));
    }
    // Move the current config file out of the way and replace it with the updated version.
@@ -1612,7 +1594,7 @@
      oldSource.delete();
    }
    sourceFile.renameTo(oldSource);
    new File(tempFile).renameTo(sourceFile);
    new File(tempFilePath).renameTo(sourceFile);
    // Move the changes file out of the way so it doesn't get applied again.
    File newChanges = new File(changesFile.getAbsolutePath() + ".applied");
opendj-server-legacy/src/main/java/org/opends/server/crypto/CryptoManagerImpl.java
@@ -67,6 +67,7 @@
import org.forgerock.opendj.config.server.ConfigChangeResult;
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.config.server.ConfigurationChangeListener;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ModificationType;
@@ -108,7 +109,6 @@
import org.opends.server.types.InitializationException;
import org.opends.server.types.Modification;
import org.opends.server.types.SearchResultEntry;
import org.opends.server.util.Base64;
import org.opends.server.util.SelectableCertificateKeyManager;
import org.opends.server.util.ServerConstants;
import org.opends.server.util.StaticUtils;
@@ -385,7 +385,7 @@
                "jucN34MZwvzbmFHT/leUu3/cpykbGM9HL2QUX7iKvv2LJVqexhj7CLoXxZP" +
                "oNL+HHKW0vi5/7W5KwOZsPqKI2SdYV7nDqTZklm5ZP0gmIuNO6mTqBRtC2D" +
                "lplX1Iq+BrQJAmteiPtwhdZD+EIghe51CaseImjlLlY2ZK8w==";
          final byte[] certificate = Base64.decode(certificateBase64);
          final byte[] certificate = Base64.decode(certificateBase64).toByteArray();
          final String keyID = getInstanceKeyID(certificate);
          final SecretKey macKey = macCryptoManager.generateKeyEntry(
                  requestedMACAlgorithm,
opendj-server-legacy/src/main/java/org/opends/server/extensions/AESPasswordStorageScheme.java
@@ -17,6 +17,7 @@
package org.opends.server.extensions;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.AESPasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -26,7 +27,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import java.util.Arrays;
@@ -153,7 +153,7 @@
    {
      ByteString decryptedPassword =
          ByteString.wrap(cryptoManager.decrypt(
               Base64.decode(storedPassword.toString())));
                  Base64.decode(storedPassword.toString()).toByteArray()));
      return plaintextPassword.equals(decryptedPassword);
    }
    catch (Exception e)
@@ -177,7 +177,7 @@
    try
    {
      byte[] decryptedPassword =
           cryptoManager.decrypt(Base64.decode(storedPassword.toString()));
           cryptoManager.decrypt(Base64.decode(storedPassword.toString()).toByteArray());
      return ByteString.wrap(decryptedPassword);
    }
    catch (Exception e)
opendj-server-legacy/src/main/java/org/opends/server/extensions/Base64PasswordStorageScheme.java
@@ -17,6 +17,7 @@
package org.opends.server.extensions;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.Base64PasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -25,7 +26,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import static org.opends.messages.ExtensionMessages.*;
import static org.opends.server.extensions.ExtensionsConstants.*;
@@ -106,7 +106,7 @@
  {
    try
    {
      return ByteString.wrap(Base64.decode(storedPassword.toString()));
      return ByteString.wrap(Base64.decode(storedPassword.toString()).toByteArray());
    }
    catch (Exception e)
    {
opendj-server-legacy/src/main/java/org/opends/server/extensions/BlowfishPasswordStorageScheme.java
@@ -17,6 +17,7 @@
package org.opends.server.extensions;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.BlowfishPasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -26,7 +27,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import java.util.Arrays;
@@ -152,10 +152,8 @@
  {
    try
    {
      ByteString decryptedPassword =
          ByteString.wrap(cryptoManager.decrypt(
               Base64.decode(storedPassword.toString())));
      return plaintextPassword.equals(decryptedPassword);
      return plaintextPassword.equals(ByteString.wrap(
              cryptoManager.decrypt(Base64.decode(storedPassword.toString()).toByteArray())));
    }
    catch (Exception e)
    {
@@ -178,7 +176,7 @@
    try
    {
      byte[] decryptedPassword =
           cryptoManager.decrypt(Base64.decode(storedPassword.toString()));
           cryptoManager.decrypt(Base64.decode(storedPassword.toString()).toByteArray());
      return ByteString.wrap(decryptedPassword);
    }
    catch (Exception e)
opendj-server-legacy/src/main/java/org/opends/server/extensions/MD5PasswordStorageScheme.java
@@ -20,6 +20,7 @@
import java.util.Arrays;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.MD5PasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -29,7 +30,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import static org.opends.messages.ExtensionMessages.*;
import static org.opends.server.extensions.ExtensionsConstants.*;
@@ -210,7 +210,7 @@
    try
    {
      storedPWDigestBytes =
          ByteString.wrap(Base64.decode(storedPassword.toString()));
          ByteString.wrap(Base64.decode(storedPassword.toString()).toByteArray());
    }
    catch (Exception e)
    {
opendj-server-legacy/src/main/java/org/opends/server/extensions/PBKDF2PasswordStorageScheme.java
@@ -27,6 +27,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ResultCode;
@@ -37,7 +38,6 @@
import org.forgerock.opendj.config.server.ConfigChangeResult;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.util.Base64;
import static org.opends.messages.ExtensionMessages.*;
import static org.opends.server.extensions.ExtensionsConstants.*;
@@ -155,7 +155,7 @@
      }
      final int iterations = Integer.parseInt(stored.substring(0, pos));
      byte[] decodedBytes = Base64.decode(stored.substring(pos + 1));
      byte[] decodedBytes = Base64.decode(stored.substring(pos + 1)).toByteArray();
      final int saltLength = decodedBytes.length - SHA1_LENGTH;
      if (saltLength <= 0)
@@ -214,8 +214,8 @@
        throw new Exception();
      }
      int iterations = Integer.parseInt(authInfo.substring(0, pos));
      byte[] saltBytes   = Base64.decode(authInfo.substring(pos + 1));
      byte[] digestBytes = Base64.decode(authValue);
      byte[] saltBytes   = Base64.decode(authInfo.substring(pos + 1)).toByteArray();
      byte[] digestBytes = Base64.decode(authValue).toByteArray();
      return encodeAndMatch(plaintextPassword, saltBytes, digestBytes, iterations);
    }
    catch (Exception e)
opendj-server-legacy/src/main/java/org/opends/server/extensions/PKCS5S2PasswordStorageScheme.java
@@ -26,6 +26,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ResultCode;
@@ -34,7 +35,6 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.util.Base64;
import static org.opends.messages.ExtensionMessages.*;
import static org.opends.server.extensions.ExtensionsConstants.*;
@@ -126,7 +126,7 @@
    try
    {
      String stored = storedPassword.toString();
      byte[] decodedBytes = Base64.decode(stored);
      byte[] decodedBytes = Base64.decode(stored).toByteArray();
      if (decodedBytes.length != NUM_SALT_BYTES + SHA1_LENGTH)
      {
@@ -183,8 +183,8 @@
        throw new Exception();
      }
      int iterations = Integer.parseInt(authInfo.substring(0, pos));
      byte[] saltBytes   = Base64.decode(authInfo.substring(pos + 1));
      byte[] digestBytes = Base64.decode(authValue);
      byte[] saltBytes   = Base64.decode(authInfo.substring(pos + 1)).toByteArray();
      byte[] digestBytes = Base64.decode(authValue).toByteArray();
      return encodeAndMatch(plaintextPassword, saltBytes, digestBytes, iterations);
    }
    catch (Exception e)
opendj-server-legacy/src/main/java/org/opends/server/extensions/RC4PasswordStorageScheme.java
@@ -17,6 +17,7 @@
package org.opends.server.extensions;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.RC4PasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -26,7 +27,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import java.util.Arrays;
@@ -152,10 +152,8 @@
  {
    try
    {
      ByteString decryptedPassword =
          ByteString.wrap(cryptoManager.decrypt(
               Base64.decode(storedPassword.toString())));
      return plaintextPassword.equals(decryptedPassword);
      return plaintextPassword.equals(ByteString.wrap(
              cryptoManager.decrypt(Base64.decode(storedPassword.toString()).toByteArray())));
    }
    catch (Exception e)
    {
@@ -178,7 +176,7 @@
    try
    {
      byte[] decryptedPassword =
           cryptoManager.decrypt(Base64.decode(storedPassword.toString()));
           cryptoManager.decrypt(Base64.decode(storedPassword.toString()).toByteArray());
      return ByteString.wrap(decryptedPassword);
    }
    catch (Exception e)
opendj-server-legacy/src/main/java/org/opends/server/extensions/SHA1PasswordStorageScheme.java
@@ -20,6 +20,7 @@
import java.util.Arrays;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.SHA1PasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -29,7 +30,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import static org.opends.messages.ExtensionMessages.*;
import static org.opends.server.extensions.ExtensionsConstants.*;
@@ -210,7 +210,7 @@
    try
    {
      storedPWDigestBytes =
          ByteString.wrap(Base64.decode(storedPassword.toString()));
          ByteString.wrap(Base64.decode(storedPassword.toString()).toByteArray());
    }
    catch (Exception e)
    {
opendj-server-legacy/src/main/java/org/opends/server/extensions/SaltedMD5PasswordStorageScheme.java
@@ -21,6 +21,7 @@
import java.util.Random;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.SaltedMD5PasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -30,7 +31,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import static org.opends.messages.ExtensionMessages.*;
import static org.opends.server.extensions.ExtensionsConstants.*;
@@ -222,7 +222,7 @@
    int saltLength = 0;
    try
    {
      byte[] decodedBytes = Base64.decode(storedPassword.toString());
      byte[] decodedBytes = Base64.decode(storedPassword.toString()).toByteArray();
      saltLength = decodedBytes.length - MD5_LENGTH;
      if (saltLength <= 0)
@@ -343,8 +343,8 @@
    byte[] digestBytes;
    try
    {
      saltBytes   = Base64.decode(authInfo);
      digestBytes = Base64.decode(authValue);
      saltBytes   = Base64.decode(authInfo).toByteArray();
      digestBytes = Base64.decode(authValue).toByteArray();
    }
    catch (Exception e)
    {
opendj-server-legacy/src/main/java/org/opends/server/extensions/SaltedSHA1PasswordStorageScheme.java
@@ -21,6 +21,7 @@
import java.util.Random;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.SaltedSHA1PasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -30,7 +31,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import static org.opends.messages.ExtensionMessages.*;
import static org.opends.server.extensions.ExtensionsConstants.*;
@@ -222,7 +222,7 @@
    int saltLength = 0;
    try
    {
      byte[] decodedBytes = Base64.decode(storedPassword.toString());
      byte[] decodedBytes = Base64.decode(storedPassword.toString()).toByteArray();
      saltLength = decodedBytes.length - SHA1_LENGTH;
      if (saltLength <= 0)
@@ -343,8 +343,8 @@
    byte[] digestBytes;
    try
    {
      saltBytes   = Base64.decode(authInfo);
      digestBytes = Base64.decode(authValue);
      saltBytes   = Base64.decode(authInfo).toByteArray();
      digestBytes = Base64.decode(authValue).toByteArray();
    }
    catch (Exception e)
    {
@@ -450,6 +450,6 @@
    Arrays.fill(passwordPlusSalt, (byte) 0);
    return "{" + STORAGE_SCHEME_NAME_SALTED_SHA_1 + "}" +
           Base64.encode(digestPlusSalt);
            Base64.encode(digestPlusSalt);
  }
}
opendj-server-legacy/src/main/java/org/opends/server/extensions/SaltedSHA256PasswordStorageScheme.java
@@ -21,6 +21,7 @@
import java.util.Random;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.SaltedSHA256PasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -30,7 +31,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import static org.opends.messages.ExtensionMessages.*;
import static org.opends.server.extensions.ExtensionsConstants.*;
@@ -226,7 +226,7 @@
    try
    {
      byte[] decodedBytes = Base64.decode(storedPassword.toString());
      byte[] decodedBytes = Base64.decode(storedPassword.toString()).toByteArray();
      saltLength = decodedBytes.length - SHA256_LENGTH;
      if (saltLength <= 0)
@@ -347,8 +347,8 @@
    byte[] digestBytes;
    try
    {
      saltBytes   = Base64.decode(authInfo);
      digestBytes = Base64.decode(authValue);
      saltBytes   = Base64.decode(authInfo).toByteArray();
      digestBytes = Base64.decode(authValue).toByteArray();
    }
    catch (Exception e)
    {
opendj-server-legacy/src/main/java/org/opends/server/extensions/SaltedSHA384PasswordStorageScheme.java
@@ -21,6 +21,7 @@
import java.util.Random;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.SaltedSHA384PasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -30,7 +31,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import static org.opends.messages.ExtensionMessages.*;
import static org.opends.server.extensions.ExtensionsConstants.*;
@@ -226,7 +226,7 @@
    try
    {
      byte[] decodedBytes = Base64.decode(storedPassword.toString());
      byte[] decodedBytes = Base64.decode(storedPassword.toString()).toByteArray();
      saltLength = decodedBytes.length - SHA384_LENGTH;
      if (saltLength <= 0)
@@ -347,8 +347,8 @@
    byte[] digestBytes;
    try
    {
      saltBytes   = Base64.decode(authInfo);
      digestBytes = Base64.decode(authValue);
      saltBytes   = Base64.decode(authInfo).toByteArray();
      digestBytes = Base64.decode(authValue).toByteArray();
    }
    catch (Exception e)
    {
opendj-server-legacy/src/main/java/org/opends/server/extensions/SaltedSHA512PasswordStorageScheme.java
@@ -21,6 +21,7 @@
import java.util.Random;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.SaltedSHA512PasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -30,7 +31,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import static org.opends.messages.ExtensionMessages.*;
import static org.opends.server.extensions.ExtensionsConstants.*;
@@ -226,7 +226,7 @@
    try
    {
      byte[] decodedBytes = Base64.decode(storedPassword.toString());
      byte[] decodedBytes = Base64.decode(storedPassword.toString()).toByteArray();
      saltLength = decodedBytes.length - SHA512_LENGTH;
      if (saltLength <= 0)
@@ -347,8 +347,8 @@
    byte[] digestBytes;
    try
    {
      saltBytes   = Base64.decode(authInfo);
      digestBytes = Base64.decode(authValue);
      saltBytes   = Base64.decode(authInfo).toByteArray();
      digestBytes = Base64.decode(authValue).toByteArray();
    }
    catch (Exception e)
    {
@@ -455,6 +455,6 @@
    Arrays.fill(passwordPlusSalt, (byte) 0);
    return "{" + STORAGE_SCHEME_NAME_SALTED_SHA_512 + "}" +
           Base64.encode(digestPlusSalt);
            Base64.encode(digestPlusSalt);
  }
}
opendj-server-legacy/src/main/java/org/opends/server/extensions/TripleDESPasswordStorageScheme.java
@@ -17,6 +17,7 @@
package org.opends.server.extensions;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.server.config.server.TripleDESPasswordStorageSchemeCfg;
import org.opends.server.api.PasswordStorageScheme;
import org.forgerock.opendj.config.server.ConfigException;
@@ -26,7 +27,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteSequence;
import org.opends.server.util.Base64;
import java.util.Arrays;
@@ -152,10 +152,8 @@
  {
    try
    {
      ByteString decryptedPassword =
          ByteString.wrap(cryptoManager.decrypt(
               Base64.decode(storedPassword.toString())));
      return plaintextPassword.equals(decryptedPassword);
      return plaintextPassword.equals(ByteString.wrap(
              cryptoManager.decrypt(Base64.decode(storedPassword.toString()).toByteArray())));
    }
    catch (Exception e)
    {
@@ -178,7 +176,7 @@
    try
    {
      byte[] decryptedPassword =
           cryptoManager.decrypt(Base64.decode(storedPassword.toString()));
           cryptoManager.decrypt(Base64.decode(storedPassword.toString()).toByteArray());
      return ByteString.wrap(decryptedPassword);
    }
    catch (Exception e)
opendj-server-legacy/src/main/java/org/opends/server/loggers/TextAuditLogPublisher.java
@@ -28,6 +28,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.config.server.ConfigChangeResult;
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
@@ -45,7 +46,6 @@
import org.opends.server.types.InitializationException;
import org.opends.server.types.Modification;
import org.opends.server.types.Operation;
import org.opends.server.util.Base64;
import org.opends.server.util.StaticUtils;
import org.opends.server.util.TimeThread;
opendj-server-legacy/src/main/java/org/opends/server/protocols/ldap/AddRequestProtocolOp.java
@@ -12,7 +12,7 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2006-2008 Sun Microsystems, Inc.
 * Portions Copyright 2013-2015 ForgeRock AS.
 * Portions Copyright 2013-2016 ForgeRock AS.
 */
package org.opends.server.protocols.ldap;
@@ -23,9 +23,9 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.types.RawAttribute;
import org.opends.server.util.Base64;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import static org.opends.server.util.ServerConstants.*;
opendj-server-legacy/src/main/java/org/opends/server/protocols/ldap/SearchResultEntryProtocolOp.java
@@ -31,6 +31,7 @@
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.schema.AttributeType;
@@ -41,7 +42,6 @@
import org.opends.server.types.Entry;
import org.opends.server.types.LDAPException;
import org.opends.server.types.SearchResultEntry;
import org.opends.server.util.Base64;
/**
 * This class defines the structures and methods for an LDAP search result entry
opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaFilesWriter.java
@@ -57,6 +57,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.AVA;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ModificationType;
@@ -79,7 +80,6 @@
import org.opends.server.types.InitializationException;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.Modification;
import org.opends.server.util.Base64;
import org.opends.server.util.BuildVersion;
import org.opends.server.util.LDIFException;
import org.opends.server.util.LDIFWriter;
@@ -481,7 +481,7 @@
      // See OPENDJ-2792: the definition of the ds-cfg-csv-delimiter-char attribute type
      // had a space accidentally added after the closing parenthesis.
      // This was unfortunately interpreted as base64
      definition = ByteString.wrap(Base64.decode(definition.substring(2).trim())).toString();
      definition = ByteString.wrap(Base64.decode(definition.substring(2).trim()).toByteArray()).toString();
    }
    else if (definition.startsWith(":"))
    {
opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureWindowsService.java
@@ -576,7 +576,7 @@
   */
  public static int serviceState()
  {
    return serviceState(NullOutputStream.printStream(), NullOutputStream.printStream());
    return serviceState(NullOutputStream.nullPrintStream(), NullOutputStream.nullPrintStream());
  }
  /**
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPAuthenticationHandler.java
@@ -56,6 +56,7 @@
import org.forgerock.i18n.LocalizableMessageDescriptor.Arg0;
import org.forgerock.i18n.LocalizableMessageDescriptor.Arg1;
import org.forgerock.i18n.LocalizableMessageDescriptor.Arg2;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DecodeException;
@@ -66,7 +67,6 @@
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.types.Control;
import org.opends.server.types.LDAPException;
import org.opends.server.util.Base64;
import com.forgerock.opendj.cli.ClientException;
import com.forgerock.opendj.cli.ConsoleApplication;
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPCompare.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPCompareOptions.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPDelete.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPDeleteOptions.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPModify.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPModifyOptions.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPPasswordModify.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPSearch.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPSearchOptions.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPToolOptions.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPToolUtils.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFDiff.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFModify.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFSearch.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/tools/StopDS.java
@@ -366,7 +366,7 @@
    if (quietMode.isPresent())
    {
      out = NullOutputStream.printStream();
      out = NullOutputStream.nullPrintStream();
    }
    if (checkStoppability.isPresent())
opendj-server-legacy/src/main/java/org/opends/server/types/BackupInfo.java
@@ -33,7 +33,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.server.ConfigException;
import org.opends.server.util.Base64;
import org.forgerock.opendj.ldap.Base64;
/**
 * This class defines a data structure for holding information about a
@@ -453,11 +453,11 @@
        }
        else if (name.equals(PROPERTY_UNSIGNED_HASH))
        {
          unsignedHash = Base64.decode(value);
          unsignedHash = Base64.decode(value).toByteArray();
        }
        else if (name.equals(PROPERTY_SIGNED_HASH))
        {
          signedHash = Base64.decode(value);
          signedHash = Base64.decode(value).toByteArray();
        }
        else if (name.equals(PROPERTY_DEPENDENCY))
        {
opendj-server-legacy/src/main/java/org/opends/server/types/NullOutputStream.java
@@ -12,7 +12,7 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2006-2008 Sun Microsystems, Inc.
 * Portions Copyright 2013 ForgeRock AS.
 * Portions Copyright 2013-2016 ForgeRock AS.
 */
package org.opends.server.types;
@@ -64,7 +64,7 @@
   *
   * @return  A print stream using this null output stream.
   */
  public static PrintStream printStream()
  public static PrintStream nullPrintStream()
  {
    return printStream;
  }
@@ -72,12 +72,12 @@
  /**
   * Returns s wrapped into a {@link PrintStream} if is not null,
   * {@link NullOutputStream#printStream()} otherwise.
   * {@link NullOutputStream#nullPrintStream()} otherwise.
   *
   * @param s
   *          the OutputStream to wrap into a {@link PrintStream}. Can be null.
   * @return a PrintStream wrapping s if not null,
   *         {@link NullOutputStream#printStream()} otherwise.
   *         {@link NullOutputStream#nullPrintStream()} otherwise.
   */
  public static PrintStream wrapOrNullStream(OutputStream s)
  {
@@ -85,7 +85,7 @@
    {
      return new PrintStream(s);
    }
    return NullOutputStream.printStream();
    return NullOutputStream.nullPrintStream();
  }
opendj-server-legacy/src/main/java/org/opends/server/util/Base64.java
File was deleted
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFReader.java
@@ -39,6 +39,7 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.AVA;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.forgerock.opendj.ldap.DN;
@@ -599,7 +600,7 @@
  {
    try
    {
      return new String(Base64.decode(encodedStr), "UTF-8");
      return new String(Base64.decode(encodedStr).toByteArray(), "UTF-8");
    }
    catch (Exception e)
    {
@@ -1379,7 +1380,7 @@
        try
        {
          value = ByteString.wrap(Base64.decode(line.substring(pos)));
          value = ByteString.wrap(Base64.decode(line.substring(pos)).toByteArray());
        }
        catch (Exception e)
        {
opendj-server-legacy/src/main/java/org/opends/server/util/LDIFWriter.java
@@ -25,6 +25,7 @@
import java.util.regex.Pattern;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java
@@ -24,11 +24,13 @@
import static org.opends.server.loggers.TextAccessLogPublisher.getStartupTextAccessPublisher;
import static org.opends.server.loggers.TextErrorLogPublisher.getToolStartupTextErrorPublisher;
import static org.opends.server.loggers.TextHTTPAccessLogPublisher.getStartupTextHTTPAccessPublisher;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.ServerConstants.PROPERTY_RUNNING_UNIT_TESTS;
import static org.testng.Assert.assertTrue;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -67,6 +69,7 @@
import java.util.logging.LogManager;
import java.util.logging.Logger;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.config.dsconfig.DSConfig;
import org.forgerock.opendj.config.server.ConfigException;
@@ -98,7 +101,7 @@
import org.opends.server.protocols.ldap.BindResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.protocols.ldap.LDAPReader;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.types.Attribute;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
@@ -1460,7 +1463,6 @@
      "-p", String.valueOf(ports.serverLdapPort),
      "-D", "cn=Directory Manager",
      "-w", "password",
      "-a",
      "-f", path
    };
    String[] adminArgs =
@@ -1471,14 +1473,13 @@
      "-Z", "-X",
      "-D", "cn=Directory Manager",
      "-w", "password",
      "-a",
      "-f", path
    };
    if (useAdminPort) {
      return LDAPModify.mainModify(adminArgs, false, null, null);
      return LDAPModify.run(nullPrintStream(), nullPrintStream(), adminArgs);
    }
    return LDAPModify.mainModify(args, false, null, null);
    return LDAPModify.run(nullPrintStream(), nullPrintStream(), args);
  }
  /**
@@ -1923,4 +1924,29 @@
      return;
    }
  }
  public static int runLdapSearchTrustCertificateForSession(final String[] args)
  {
    return runLdapSearchTrustCertificateForSession(nullPrintStream(), System.err, args);
  }
  public static int runLdapSearchTrustCertificateForSession(final PrintStream out,
                                                            final PrintStream err,
                                                            final String[] args)
  {
    final InputStream stdin = System.in;
    try
    {
      // Since hostnames are different between the client.truststore (CN=OpenDJ Test Certificate, O=OpenDJ.org) and the
      // one given in parameter (127.0.0.1), ldapsearch tool prompt user to know what to do (either untrust the server
      // certificate, trust it for the session only or trust it permanently).
      // Default option is session trust, we just hit enter in stdin to have a non blocking unit test.
      System.setIn(new ByteArrayInputStream(System.lineSeparator().getBytes()));
      return LDAPSearch.run(nullPrintStream(), System.err, args);
    }
    finally
    {
      System.setIn(stdin);
    }
  }
}
opendj-server-legacy/src/test/java/org/opends/server/api/PasswordValidatorTestCase.java
@@ -19,6 +19,7 @@
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
import java.util.Set;
@@ -29,7 +30,7 @@
import org.opends.server.extensions.TestPasswordValidator;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.protocols.ldap.ModifyResponseProtocolOp;
import org.opends.server.tools.LDAPPasswordModify;
import com.forgerock.opendj.ldap.tools.LDAPPasswordModify;
import org.opends.server.tools.RemoteConnection;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -115,8 +116,7 @@
      "-c", "password",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null),
                 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    assertEquals(TestPasswordValidator.getLastNewPassword(),
                 ByteString.valueOfUtf8("newPassword"));
@@ -165,8 +165,7 @@
      "-n", "newPassword"
    };
    int returnCode = LDAPPasswordModify.mainPasswordModify(args, false, null,
                                                           null);
    int returnCode = LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args);
    assertNotEquals(returnCode, 0);
    assertEquals(TestPasswordValidator.getLastNewPassword(),
@@ -214,8 +213,7 @@
      "-w", "password",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null),
                 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    Set<ByteString> currentPasswords =
         TestPasswordValidator.getLastCurrentPasswords();
@@ -262,8 +260,7 @@
      "-c", "password",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null),
                 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    Set<ByteString> currentPasswords =
         TestPasswordValidator.getLastCurrentPasswords();
@@ -314,8 +311,7 @@
      "-w", "password",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null),
                 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    Set<ByteString> currentPasswords =
         TestPasswordValidator.getLastCurrentPasswords();
@@ -367,8 +363,7 @@
      "-c", "password",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null),
                 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    Set<ByteString> currentPasswords =
         TestPasswordValidator.getLastCurrentPasswords();
opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/AciTestCase.java
@@ -24,6 +24,7 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
@@ -49,10 +50,10 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyOperation;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.tools.LDAPDelete;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.LDAPPasswordModify;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPDelete;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPPasswordModify;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.types.Attribute;
import org.opends.server.types.Entry;
import org.opends.server.types.Modification;
@@ -190,12 +191,15 @@
      argList.add("-J");
      argList.add(pwdPolicyControl);
    }
    String[] args = new String[argList.size()];
    oStream.reset();
    int ret = LDAPPasswordModify.mainPasswordModify(argList.toArray(args),
                   false, oStream, oStream);
    Assert.assertEquals(ret, expectedRc, "Returned error: " + oStream);
    return oStream.toString();
    try (final PrintStream printStream = new PrintStream(oStream)) {
      int ret = LDAPPasswordModify.run(printStream, printStream, argList.toArray(args));
      final String output = oStream.toString();
      Assert.assertEquals(ret, expectedRc, "ldappasswordmodify output: " + output);
      return output;
    }
  }
  /**
@@ -231,12 +235,9 @@
    }
    argList.add("-f");
    argList.add(tempFile.getAbsolutePath());
    String[] args = new String[argList.size()];
    oStream.reset();
    int retVal =LDAPModify.mainModify(argList.toArray(args), false, oStream, oStream);
    Assert.assertEquals(retVal, 0, "Returned error: " + oStream);
    return oStream.toString();
    return runLdapModify(argList, 0);
  }
  protected String LDAPSearchCtrl(String bindDn, String bindPassword,
@@ -251,7 +252,8 @@
    argList.add(bindDn);
    argList.add("-w");
    argList.add(bindPassword);
    argList.add("-T");
    argList.add("-t");
    argList.add("0");
    if(proxyDN != null) {
      argList.add("-Y");
      argList.add("dn:" + proxyDN);
@@ -266,12 +268,8 @@
    argList.add("sub");
    argList.add(filter);
    Collections.addAll(argList, attr.split("\\s+"));
    String[] args = new String[argList.size()];
    oStream.reset();
    int retVal =
            LDAPSearch.mainSearch(argList.toArray(args), false, oStream, oStream);
    Assert.assertEquals(retVal, 0, "Returned error: " + oStream);
    return oStream.toString();
    return runLdapSearch(argList);
  }
  protected String
@@ -307,7 +305,8 @@
    argList.add(bindDn);
    argList.add("-w");
    argList.add(bindPassword);
    argList.add("-T");
    argList.add("-t");
    argList.add("0");
    if(proxyDN != null) {
      argList.add("-Y");
      argList.add("dn:" + proxyDN);
@@ -336,40 +335,37 @@
    if(attr != null) {
      Collections.addAll(argList, attr.split("\\s+"));
    }
    String[] args = new String[argList.size()];
    oStream.reset();
    int retVal = LDAPSearch.mainSearch(argList.toArray(args), false, oStream, oStream);
    Assert.assertEquals(retVal, expectedRc, "Returned error: " + oStream);
    return oStream.toString();
    return runLdapSearch(argList);
  }
  protected void LDIFAdd(String ldif, String bindDn, String bindPassword,
      String controlStr, int expectedRc) throws Exception
  {
    _LDIFModify(ldif, bindDn, bindPassword, controlStr, true, expectedRc, false);
    _LDIFModify(ldif, bindDn, bindPassword, controlStr, expectedRc, false);
  }
  protected void LDIFModify(String ldif, String bindDn, String bindPassword,
      String controlStr, int expectedRc) throws Exception
  {
    _LDIFModify(ldif, bindDn, bindPassword, controlStr, false, expectedRc, false);
    _LDIFModify(ldif, bindDn, bindPassword, controlStr, expectedRc, false);
  }
  protected void LDIFModify(String ldif, String bindDn, String bindPassword)
  throws Exception {
    _LDIFModify(ldif, bindDn, bindPassword, null, false, -1, false);
    _LDIFModify(ldif, bindDn, bindPassword, null, -1, false);
  }
  protected void LDIFAdminModify (String ldif, String bindDn,
                                  String bindPassword)
  throws Exception {
    _LDIFModify(ldif, bindDn, bindPassword, null, false, -1, true);
    _LDIFModify(ldif, bindDn, bindPassword, null, -1, true);
  }
  protected void LDIFModify(String ldif, String bindDn, String bindPassword,
                            String ctrlString)
  throws Exception {
    _LDIFModify(ldif, bindDn, bindPassword, ctrlString, false, -1, false);
    _LDIFModify(ldif, bindDn, bindPassword, ctrlString, -1, false);
  }
  protected void LDIFDelete(String dn, String bindDn, String bindPassword,
@@ -402,13 +398,16 @@
  private void ldapDelete(String[] args, int expectedRc)
  {
    oStream.reset();
    int retVal = LDAPDelete.mainDelete(args, false, oStream, oStream);
    Assert.assertEquals(retVal, expectedRc, "Returned error: " + oStream);
    try (final PrintStream printStream = new PrintStream(oStream))
    {
      final int retVal = LDAPDelete.run(printStream, printStream, args);
      Assert.assertEquals(retVal, expectedRc, "ldapdelete output: " + oStream.toString());
    }
  }
  private void _LDIFModify(String ldif, String bindDn, String bindPassword,
      String controlStr, boolean add, int expectedRc, boolean useAdminPort)
      String controlStr, int expectedRc, boolean useAdminPort)
      throws Exception
  {
    File tempFile = getTemporaryLdifFile();
@@ -432,13 +431,9 @@
      argList.add("-J");
      argList.add(controlStr);
    }
    if(add) {
     argList.add("-a");
    }
    argList.add("-f");
    argList.add(tempFile.getAbsolutePath());
    String[] args = new String[argList.size()];
    ldapModify(argList.toArray(args), expectedRc);
    runLdapModify(argList, expectedRc);
  }
  protected void JNDIModify(Hashtable<?, ?> env, String name, String attr,
@@ -484,18 +479,7 @@
      }
      argList.add("-f");
      argList.add(tempFile.getAbsolutePath());
      String[] args = new String[argList.size()];
      ldapModify(argList.toArray(args), expectedRc);
  }
  private void ldapModify(String[] args, int expectedRc)
  {
    oStream.reset();
    int retVal =LDAPModify.mainModify(args, false, oStream, oStream);
    if (expectedRc != -1)
    {
      Assert.assertEquals(retVal, expectedRc, "Returned error: " + oStream);
    }
      runLdapModify(argList, expectedRc);
  }
  protected void deleteAttrFromEntry(String dn, String attr) throws Exception {
@@ -802,4 +786,28 @@
    return attrMap;
  }
  private String runLdapModify(final List<String> argList, final int expectedReturnCode)
  {
    try (final PrintStream printStream = new PrintStream(oStream))
    {
      final int retVal = LDAPModify.run(printStream, printStream, argList.toArray(new String[argList.size()]));
      final String output = oStream.toString();
      if (expectedReturnCode != -1)
      {
        Assert.assertEquals(retVal, expectedReturnCode, "ldapmodify output: " + output);
      }
      return output;
    }
  }
  private String runLdapSearch(final List<String> argList)
  {
    try (final PrintStream printStream = new PrintStream(oStream))
    {
      final int retVal = LDAPSearch.run(printStream, printStream, argList.toArray(new String[argList.size()]));
      final String output = oStream.toString();
      Assert.assertEquals(retVal, 0, "ldapsearch output: " + output);
      return output;
    }
  }
}
opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/AciTests.java
@@ -27,7 +27,7 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -41,18 +41,12 @@
import java.util.Set;
import java.util.regex.Pattern;
import org.forgerock.i18n.LocalizableMessage;
import com.forgerock.opendj.ldap.tools.LDAPCompare;
import com.forgerock.opendj.ldap.tools.LDIFDiff;
import org.opends.server.TestCaseUtils;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.tools.LDAPCompare;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.LDAPSearch;
import org.opends.server.tools.LDIFDiff;
import org.opends.server.tools.LDIFModify;
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.util.LDIFReader;
import org.opends.server.util.LDIFWriter;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
@@ -1733,7 +1727,6 @@
         "-p", getServerLdapPort(),
         "-D", _bindDn,
         "-w", _bindPw,
         "--useCompareResultCode",
        attrAssertion,
        _searchBaseDn};
    }
@@ -1760,24 +1753,6 @@
            searchFilter, searchScope, expectedResultsLdif, _initialDitLdif, equivalentAci));
      }
    }
    /**
     * @return the LDIF result of applying changesLdif to changesLdif
     */
    private String applyChangesToLdif(String baseLdif, String changesLdif) throws Exception {
      LDIFReader baseReader = new LDIFReader(new LDIFImportConfig(new StringReader(baseLdif)));
      LDIFReader changesReader = new LDIFReader(new LDIFImportConfig(new StringReader(changesLdif)));
      ByteArrayOutputStream updatedEntriesStream = new ByteArrayOutputStream();
      LDIFWriter ldifWriter = new LDIFWriter(new LDIFExportConfig(updatedEntriesStream));
      List<LocalizableMessage> errors = new ArrayList<>();
      LDIFModify.modifyLDIF(baseReader, changesReader, ldifWriter, errors);
      Assert.assertTrue(errors.isEmpty(), "Unexpected errors applying LDIF changes: " + errors);
      ldifWriter.flush();
      return updatedEntriesStream.toString();
    }
  }
  @DataProvider
@@ -2290,7 +2265,6 @@
      "-p", getServerLdapPort(),
      "-D", bindDn,
      "-w", bindPassword,
      "-a",
      "-f", tempFile.getAbsolutePath()
    };
@@ -2299,20 +2273,20 @@
  private void ldapModify(String[] args, boolean expectSuccess) throws Exception {
    clearOutputStream();
    int retVal = LDAPModify.mainModify(args, false, getOutputStream(), getOutputStream());
    int retVal = LDAPModify.run(getOutputPrintStream(), getOutputPrintStream(), args);
    assertEquals(retVal == 0, expectSuccess, "Return value = " + retVal);
  }
  private String ldapSearch(String[] args) throws Exception {
    clearOutputStream();
    int retVal = LDAPSearch.mainSearch(args, false, getOutputStream(), getOutputStream());
    int retVal = LDAPSearch.run(getOutputPrintStream(), getOutputPrintStream(), args);
    Assert.assertEquals(retVal, 0, "Non-zero return code because, error: " + getOutputStreamContents());
    return getOutputStreamContents();
  }
  private String ldapCompare(String[] args, int expectedRc) throws Exception {
    clearOutputStream();
    int retVal = LDAPCompare.mainCompare(args, false, getOutputStream(), getOutputStream());
    int retVal = LDAPCompare.run(getOutputPrintStream(), getOutputPrintStream(), args);
    Assert.assertEquals(retVal, expectedRc,  "Non-zero return code because, error: " + getOutputStreamContents());
    return getOutputStreamContents();
  }
@@ -2450,12 +2424,12 @@
    String[] args =
    {
      "--sourceLDIF", actualLdifFile.getAbsolutePath(),
      "--targetLDIF", expectedLdifFile.getAbsolutePath(),
      "--outputLDIF", diffLdifFile.getAbsolutePath()
      "--outputLDIF", diffLdifFile.getAbsolutePath(),
      actualLdifFile.getAbsolutePath(),
      expectedLdifFile.getAbsolutePath()
    };
    int retVal = LDIFDiff.mainDiff(args, true, System.out, System.err);
    int retVal = LDIFDiff.run(System.out, System.err, args);
    assertEquals(retVal, 0, "LDIFDiff failed");
    if (diffLdifFile.exists()) {
@@ -2531,6 +2505,9 @@
    return _cmdOutput;
  }
  private static PrintStream getOutputPrintStream() {
    return new PrintStream(getOutputStream());
  }
  private static String makeUserLdif(String dn, String givenName, String sn, String password) {
    String cn = givenName + " " + sn;
opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/ReferencesTestCase.java
@@ -12,7 +12,7 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2008-2009 Sun Microsystems, Inc.
 * Portions Copyright 2015 ForgeRock AS.
 * Portions Copyright 2015-2016 ForgeRock AS.
 */
package org.opends.server.authorization.dseecompat;
@@ -187,7 +187,7 @@
        {
          break;
        }
        if(s.startsWith("SearchReference")) {
        if(s.startsWith("SearchResultReference")) {
          return true;
        }
      }
opendj-server-legacy/src/test/java/org/opends/server/authorization/dseecompat/TargetControlTestCase.java
@@ -12,7 +12,7 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2008-2009 Sun Microsystems, Inc.
 * Portions Copyright 2012-2015 ForgeRock AS.
 * Portions Copyright 2012-2016 ForgeRock AS.
 */
package org.opends.server.authorization.dseecompat;
@@ -245,8 +245,7 @@
    String noOpCtrlStr=OID_LDAP_NOOP_OPENLDAP_ASSIGNED + ":true";
    //This pwd change should return no-op since the no-op control is
    //specified and it is allowed for authorization dn.
    pwdModify(level3User, PWD, newPWD, noOpCtrlStr, null,
            LDAPResultCode.NO_OPERATION);
    pwdModify(level3User, PWD, newPWD, noOpCtrlStr, null, LDAPResultCode.SUCCESS);
    //This pwd change should fail even though the no-op is specified, since
    //since the no-op control is not allowed for this authorization dn.
    pwdModify(superUser, PWD, newPWD, noOpCtrlStr, null,
opendj-server-legacy/src/test/java/org/opends/server/backends/LDIFBackendTestCase.java
@@ -40,8 +40,8 @@
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.tasks.LdifFileWriter;
import org.opends.server.tasks.TasksTestCase;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
@@ -177,7 +177,7 @@
      "-w", "password",
      "-f", subtreeDeletePath
    };
    resultCode = LDAPModify.mainModify(args, false, System.out, System.err);
    resultCode = LDAPModify.run(System.out, System.err, args);
    assertEquals(resultCode, ResultCode.NOT_ALLOWED_ON_NONLEAF.intValue());
@@ -192,7 +192,7 @@
      "-J", "subtreeDelete",
      "-f", subtreeDeletePath
    };
    resultCode = LDAPModify.mainModify(args, false, System.out, System.err);
    resultCode = LDAPModify.run(System.out, System.err, args);
    assertEquals(resultCode, 0);
  }
@@ -270,7 +270,7 @@
      "-J", "subtreeDelete",
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, System.out, System.err), 0);
    assertEquals(LDAPModify.run(System.out, System.err, args), 0);
    assertFalse(DirectoryServer.entryExists(DN.valueOf("o=ldif")));
    assertFalse(DirectoryServer.entryExists(
                    DN.valueOf("uid=user.1,ou=People,o=ldif")));
@@ -312,7 +312,7 @@
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, System.out, System.err), 0);
    assertEquals(LDAPSearch.run(System.out, System.err, args), 0);
  }
@@ -356,7 +356,7 @@
      "-w", "password",
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, System.out, System.err), 0);
    assertEquals(LDAPModify.run(System.out, System.err, args), 0);
  }
opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaBackendTestCase.java
@@ -24,6 +24,7 @@
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.types.ExistingFileBehavior.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.StaticUtils.*;
import static org.testng.Assert.*;
@@ -62,7 +63,7 @@
import org.opends.server.schema.SchemaConstants;
import org.opends.server.schema.SchemaHandler;
import org.opends.server.schema.SchemaHandler.SchemaUpdater;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.LDIFExportConfig;
@@ -4284,7 +4285,7 @@
  private void runModify(String[] args, String ldifContent, ResultCode expectedRC)
  {
    runModify(args, ldifContent, null, expectedRC);
    runModify(args, ldifContent, nullPrintStream(), expectedRC);
  }
  private void runModify(String[] args, String ldifContent, PrintStream stderr, ResultCode expectedRC)
@@ -4300,7 +4301,7 @@
    try
    {
      System.setIn(new ByteArrayInputStream(ldifContent.getBytes()));
      return LDAPModify.mainModify(args, false, stdout, stderr);
      return LDAPModify.run(stdout, stderr, args);
    }
    finally
    {
opendj-server-legacy/src/test/java/org/opends/server/controls/MatchedValuesControlTest.java
@@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.List;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.schema.CoreSchema;
import org.forgerock.opendj.ldap.schema.MatchingRule;
import org.opends.server.core.DirectoryServer;
@@ -29,7 +30,6 @@
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.io.ASN1;
import org.opends.server.util.Base64;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@@ -782,7 +782,7 @@
      "{ serialNumber 13233831500277100508, issuer rdnSequence:\""+
      "CN=Babs Jensen,OU=Product Development,L=Cupertione,C=US\" }";
    return new Object[][]{
      {"userCertificate", ByteString.wrap(Base64.decode(BASE64_CERT_VALUE)),
      {"userCertificate", ByteString.wrap(Base64.decode(BASE64_CERT_VALUE).toByteArray()),
        CERT_EXACT_ASSERTION}};
  }
opendj-server-legacy/src/test/java/org/opends/server/controls/PersistentSearchControlTest.java
@@ -22,6 +22,7 @@
import static org.opends.server.controls.PersistentSearchChangeType.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -48,7 +49,7 @@
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.protocols.ldap.LDAPReader;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.types.CancelRequest;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.LDAPException;
@@ -550,8 +551,7 @@
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false,
                  true, null, System.err),11);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 11);
    //cancel the persisting persistent search.
    search.cancel(new CancelRequest(true,LocalizableMessage.EMPTY));
  }
opendj-server-legacy/src/test/java/org/opends/server/core/AddOperationTestCase.java
@@ -22,6 +22,7 @@
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
@@ -45,7 +46,7 @@
import org.opends.server.protocols.ldap.AddRequestProtocolOp;
import org.opends.server.protocols.ldap.LDAPAttribute;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.tools.RemoteConnection;
import org.opends.server.types.Attribute;
import org.opends.server.types.Attributes;
@@ -1577,7 +1578,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    assertTrue(DirectoryServer.getSchema().hasAttributeType(attrName));
    path = TestCaseUtils.createTempFile(
@@ -1598,7 +1599,7 @@
      "-f", path
    };
    assertFalse(LDAPModify.mainModify(args, false, null, null) == 0);
    assertFalse(LDAPModify.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
  /**
@@ -1633,7 +1634,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    assertTrue(DirectoryServer.getSchema().hasAttributeType(attrName));
    path = TestCaseUtils.createTempFile(
@@ -1654,7 +1655,7 @@
      "-f", path
    };
    assertFalse(LDAPModify.mainModify(args, false, null, null) == 0);
    assertFalse(LDAPModify.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
  /**
@@ -1688,7 +1689,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    assertTrue(DirectoryServer.getSchema().hasObjectClass(ocName));
    path = TestCaseUtils.createTempFile(
@@ -1708,7 +1709,7 @@
      "-f", path
    };
    assertFalse(LDAPModify.mainModify(args, false, null, null) == 0);
    assertFalse(LDAPModify.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
  /**
opendj-server-legacy/src/test/java/org/opends/server/core/BindOperationTestCase.java
@@ -34,9 +34,9 @@
import org.opends.server.protocols.ldap.LDAPControl;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.tools.LDAPDelete;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPDelete;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.tools.RemoteConnection;
import org.opends.server.types.AuthenticationInfo;
import org.opends.server.types.AuthenticationType;
@@ -52,6 +52,7 @@
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -1523,7 +1524,7 @@
        "--noPropertiesFile",
        "ou=people,dc=example,dc=com"
        };
      assertEquals(LDAPDelete.mainDelete(args, false, null, System.err), 0);
      assertEquals(LDAPDelete.run(nullPrintStream(), System.err, args), 0);
      assertNull(DirectoryServer.getAuthenticatedUsers().get(userDN));
    }
@@ -1587,7 +1588,7 @@
        "--noPropertiesFile",
        "-f", path
        };
      assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
      assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
      DN newUserDN = DN.valueOf("uid=test,ou=users,dc=example,dc=com");
      assertNotNull(DirectoryServer.getAuthenticatedUsers().get(newUserDN));
@@ -1654,8 +1655,7 @@
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPSearch.run(System.out, System.err, args), 0);
      args = new String[]
      {
@@ -1668,8 +1668,7 @@
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPSearch.run(System.out, System.err, args), 0);
    }
    finally
    {
@@ -1746,7 +1745,7 @@
        "(objectClass=*)"
      };
      int rc = LDAPSearch.mainSearch(args, false, System.out, System.err);
      int rc = LDAPSearch.run(System.out, System.err, args);
      assertFalse(rc == 0);
      assertFalse(rc == LDAPResultCode.INVALID_CREDENTIALS);
@@ -1761,8 +1760,7 @@
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPSearch.run(System.out, System.err, args), 0);
    }
    finally
    {
@@ -1839,8 +1837,7 @@
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, System.out, System.err),
                   LDAPResultCode.INVALID_CREDENTIALS);
      assertEquals(LDAPSearch.run(System.out, System.err, args), LDAPResultCode.INVALID_CREDENTIALS);
      args = new String[]
      {
@@ -1853,8 +1850,7 @@
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPSearch.run(System.out, System.err, args), 0);
    }
    finally
    {
opendj-server-legacy/src/test/java/org/opends/server/core/DeleteOperationTestCase.java
@@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.List;
import com.forgerock.opendj.ldap.tools.LDAPDelete;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
@@ -29,7 +30,6 @@
import org.opends.server.plugins.ShortCircuitPlugin;
import org.opends.server.protocols.ldap.DeleteRequestProtocolOp;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.tools.LDAPDelete;
import org.opends.server.tools.RemoteConnection;
import org.opends.server.types.CancelRequest;
import org.opends.server.types.CancelResult;
@@ -45,6 +45,7 @@
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
/**
@@ -256,7 +257,7 @@
    TestCaseUtils.initializeTestBackend(true);
    String[] args = getArgs("o=test");
    assertEquals(LDAPDelete.mainDelete(args, false, null, null), 0);
    assertEquals(LDAPDelete.run(nullPrintStream(), nullPrintStream(), args), 0);
  }
@@ -550,7 +551,7 @@
    DirectoryServer.setWritabilityMode(WritabilityMode.INTERNAL_ONLY);
    String[] args = getArgs("o=test");
    assertFalse(LDAPDelete.mainDelete(args, false, null, null) == 0);
    assertFalse(LDAPDelete.run(nullPrintStream(), nullPrintStream(), args) == 0);
    DirectoryServer.setWritabilityMode(WritabilityMode.ENABLED);
  }
@@ -616,7 +617,7 @@
    backend.setWritabilityMode(WritabilityMode.INTERNAL_ONLY);
    String[] args = getArgs("o=test");
    assertFalse(LDAPDelete.mainDelete(args, false, null, null) == 0);
    assertFalse(LDAPDelete.run(nullPrintStream(), nullPrintStream(), args) == 0);
    backend.setWritabilityMode(WritabilityMode.ENABLED);
  }
opendj-server-legacy/src/test/java/org/opends/server/core/GroupManagerTestCase.java
@@ -34,8 +34,8 @@
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.tools.LDAPDelete;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPDelete;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.MemberList;
@@ -49,6 +49,7 @@
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -2203,7 +2204,7 @@
      "--noPropertiesFile",
      "ou=groups,dc=example,dc=com"
    };
    assertEquals(LDAPDelete.mainDelete(args, false, null, System.err), 0);
    assertEquals(LDAPDelete.run(nullPrintStream(), System.err, args), 0);
    InternalClientConnection conn1 =
            new InternalClientConnection(userDN);
@@ -2265,7 +2266,7 @@
      "--noPropertiesFile",
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    InternalClientConnection conn1 =
            new InternalClientConnection(userDN);
opendj-server-legacy/src/test/java/org/opends/server/core/ModifyOperationTestCase.java
@@ -25,6 +25,7 @@
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.newSearchRequest;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -34,6 +35,7 @@
import java.util.List;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ModificationType;
@@ -54,7 +56,7 @@
import org.opends.server.protocols.ldap.LDAPModification;
import org.opends.server.protocols.ldap.ModifyRequestProtocolOp;
import org.opends.server.protocols.ldap.ModifyResponseProtocolOp;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.tools.RemoteConnection;
import org.opends.server.types.Attribute;
import org.opends.server.types.Attributes;
@@ -68,7 +70,6 @@
import org.opends.server.types.Operation;
import org.opends.server.types.RawModification;
import org.opends.server.types.WritabilityMode;
import org.opends.server.util.Base64;
import org.opends.server.workflowelement.localbackend.LocalBackendModifyOperation;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
@@ -2854,7 +2855,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    assertTrue(DirectoryServer.getSchema().hasAttributeType(attrName));
    path = TestCaseUtils.createTempFile(
@@ -2875,7 +2876,7 @@
      "-f", path
    };
    assertFalse(LDAPModify.mainModify(args, false, null, null) == 0);
    assertFalse(LDAPModify.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -2912,7 +2913,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    assertTrue(DirectoryServer.getSchema().hasObjectClass(ocName));
    path = TestCaseUtils.createTempFile(
@@ -2930,7 +2931,7 @@
      "-f", path
    };
    assertFalse(LDAPModify.mainModify(args, false, null, null) == 0);
    assertFalse(LDAPModify.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -3098,7 +3099,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
  }
   /**
@@ -3144,7 +3145,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
  }
   /**
@@ -3194,7 +3195,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
  }
  private String firstValue(List<Attribute> attrs)
@@ -3406,7 +3407,7 @@
      "axuJ8LFNbZtsp1ldW3i84+F5+SYT+xI67ZcoAtwx/VFVI9s5I/Gkmu9f9nxjPpK7" +
      "1AIUXiE3Qcck";
    ByteString value = ByteString.wrap(Base64.decode(certificateValue));
    ByteString value = ByteString.wrap(Base64.decode(certificateValue).toByteArray());
    LDAPAttribute attr = new LDAPAttribute("usercertificate", value);
    ModifyOperation modifyOperation = processModify("uid=test.user," + baseDN, new LDAPModification(ADD, attr));
    assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
opendj-server-legacy/src/test/java/org/opends/server/core/PasswordPolicyTestCase.java
@@ -30,7 +30,7 @@
import org.opends.server.api.PasswordStorageScheme;
import org.opends.server.extensions.InitializationUtils;
import org.opends.server.schema.UserPasswordSyntax;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.types.Attribute;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
@@ -42,6 +42,7 @@
import static org.assertj.core.api.Assertions.*;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
/**
@@ -4247,7 +4248,7 @@
        "-f", path
      };
      assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
      assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    }
    finally
    {
@@ -4378,7 +4379,7 @@
                      "-f", newPWsPath
              };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
      assertEquals(LDAPModify.run(System.out, System.err, args),
              0);
@@ -4402,7 +4403,7 @@
                      "-f", newPWsPath
              };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
      assertEquals(LDAPModify.run(System.out, System.err, args),
              0);
@@ -4467,7 +4468,7 @@
      "-f", origPWPath
    };
    assertEquals(LDAPModify.mainModify(args, false, System.out, System.err), 0);
    assertEquals(LDAPModify.run(System.out, System.err, args), 0);
    TestCaseUtils.dsconfig(
      "set-password-policy-prop",
@@ -4478,8 +4479,7 @@
    {
      // Make sure that we cannot re-use the original password as a new
      // password.
      assertFalse(LDAPModify.mainModify(args, false, System.out, System.err) ==
                  0);
      assertFalse(LDAPModify.run(System.out, System.err, args) == 0);
      // Change the password three times.
@@ -4508,8 +4508,7 @@
        "-f", newPWsPath
      };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPModify.run(System.out, System.err, args), 0);
      advanceTimeThread();
@@ -4525,8 +4524,7 @@
        "-f", origPWPath
      };
      assertFalse(LDAPModify.mainModify(args, false, System.out, System.err) ==
                  0);
      assertFalse(LDAPModify.run(System.out, System.err, args) == 0);
      // Change the password one more time and then verify that we can use the
@@ -4551,8 +4549,7 @@
        "-f", newPWsPath2
      };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPModify.run(System.out, System.err, args), 0);
      advanceTimeThread();
@@ -4574,8 +4571,7 @@
        "-f", firstPWPath
      };
      assertFalse(LDAPModify.mainModify(args, false, System.out, System.err) ==
                  0);
      assertFalse(LDAPModify.run(System.out, System.err, args) == 0);
      advanceTimeThread();
@@ -4588,8 +4584,7 @@
        "--policy-name", "Default Password Policy",
        "--set", "password-history-count:2");
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPModify.run(System.out, System.err, args), 0);
    }
    finally
    {
@@ -4643,7 +4638,7 @@
      "-f", origPWPath
    };
    assertEquals(LDAPModify.mainModify(args, false, System.out, System.err), 0);
    assertEquals(LDAPModify.run(System.out, System.err, args), 0);
    TestCaseUtils.dsconfig(
      "set-password-policy-prop",
@@ -4654,8 +4649,7 @@
    {
      // Make sure that we can no longer re-use the original password as a new
      // password.
      assertFalse(LDAPModify.mainModify(args, false, System.out, System.err) ==
                  0);
      assertFalse(LDAPModify.run(System.out, System.err, args) == 0);
      // Change the password three times.
@@ -4684,8 +4678,7 @@
        "-f", newPWsPath
      };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPModify.run(System.out, System.err, args), 0);
      // Make sure that we still can't use the original password.
@@ -4698,15 +4691,13 @@
        "-f", origPWPath
      };
      assertFalse(LDAPModify.mainModify(args, false, System.out, System.err) ==
                  0);
      assertFalse(LDAPModify.run(System.out, System.err, args) == 0);
      // Sleep for six seconds and then verify that we can use the original
      // password again.
      Thread.sleep(6000);
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                  0);
      assertEquals(LDAPModify.run(System.out, System.err, args), 0);
    }
    finally
    {
@@ -4748,7 +4739,7 @@
      "-f", path
    };
    assertFalse(LDAPModify.mainModify(args, false, System.out, System.err) ==
    assertFalse(LDAPModify.run(System.out, System.err, args) ==
                0);
  }
@@ -4786,7 +4777,7 @@
      "-f", path
    };
    assertFalse(LDAPModify.mainModify(args, false, System.out, System.err) ==
    assertFalse(LDAPModify.run(System.out, System.err, args) ==
                0);
  }
opendj-server-legacy/src/test/java/org/opends/server/core/RejectUnauthReqTests.java
@@ -19,16 +19,16 @@
import java.util.ArrayList;
import java.util.List;
import com.forgerock.opendj.ldap.tools.LDAPCompare;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.TestCaseUtils;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.tools.LDAPAuthenticationHandler;
import org.opends.server.tools.LDAPCompare;
import org.opends.server.tools.LDAPDelete;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPDelete;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.tools.RemoteConnection;
import org.opends.server.types.AuthenticationInfo;
import org.opends.server.types.Control;
@@ -38,6 +38,7 @@
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -90,20 +91,15 @@
        "dn: o=rejectTestCase,o=test", "objectclass: top",
        "objectclass: organization", "o: rejectTestCase",
        "description: Reject Test Case");
    return LDAPModify.mainModify(addArgs(authenticate, filePath), false, null, null);
    return LDAPModify.run(nullPrintStream(), nullPrintStream(), modifyArgs(authenticate, filePath));
  }
  private String[] modifyArgs(boolean authenticate, String filePath)
  {
    return args(authenticate, false, filePath);
    return args(authenticate, filePath);
  }
  private String[] addArgs(boolean authenticate, String filePath)
  {
    return args(authenticate, true, filePath);
  }
  private String[] args(boolean authenticate, boolean add, String filePath)
  private String[] args(boolean authenticate, String filePath)
  {
    Args args = new Args();
    args.add("--noPropertiesFile");
@@ -114,10 +110,6 @@
      args.add("-D", "cn=directory manager");
      args.add("-w", "password");
    }
    if (add)
    {
      args.add("-a");
    }
    args.add("-f", filePath);
    return args.toArray();
  }
@@ -136,7 +128,7 @@
    String path = TestCaseUtils.createTempFile("dn: o=rejectTestCase,o=test",
        "changetype: modify", "replace: description",
        "description: New Description");
    return LDAPModify.mainModify(modifyArgs(authenticate, path), false, null, null);
    return LDAPModify.run(nullPrintStream(), nullPrintStream(), modifyArgs(authenticate, path));
  }
@@ -153,7 +145,7 @@
   */
  private int performCompareOperation(boolean authentication) throws Exception
  {
    return LDAPCompare.mainCompare(compareArgs(authentication), false, null, null);
    return LDAPCompare.run(nullPrintStream(), nullPrintStream(), compareArgs(authentication));
  }
  private String[] compareArgs(boolean authenticate)
@@ -186,7 +178,7 @@
    String path = TestCaseUtils
        .createTempFile("dn: o=rejectTestCase,o=Test", "changetype: modrdn",
            "newrdn: o=mod_rejectTestCase", "deleteoldrdn: 0");
    return LDAPModify.mainModify(modRdnArgs(authentication, path), false, null, null);
    return LDAPModify.run(nullPrintStream(), nullPrintStream(), modRdnArgs(authentication, path));
  }
  private String[] modRdnArgs(boolean authenticate, String path)
@@ -216,7 +208,7 @@
   */
  private int performDeleteOperation(boolean authentication) throws Exception
  {
    return LDAPDelete.mainDelete(deleteArgs(authentication), false, null, null);
    return LDAPDelete.run(nullPrintStream(), nullPrintStream(), deleteArgs(authentication));
  }
  private String[] deleteArgs(boolean authenticate)
@@ -227,7 +219,6 @@
    args.add("-p", TestCaseUtils.getServerLdapPort());
    if (authenticate)
    {
      args.add("-V", "3");
      args.add("-D", "cn=Directory Manager");
      args.add("-w", "password");
    }
@@ -284,7 +275,7 @@
  public void testAuthSearchDefCfg()
  {
    DirectoryServer.setRejectUnauthenticatedRequests(false);
    assertEquals(LDAPSearch.mainSearch(searchArgs(Auth.SIMPLE), false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, searchArgs(Auth.SIMPLE)), 0);
  }
  /**
@@ -295,7 +286,7 @@
  public void testUnauthSearchDefCfg()
  {
    DirectoryServer.setRejectUnauthenticatedRequests(false);
    assertEquals(LDAPSearch.mainSearch(searchArgs(Auth.ANONYMOUS), false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, searchArgs(Auth.ANONYMOUS)), 0);
  }
  /**
@@ -396,7 +387,7 @@
  public void testStartTLSUnauthDefCfg() throws Exception
  {
    DirectoryServer.setRejectUnauthenticatedRequests(false);
    assertEquals(LDAPSearch.mainSearch(searchArgs(Auth.START_TLS), false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, searchArgs(Auth.START_TLS)), 0);
  }
  /**
@@ -454,8 +445,8 @@
    {
      DirectoryServer.setRejectUnauthenticatedRequests(true);
      assertFalse(LDAPSearch.mainSearch(searchArgs(Auth.ANONYMOUS), false, null, null) == 0);
      assertEquals(LDAPSearch.mainSearch(searchArgs(Auth.START_TLS), false, null, System.err), 0);
      assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), searchArgs(Auth.ANONYMOUS)) == 0);
      assertEquals(LDAPSearch.run(nullPrintStream(), System.err, searchArgs(Auth.START_TLS)), 0);
    }
    finally
    {
@@ -507,8 +498,7 @@
    try
    {
      DirectoryServer.setRejectUnauthenticatedRequests(true);
      assertEquals(LDAPSearch.mainSearch(searchArgs(Auth.START_TLS), false, null, System.err), 0);
      assertEquals(LDAPSearch.run(nullPrintStream(), System.err, searchArgs(Auth.START_TLS)), 0);
    }
    finally
    {
opendj-server-legacy/src/test/java/org/opends/server/core/SearchOperationTestCase.java
@@ -19,6 +19,7 @@
import static org.assertj.core.api.Assertions.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -57,7 +58,7 @@
import org.opends.server.protocols.ldap.SearchRequestProtocolOp;
import org.opends.server.protocols.ldap.SearchResultDoneProtocolOp;
import org.opends.server.protocols.ldap.SearchResultEntryProtocolOp;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.tools.RemoteConnection;
import org.opends.server.types.Attribute;
import org.opends.server.types.Control;
@@ -1261,10 +1262,9 @@
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D","cn=directory manager",
      "-w","password",
      "-a",
      "-f", filePath
    };
    int err = LDAPModify.mainModify(args, false, null,null);
    int err = LDAPModify.run(nullPrintStream(), nullPrintStream(), args);
    assertEquals(err,0);
@@ -1295,10 +1295,9 @@
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D","cn=directory manager",
      "-w","password",
      "-a",
      "-f", filePath
    };
    int err = LDAPModify.mainModify(args, false, null,null);
    int err = LDAPModify.run(nullPrintStream(), nullPrintStream(), args);
    assertEquals(err, 0);
  }
}
opendj-server-legacy/src/test/java/org/opends/server/core/SubentryManagerTestCase.java
@@ -22,6 +22,7 @@
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.CollectionUtils.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -38,8 +39,8 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.tools.LDAPDelete;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPDelete;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.types.Attribute;
import org.opends.server.types.Attributes;
import org.opends.server.types.DirectoryException;
@@ -418,7 +419,7 @@
      "--noPropertiesFile",
      SUFFIX
    };
    assertEquals(LDAPDelete.mainDelete(args, false, null, System.err), 0);
    assertEquals(LDAPDelete.run(nullPrintStream(), System.err, args), 0);
    assertTrue(DirectoryServer.getSubentryManager().getCollectiveSubentries(
            DN.valueOf("uid=rogasawara," + BASE)).isEmpty());
@@ -450,7 +451,7 @@
      "--noPropertiesFile",
      "-f", newPath
    };
    assertEquals(LDAPModify.mainModify(newArgs, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, newArgs), 0);
    assertNotNull(DirectoryServer.getEntry(DN.valueOf(
            "uid=rogasawara," + NEWBASE + "," + SUFFIX)));
@@ -476,7 +477,7 @@
      "--noPropertiesFile",
      "-f", oldPath
    };
    assertEquals(LDAPModify.mainModify(oldArgs, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, oldArgs), 0);
    assertNotNull(DirectoryServer.getEntry(DN.valueOf(
            "uid=rogasawara," + OLDBASE + "," + SUFFIX)));
opendj-server-legacy/src/test/java/org/opends/server/core/TestModifyDNOperation.java
@@ -22,6 +22,7 @@
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -47,7 +48,7 @@
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.protocols.ldap.ModifyDNRequestProtocolOp;
import org.opends.server.protocols.ldap.ModifyDNResponseProtocolOp;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.tools.RemoteConnection;
import org.opends.server.types.Attribute;
import org.opends.server.types.CancelRequest;
@@ -844,7 +845,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    assertTrue(DirectoryServer.getSchema().hasAttributeType(attrName));
    path = TestCaseUtils.createTempFile(
@@ -870,7 +871,7 @@
      "-f", path
    };
    assertFalse(LDAPModify.mainModify(args, false, null, null) == 0);
    assertFalse(LDAPModify.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
  /**
opendj-server-legacy/src/test/java/org/opends/server/extensions/AnonymousSASLMechanismHandlerTestCase.java
@@ -23,12 +23,13 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.BindOperationBasis;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.types.Control;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -182,12 +183,11 @@
      "--noPropertiesFile",
      "-h", "127.0.0.1",
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-o", "mech=ANONYMOUS",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
    handler.finalizeSASLMechanismHandler();
  }
@@ -209,13 +209,12 @@
      "--noPropertiesFile",
      "-h", "127.0.0.1",
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-o", "mech=ANONYMOUS",
      "-o", "trace=LDAP Trace String",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
    handler.finalizeSASLMechanismHandler();
  }
opendj-server-legacy/src/test/java/org/opends/server/extensions/CRAMMD5SASLMechanismHandlerTestCase.java
@@ -27,13 +27,14 @@
import org.opends.server.core.BindOperation;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.types.*;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -189,7 +190,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
@@ -231,7 +232,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
@@ -276,7 +277,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
@@ -318,7 +319,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -360,7 +361,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -400,7 +401,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -440,7 +441,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -480,7 +481,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -520,7 +521,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -547,7 +548,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -575,7 +576,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
opendj-server-legacy/src/test/java/org/opends/server/extensions/DigestMD5SASLMechanismHandlerTestCase.java
@@ -27,7 +27,7 @@
import org.opends.server.core.DeleteOperation;
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.types.AuthenticationInfo;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.Entry;
@@ -39,6 +39,7 @@
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -217,7 +218,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
@@ -260,7 +261,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
@@ -303,7 +304,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -346,7 +347,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -387,7 +388,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -428,7 +429,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -469,7 +470,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -510,7 +511,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -551,7 +552,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -581,7 +582,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -611,7 +612,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -641,7 +642,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -685,7 +686,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -714,7 +715,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -758,7 +759,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
    DeleteOperation deleteOperation = getRootConnection().processDelete(e.getName());
@@ -806,7 +807,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -850,7 +851,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -894,7 +895,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
opendj-server-legacy/src/test/java/org/opends/server/extensions/ExternalSASLMechanismHandlerTestCase.java
@@ -23,6 +23,7 @@
import java.util.List;
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ModificationType;
import org.forgerock.opendj.ldap.ResultCode;
@@ -34,20 +35,21 @@
import org.opends.server.protocols.ldap.BindRequestProtocolOp;
import org.opends.server.protocols.ldap.BindResponseProtocolOp;
import org.opends.server.protocols.ldap.LDAPMessage;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.tools.RemoteConnection;
import org.opends.server.types.Attributes;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.Entry;
import org.opends.server.types.InitializationException;
import org.opends.server.types.Modification;
import org.opends.server.util.Base64;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.opends.server.TestCaseUtils.runLdapSearchTrustCertificateForSession;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
@@ -202,13 +204,14 @@
      "-K", keyStorePath,
      "-W", "password",
      "-P", trustStorePath,
      "-r",
      "-o", "mech=EXTERNAL",
      "-N", "client-cert",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
  }
@@ -247,13 +250,14 @@
      "-K", keyStorePath,
      "-W", "password",
      "-X",
      "-r",
      "-o", "mech=EXTERNAL",
      "-N", "client-cert",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
@@ -308,13 +312,13 @@
      "-K", keyStorePath,
      "-W", "password",
      "-X",
      "-r",
      "-o", "mech=EXTERNAL",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -363,13 +367,13 @@
      "-K", keyStorePath,
      "-W", "password",
      "-X",
      "-r",
      "-o", "mech=EXTERNAL",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
    mods.clear();
@@ -425,13 +429,14 @@
      "-K", keyStorePath,
      "-W", "password",
      "-X",
      "-r",
      "-o", "mech=EXTERNAL",
      "-N", "client-cert",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
@@ -491,13 +496,13 @@
      "-K", keyStorePath,
      "-W", "password",
      "-X",
      "-r",
      "-o", "mech=EXTERNAL",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -554,13 +559,14 @@
      "-K", keyStorePath,
      "-W", "password",
      "-X",
      "-r",
      "-o", "mech=EXTERNAL",
      "-N", "client-cert",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
    mods.clear();
@@ -635,13 +641,13 @@
      "-K", keyStorePath,
      "-W", "password",
      "-X",
      "-r",
      "-o", "mech=EXTERNAL",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
    mods.clear();
opendj-server-legacy/src/test/java/org/opends/server/extensions/FingerprintCertificateMapperTestCase.java
@@ -18,7 +18,9 @@
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.opends.server.TestCaseUtils.runLdapSearchTrustCertificateForSession;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
import java.io.File;
@@ -31,7 +33,6 @@
import org.forgerock.opendj.server.config.meta.FingerprintCertificateMapperCfgDefn;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyOperation;
import org.opends.server.tools.LDAPSearch;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.InitializationException;
@@ -205,13 +206,13 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
@@ -267,13 +268,13 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
@@ -326,13 +327,13 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
      assertFalse(runLdapSearchTrustCertificateForSession(nullPrintStream(), nullPrintStream(), args) == 0);
    }
    finally
    {
@@ -399,13 +400,13 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
      assertFalse(runLdapSearchTrustCertificateForSession(nullPrintStream(), nullPrintStream(), args) == 0);
    }
    finally
    {
@@ -600,13 +601,13 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "cn=config",
        "-s", "sub",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
opendj-server-legacy/src/test/java/org/opends/server/extensions/PasswordModifyExtendedOperationTestCase.java
@@ -34,7 +34,7 @@
import org.opends.server.core.ExtendedOperation;
import org.opends.server.core.ModifyOperation;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.tools.LDAPPasswordModify;
import com.forgerock.opendj.ldap.tools.LDAPPasswordModify;
import org.opends.server.types.AuthenticationInfo;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.DirectoryException;
@@ -47,6 +47,7 @@
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.opends.server.extensions.ExtensionsConstants.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -161,7 +162,7 @@
      "-c", "password",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(DN.valueOf("cn=Directory Manager"), "newPassword");
@@ -176,7 +177,7 @@
      "-c", "newPassword",
      "-n", "password"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
  }
@@ -204,10 +205,9 @@
      "-D", "cn=Directory Manager",
      "-w", "password",
      "-c", "password",
      "-n", "newPassword",
      "-A"
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(DN.valueOf("cn=Directory Manager"), "newPassword");
@@ -220,10 +220,9 @@
      "-D", "cn=Directory Manager",
      "-w", "newPassword",
      "-c", "newPassword",
      "-n", "password",
      "-A"
      "-n", "password"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
  }
@@ -252,7 +251,7 @@
      "-c", "password",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(DN.valueOf("cn=Directory Manager"), "newPassword");
@@ -266,7 +265,7 @@
      "-c", "newPassword",
      "-n", "password"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
  }
@@ -300,7 +299,7 @@
      "-c", "password",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(userEntry.getName(), "newPassword");
  }
@@ -335,7 +334,7 @@
      "-w", "password",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(userEntry.getName(), "newPassword");
  }
@@ -381,7 +380,7 @@
      "-D", "uid=test.user,o=test",
      "-w", "password"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
  }
@@ -415,7 +414,7 @@
      "-a", "dn:uid=test.user,o=test",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(userEntry.getName(), "newPassword");
  }
@@ -452,7 +451,7 @@
      "-a", "u:test.user",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(userEntry.getName(), "newPassword");
  }
@@ -489,7 +488,7 @@
      "-a", "uid=test.user,o=test",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(userEntry.getName(), "newPassword");
  }
@@ -526,7 +525,7 @@
      "-a", "test.user",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(userEntry.getName(), "newPassword");
  }
@@ -561,7 +560,7 @@
      "-c", "password",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(userEntry.getName(), "newPassword");
  }
@@ -596,7 +595,7 @@
      "-c", "password",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(userEntry.getName(), "newPassword");
  }
@@ -632,7 +631,7 @@
      "-a", "dn:uid=test.user,o=test",
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    verifyPasswordPerformingInternalBind(userEntry.getName(), "newPassword");
  }
@@ -663,7 +662,7 @@
      "-n", "newPassword"
    };
    assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
    assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
  }
@@ -691,7 +690,7 @@
      "-n", "newPassword"
    };
    assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
    assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
  }
@@ -720,7 +719,7 @@
      "-n", "newPassword"
    };
    assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
    assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
  }
@@ -749,7 +748,7 @@
      "-n", "newPassword"
    };
    assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
    assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
  }
@@ -779,7 +778,7 @@
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 32);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 32);
  }
@@ -807,7 +806,7 @@
      "-n", "newPassword"
    };
    assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
    assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
  }
@@ -837,7 +836,7 @@
      "-n", "newPassword"
    };
    assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 49);
    assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 49);
  }
@@ -871,7 +870,7 @@
    };
    try {
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    } finally {
      applyPwdPolicyMods(dnStr, attr, "false");
    }
@@ -908,7 +907,7 @@
      "-n", "{SSHA}Fv4b7f4AnRMUiGqBi9QA1xJrTtRTqS3WpRi81g=="
    };
    assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
    assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
    // don't restore password policy as this is already the default.
  }
@@ -941,7 +940,7 @@
      "-n", "{SSHA}Fv4b7f4AnRMUiGqBi9QA1xJrTtRTqS3WpRi81g=="
    };
    assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
    assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
  }
@@ -1033,7 +1032,7 @@
    };
    try {
      assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
      assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
    } finally {
      applyPwdPolicyMods(dnStr, attr, "true");
    }
@@ -1071,7 +1070,7 @@
    };
    try {
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 53);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 53);
    } finally {
      applyPwdPolicyMods(dnStr, attr, "true");
    }
@@ -1109,7 +1108,7 @@
    };
    try {
      assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
      assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
    } finally {
      // Reset to default configuration
      applyPwdPolicyMods(dnStr, attr, "false");
@@ -1148,7 +1147,7 @@
    };
    try {
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 13);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 13);
    } finally {
      // Reset to default configuration
      applyPwdPolicyMods(dnStr, attr, "false");
@@ -1187,7 +1186,7 @@
    };
    try {
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 13);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 13);
    } finally {
      applyPwdPolicyMods(dnStr, attr, "false");
    }
@@ -1227,7 +1226,7 @@
    };
    try {
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 13);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 13);
    } finally {
      // Reset to default configuration
      applyPwdPolicyMods(dnStr, attr, "false");
@@ -1264,7 +1263,7 @@
    };
    try {
      assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
      assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
    } finally {
      applyPwdPolicyMods(dnStr, attr, "0 seconds");
    }
@@ -1301,7 +1300,7 @@
    };
    try {
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 53);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 53);
    } finally {
      applyPwdPolicyMods(dnStr, attr, "0 seconds");
    }
@@ -1342,7 +1341,7 @@
        "-n", "newPassword"
      };
      assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
      assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
    } finally {
      applyPwdPolicyMods(dnStr, attr1, "0 seconds");
      applyPwdPolicyMods(dnStr, attr2, "false");
@@ -1386,7 +1385,7 @@
        "-n", "newPassword"
      };
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    }
    finally {
      applyPwdPolicyMods(dnStr, attr1, "0 seconds");
@@ -1424,7 +1423,7 @@
            "-w", "password"
        };
    try {
      assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
      assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
    } finally {
      applyPwdPolicyMods(dnStr, attr, "cn=Random Password Generator,cn=Password Generators,cn=config");
    }
@@ -1458,7 +1457,7 @@
      "-c", "password"
    };
    try {
      assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
      assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
    }
    finally {
      applyPwdPolicyMods(dnStr, attr, "cn=Random Password Generator,cn=Password Generators,cn=config");
@@ -1496,7 +1495,7 @@
      "-n", "short"
    };
    try {
      assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
      assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
    }
    finally {
      applyPwdPolicyMods(dnStr, attr);
@@ -1533,7 +1532,7 @@
      "-n", "short"
    };
    try {
      assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, null));
      assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args));
    }
    finally {
      applyPwdPolicyMods(dnStr, attr);
@@ -1586,7 +1585,7 @@
    };
    try {
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, null), 0);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    } finally {
      applyPwdPolicyMods(dnStr, attr, "false");
    }
@@ -1638,7 +1637,7 @@
    };
    try {
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, System.err), 0);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), System.err, args), 0);
    } finally {
      applyPwdPolicyMods(dnStr, attr, "false");
    }
@@ -1688,7 +1687,7 @@
        "-n", "newpassword"
      };
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, System.err), 0);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), System.err, args), 0);
      userEntry = DirectoryServer.getEntry(userDN);
      assertNotNull(userEntry);
@@ -1744,7 +1743,7 @@
        "-n", "newpassword"
      };
      assertFalse(0 == LDAPPasswordModify.mainPasswordModify(args, false, null, System.err));
      assertFalse(0 == LDAPPasswordModify.run(nullPrintStream(), System.err, args));
      userEntry = DirectoryServer.getEntry(userDN);
      assertNotNull(userEntry);
@@ -1792,7 +1791,7 @@
        "-c", "password"
      };
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null, System.err), 0);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), System.err, args), 0);
      userEntry = DirectoryServer.getEntry(userDN);
      assertNotNull(userEntry);
opendj-server-legacy/src/test/java/org/opends/server/extensions/PlainSASLMechanismHandlerTestCase.java
@@ -29,7 +29,7 @@
import org.opends.server.protocols.internal.Requests;
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.schema.SchemaConstants;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.types.AuthenticationInfo;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.Entry;
@@ -38,6 +38,7 @@
import org.testng.annotations.Test;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
/**
@@ -379,7 +380,7 @@
      SchemaConstants.NO_ATTRIBUTES
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
@@ -490,7 +491,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -532,7 +533,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
@@ -574,7 +575,7 @@
      "-s", "base",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
  }
}
opendj-server-legacy/src/test/java/org/opends/server/extensions/StartTLSExtendedOperationTestCase.java
@@ -12,7 +12,7 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2006-2008 Sun Microsystems, Inc.
 * Portions Copyright 2014-2015 ForgeRock AS.
 * Portions Copyright 2014-2016 ForgeRock AS.
 */
package org.opends.server.extensions;
@@ -20,10 +20,12 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import static org.opends.server.TestCaseUtils.runLdapSearchTrustCertificateForSession;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
/**
@@ -69,7 +71,7 @@
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
  }
@@ -93,7 +95,7 @@
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
@@ -123,7 +125,7 @@
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
  }
@@ -149,7 +151,7 @@
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
@@ -190,17 +192,16 @@
      "-K", keyStorePath,
      "-W", "password",
      "-P", trustStorePath,
      "-r",
      "-o", "mech=EXTERNAL",
      "-N", "client-cert",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
  }
  /**
   * Tests the use of the StartTLS extended operation to communicate with the
   * server in conjunction with SASL EXTERNAL authentication and using blind
@@ -236,13 +237,14 @@
      "-K", keyStorePath,
      "-W", "password",
      "-X",
      "-r",
      "-o", "mech=EXTERNAL",
      "-N", "client-cert",
      "-b", "",
      "-s", "base",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
}
opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapperTestCase.java
@@ -19,7 +19,9 @@
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.opends.server.TestCaseUtils.runLdapSearchTrustCertificateForSession;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
import java.io.File;
@@ -32,7 +34,6 @@
import org.forgerock.opendj.server.config.meta.SubjectAttributeToUserAttributeCertificateMapperCfgDefn;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyOperation;
import org.opends.server.tools.LDAPSearch;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.InitializationException;
@@ -223,13 +224,14 @@
        "-K", getKeyStorePath("client.keystore"),
        "-W", "password",
        "-P", getTrustStorePath(),
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
@@ -277,13 +279,14 @@
        "-K", getKeyStorePath("client-emailAddress.keystore"),
        "-W", "password",
        "-P", getTrustStorePath(),
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
@@ -331,13 +334,14 @@
        "-K", getKeyStorePath("client-emailAddress.keystore"),
        "-W", "password",
        "-P", getTrustStorePath(),
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
@@ -393,13 +397,14 @@
        "-K", getKeyStorePath("client.keystore"),
        "-W", "password",
        "-P", getTrustStorePath(),
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
@@ -448,13 +453,14 @@
        "-K", getKeyStorePath("client.keystore"),
        "-W", "password",
        "-P", getTrustStorePath(),
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertFalse(LDAPSearch.mainSearch(args, false, null, System.err) == 0);
      assertFalse(runLdapSearchTrustCertificateForSession(args) == 0);
    }
    finally
    {
@@ -500,13 +506,14 @@
        "-K", getKeyStorePath("client.keystore"),
        "-W", "password",
        "-P", getTrustStorePath(),
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
      assertFalse(runLdapSearchTrustCertificateForSession(nullPrintStream(), nullPrintStream(), args) == 0);
    }
    finally
    {
@@ -562,13 +569,14 @@
        "-K", getKeyStorePath("client.keystore"),
        "-W", "password",
        "-P", getTrustStorePath(),
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
      assertFalse(runLdapSearchTrustCertificateForSession(nullPrintStream(), nullPrintStream(), args) == 0);
    }
    finally
    {
@@ -616,13 +624,14 @@
        "-K", getKeyStorePath("client.keystore"),
        "-W", "password",
        "-P", getTrustStorePath(),
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
      assertFalse(runLdapSearchTrustCertificateForSession(nullPrintStream(), nullPrintStream(), args) == 0);
    }
    finally
    {
@@ -852,13 +861,14 @@
        "-K", getKeyStorePath("client.keystore"),
        "-W", "password",
        "-P", getTrustStorePath(),
        "-r",
        "-o", "mech=EXTERNAL",
        "-N","client-cert",
        "-b", "cn=config",
        "-s", "sub",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
opendj-server-legacy/src/test/java/org/opends/server/extensions/SubjectDNToUserAttributeCertificateMapperTestCase.java
@@ -18,7 +18,9 @@
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.forgerock.opendj.ldap.requests.Requests.*;
import static org.opends.server.TestCaseUtils.runLdapSearchTrustCertificateForSession;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
import java.io.File;
@@ -31,7 +33,6 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyOperation;
import org.opends.server.tools.LDAPSearch;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.InitializationException;
@@ -173,13 +174,14 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
@@ -235,13 +237,14 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
@@ -298,13 +301,14 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
@@ -357,13 +361,14 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
      assertFalse(runLdapSearchTrustCertificateForSession(args) == 0);
    }
    finally
    {
@@ -429,13 +434,14 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
      assertFalse(runLdapSearchTrustCertificateForSession(args) == 0);
    }
    finally
    {
@@ -491,13 +497,14 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "",
        "-s", "base",
        "(objectClass=*)"
      };
      assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
      assertFalse(runLdapSearchTrustCertificateForSession(nullPrintStream(), nullPrintStream(), args) == 0);
    }
    finally
    {
@@ -670,13 +677,14 @@
        "-K", keyStorePath,
        "-W", "password",
        "-P", trustStorePath,
        "-r",
        "-o", "mech=EXTERNAL",
        "-N", "client-cert",
        "-b", "cn=config",
        "-s", "sub",
        "(objectClass=*)"
      };
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(runLdapSearchTrustCertificateForSession(args), 0);
    }
    finally
    {
opendj-server-legacy/src/test/java/org/opends/server/extensions/TraditionalWorkQueueTestCase.java
@@ -29,7 +29,7 @@
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.schema.SchemaConstants;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.types.Attributes;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.types.Modification;
@@ -39,6 +39,7 @@
import static org.forgerock.opendj.ldap.ModificationType.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
@@ -112,7 +113,7 @@
    for (int i=0; i < 7; i++)
    {
      assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
      assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
    }
  }
opendj-server-legacy/src/test/java/org/opends/server/extensions/UserDefinedVirtualAttributeProviderTestCase.java
@@ -31,7 +31,7 @@
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.Requests;
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.types.Attribute;
import org.opends.server.types.VirtualAttributeRule;
import org.testng.annotations.BeforeClass;
@@ -39,6 +39,7 @@
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
/**
@@ -663,7 +664,7 @@
              String.valueOf(TestCaseUtils.getServerLdapPort()), "-D",
              "cn=Directory Manager", "-w", "password", "-f", path1 };
      assertFalse(LDAPModify.mainModify(args1, false, null, null) == 0);
      assertFalse(LDAPModify.run(nullPrintStream(), nullPrintStream(), args1) == 0);
      String path2 =
          TestCaseUtils.createTempFile("dn: " + ruleDN,
@@ -676,8 +677,8 @@
              "-X", "-D", "cn=Directory Manager", "-w", "password",
              "-f", path2 };
      assertEquals(LDAPModify.mainModify(args2, false, null, null), 0);
      assertEquals(LDAPModify.mainModify(args1, false, null, null), 0);
      assertEquals(LDAPModify.run(nullPrintStream(), nullPrintStream(), args2), 0);
      assertEquals(LDAPModify.run(nullPrintStream(), nullPrintStream(), args1), 0);
    }
    finally
    {
@@ -780,7 +781,7 @@
              String.valueOf(TestCaseUtils.getServerLdapPort()), "-D",
              userDN, "-w", "password", "-f", path1 };
      assertFalse(LDAPModify.mainModify(args1, false, null, null) == 0);
      assertFalse(LDAPModify.run(nullPrintStream(), nullPrintStream(), args1) == 0);
      String path2 =
          TestCaseUtils.createTempFile("dn: " + ruleDN,
@@ -793,8 +794,8 @@
              "-X", "-D", "cn=Directory Manager", "-w", "password",
              "-f", path2 };
      assertEquals(LDAPModify.mainModify(args2, false, null, null), 0);
      assertEquals(LDAPModify.mainModify(args1, false, null, null), 0);
      assertEquals(LDAPModify.run(nullPrintStream(), nullPrintStream(), args2), 0);
      assertEquals(LDAPModify.run(nullPrintStream(), nullPrintStream(), args1), 0);
    }
    finally
    {
opendj-server-legacy/src/test/java/org/opends/server/plugins/SevenBitCleanPluginTestCase.java
@@ -12,7 +12,7 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2008 Sun Microsystems, Inc.
 * Portions Copyright 2014-2015 ForgeRock AS.
 * Portions Copyright 2014-2016 ForgeRock AS.
 */
package org.opends.server.plugins;
@@ -23,7 +23,7 @@
import org.opends.server.TestCaseUtils;
import org.forgerock.opendj.ldap.ResultCode;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import static org.testng.Assert.*;
@@ -93,7 +93,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, System.out, System.err), 0);
    assertEquals(LDAPModify.run(System.out, System.err, args), 0);
  }
@@ -133,7 +133,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, System.out, System.err), 0);
    assertEquals(LDAPModify.run(System.out, System.err, args), 0);
  }
@@ -180,8 +180,7 @@
        "-f", path
      };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPModify.run(System.out, System.err, args), 0);
    }
    finally
    {
@@ -236,8 +235,7 @@
        "-f", path
      };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                  ResultCode.CONSTRAINT_VIOLATION.intValue());
      assertEquals(LDAPModify.run(System.out, System.err, args), ResultCode.CONSTRAINT_VIOLATION.intValue());
    }
    finally
    {
@@ -294,8 +292,7 @@
        "-f", path
      };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPModify.run(System.out, System.err, args), 0);
    }
    finally
    {
@@ -349,7 +346,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, System.out, System.err), 0);
    assertEquals(LDAPModify.run(System.out, System.err, args), 0);
  }
@@ -401,8 +398,7 @@
        "-f", path
      };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                  ResultCode.CONSTRAINT_VIOLATION.intValue());
      assertEquals(LDAPModify.run(System.out, System.err, args), ResultCode.CONSTRAINT_VIOLATION.intValue());
    }
    finally
    {
@@ -462,8 +458,7 @@
        "-f", path
      };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPModify.run(System.out, System.err, args), 0);
    }
    finally
    {
@@ -523,8 +518,7 @@
        "-f", path
      };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPModify.run(System.out, System.err, args), 0);
    }
    finally
    {
@@ -577,7 +571,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, System.out, System.err), 0);
    assertEquals(LDAPModify.run(System.out, System.err, args), 0);
  }
@@ -629,8 +623,7 @@
        "-f", path
      };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                  ResultCode.CONSTRAINT_VIOLATION.intValue());
      assertEquals(LDAPModify.run(System.out, System.err, args), ResultCode.CONSTRAINT_VIOLATION.intValue());
    }
    finally
    {
@@ -690,8 +683,7 @@
        "-f", path
      };
      assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                   0);
      assertEquals(LDAPModify.run(System.out, System.err, args), 0);
    }
    finally
    {
opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/LDAPBinaryOptionTestCase.java
@@ -20,6 +20,7 @@
import static org.forgerock.opendj.ldap.SearchScope.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
import java.io.BufferedReader;
@@ -28,6 +29,7 @@
import java.io.IOException;
import java.util.List;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
@@ -38,8 +40,8 @@
import org.opends.server.core.DirectoryServer;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.tools.RemoteConnection;
import org.opends.server.types.Attribute;
import org.opends.server.types.ExistingFileBehavior;
@@ -47,7 +49,6 @@
import org.opends.server.types.LDIFExportConfig;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.SearchResultEntry;
import org.opends.server.util.Base64;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -121,10 +122,9 @@
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D","cn=directory manager",
      "-w","password",
      "-a",
      "-f", filePath
    };
    int err = LDAPModify.mainModify(args, false, null,null);
    int err = LDAPModify.run(nullPrintStream(), nullPrintStream(), args);
    assertEquals(err,0);
    //ADD with ;binary option.
@@ -142,10 +142,9 @@
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D","cn=directory manager",
      "-w","password",
      "-a",
      "-f", filePath
    };
    err = LDAPModify.mainModify(args, false, null,null);
    err = LDAPModify.run(nullPrintStream(), nullPrintStream(), args);
    assertEquals(err,0);
  }
@@ -173,10 +172,9 @@
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D","cn=directory manager",
      "-w","password",
      "-a",
      "-f", filePath,
    };
    int err = LDAPModify.mainModify(args, false, null,null);
    int err = LDAPModify.run(nullPrintStream(), nullPrintStream(), args);
    assertThat(err).isNotEqualTo(0);
  }
@@ -243,7 +241,7 @@
          .addAttribute("sn", "sn#1")
          .addAttribute("sn;x-foo", "sn#2")
          .addAttribute("sn;lang-fr", "sn#3")
          .addAttribute("userCertificate;binary", ByteString.wrap(Base64.decode(CERT)));
          .addAttribute("userCertificate;binary", ByteString.wrap(Base64.decode(CERT).toByteArray()));
      LDAPMessage message = conn.add(addRequest);
      AddResponseProtocolOp addResponse = message.getAddResponseProtocolOp();
      assertEquals(addResponse.getResultCode(),0);
@@ -302,7 +300,7 @@
        "-b", "o=test",
        "(uid=user.1)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
    exportBackend();
    assertTrue(ldif.exists());
    assertTrue(containsBinary());
@@ -380,10 +378,9 @@
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D","cn=directory manager",
      "-w","password",
      "-a",
      "-f", filePath,
    };
    int err = LDAPModify.mainModify(args, false, null,null);
    int err = LDAPModify.run(nullPrintStream(), nullPrintStream(), args);
    assertEquals(err,0);
    filePath = TestCaseUtils.createTempFile(
@@ -399,7 +396,7 @@
      "-w","password",
      "-f", filePath,
    };
    err = LDAPModify.mainModify(args, false, null,null);
    err = LDAPModify.run(nullPrintStream(), nullPrintStream(), args);
    assertEquals(err,0);
  }
opendj-server-legacy/src/test/java/org/opends/server/protocols/ldap/TestAddRequestProtocolOp.java
@@ -12,7 +12,7 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2006-2008 Sun Microsystems, Inc.
 * Portions Copyright 2013-2015 ForgeRock AS.
 * Portions Copyright 2013-2016 ForgeRock AS.
 */
package org.opends.server.protocols.ldap;
@@ -27,11 +27,11 @@
import org.forgerock.opendj.io.ASN1;
import org.forgerock.opendj.io.ASN1Reader;
import org.forgerock.opendj.io.ASN1Writer;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.types.LDAPException;
import org.opends.server.types.RawAttribute;
import org.opends.server.util.Base64;
import org.testng.annotations.Test;
/**
@@ -363,7 +363,7 @@
    BufferedReader reader =
        new BufferedReader(new StringReader(buffer.toString()));
    String line = reader.readLine();
    assertEquals(line, "dn:: "+Base64.encode(dnNeedsBase64));
    assertEquals(line, "dn:: "+ Base64.encode(dnNeedsBase64));
    for (int i = 0; i < numAttributes; i++)
    {
      for (int j = 0; j < numValues; j++)
opendj-server-legacy/src/test/java/org/opends/server/replication/ChangeNumberControlPluginTestCase.java
@@ -16,19 +16,23 @@
 */
package org.opends.server.replication;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.Connection;
import org.forgerock.opendj.ldap.LDAPConnectionFactory;
import org.forgerock.opendj.ldap.controls.Control;
import org.forgerock.opendj.ldap.requests.AddRequest;
import org.forgerock.opendj.ldap.requests.DeleteRequest;
import org.forgerock.opendj.ldap.requests.ModifyDNRequest;
import org.forgerock.opendj.ldap.requests.ModifyRequest;
import org.forgerock.opendj.ldap.requests.Requests;
import org.forgerock.opendj.ldap.responses.Result;
import org.forgerock.util.promise.ResultHandler;
import org.opends.server.TestCaseUtils;
import org.opends.server.tools.LDAPModify;
import org.forgerock.opendj.ldap.DN;
import org.opends.server.util.StaticUtils;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.opends.messages.ToolMessages.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.util.ServerConstants.*;
import static org.testng.Assert.*;
@@ -37,10 +41,43 @@
public class ChangeNumberControlPluginTestCase extends ReplicationTestCase
{
  /**
   * The port of the replicationServer.
   */
  private int replServerPort;
  private static final String HOSTNAME = "127.0.0.1";
  private static final Control CSN_CONTROL = new Control()
  {
    @Override
    public String getOID()
    {
      return OID_CSN_CONTROL;
    }
    @Override
    public ByteString getValue()
    {
      return null;
    }
    @Override
    public boolean hasValue()
    {
      return false;
    }
    @Override
    public boolean isCritical()
    {
      return false;
    }
  };
  private static final ResultHandler<Result> ASSERTION_RESULT_HANDLER = new ResultHandler<Result>()
  {
    @Override
    public void handleResult(final Result result)
    {
      assertTrue(result.containsControl(CSN_CONTROL.getOID()));
    }
  };
  /**
   * The replicationServer that will be used in this test.
@@ -58,8 +95,7 @@
    super.setUp();
    baseDn = DN.valueOf(TEST_ROOT_DN_STRING);
    replServerPort = TestCaseUtils.findFreePort();
    final int replServerPort = TestCaseUtils.findFreePort();
    // replication server
    String replServerLdif =
@@ -86,79 +122,61 @@
    configureReplication(replServerLdif, synchroServerLdif);
  }
  @DataProvider(name = "operations")
  public Object[][] createLdapRequests() {
    return new Object[][] {
      new Object[] {
        "dn: cn=user1," + baseDn + "\n"
         + "changetype: add" + "\n"
         + "objectClass: person" + "\n"
         + "cn: user1" + "\n"
         + "sn: User Test 10"},
      new Object[] {
         "dn: cn=user1," + baseDn + "\n"
         + "changetype: modify" + "\n"
         + "add: description" + "\n"
         + "description: blah"},
      new Object[] {
         "dn: cn=user1," + baseDn + "\n"
         + "changetype: moddn" + "\n"
         + "newrdn: cn=user111" + "\n"
         + "deleteoldrdn: 1"},
      new Object[] {
         "dn: cn=user111," + baseDn + "\n"
         + "changetype: delete"}
    };
  }
  @Test(dataProvider="operations")
  public void ChangeNumberControlTest(String request) throws Exception {
    String path = TestCaseUtils.createTempFile(request);
    String[] args =
  @Test
  public void changeNumberControlAddRequestTest() throws Exception {
    try (final LDAPConnectionFactory factory = new LDAPConnectionFactory(HOSTNAME, getServerLdapPort());
         final Connection connection = factory.getConnection())
    {
      "-h", "127.0.0.1",
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D", "cn=Directory Manager",
      "-w", "password",
      "-J", OID_CSN_CONTROL + ":false",
      "--noPropertiesFile",
      "-f", path
    };
    String resultPath = TestCaseUtils.createTempFile();
    FileOutputStream fos = new FileOutputStream(resultPath);
    assertEquals(LDAPModify.mainModify(args, false, fos, System.err), 0);
    //fos.flush();
    fos.close();
    assertTrue(isCsnLinePresent(resultPath));
  }
  private boolean isCsnLinePresent(String file) throws Exception {
    FileReader fr = new FileReader(file);
    try
    {
      BufferedReader br = new BufferedReader(fr);
      String line = null;
      boolean found = false;
      while ((line = br.readLine()) != null)
      {
        if (line.contains(INFO_CHANGE_NUMBER_CONTROL_RESULT.get("%s", "%s")
            .toString().split("%s")[1]))
        {
          found = true;
        }
      }
      return found;
    }
    finally
    {
      StaticUtils.close(fr);
      final AddRequest addRequest = Requests.newAddRequest("dn: cn=user1," + baseDn,
                                                           "changetype: add",
                                                           "objectClass: person",
                                                           "cn: user1",
                                                           "sn: User Test 10")
                                               .addControl(CSN_CONTROL);
      connection.addAsync(addRequest)
                .thenOnResult(ASSERTION_RESULT_HANDLER);
    }
  }
  @Test
  public void changeNumberControlDeleteRequestTest() throws Exception
  {
    try (final LDAPConnectionFactory factory = new LDAPConnectionFactory(HOSTNAME, getServerLdapPort());
         final Connection connection = factory.getConnection())
    {
      final DeleteRequest deleteRequest = Requests.newDeleteRequest("cn=user111," + baseDn)
                                                  .addControl(CSN_CONTROL);
      connection.deleteAsync(deleteRequest)
                .thenOnResult(ASSERTION_RESULT_HANDLER);
    }
  }
  @Test
  public void changeNumberControlModifyRequestTest() throws Exception
  {
    try (final LDAPConnectionFactory factory = new LDAPConnectionFactory(HOSTNAME, getServerLdapPort());
         final Connection connection = factory.getConnection())
    {
      final ModifyRequest modifyRequest = Requests.newModifyRequest("dn: cn=user1," + baseDn,
                                                                    "changetype: modify",
                                                                    "add: description",
                                                                    "description: blah")
                                                  .addControl(CSN_CONTROL);
      connection.modifyAsync(modifyRequest).thenOnResult(ASSERTION_RESULT_HANDLER);
    }
  }
  @Test
  public void changeNumberControlModifyDNRequestTest() throws Exception
  {
    try (final LDAPConnectionFactory factory = new LDAPConnectionFactory(HOSTNAME, getServerLdapPort());
         final Connection connection = factory.getConnection())
    {
      final ModifyDNRequest modifyDNRequest = Requests.newModifyDNRequest("cn=user.1" + baseDn, "cn=user.111")
                                                      .addControl(CSN_CONTROL)
                                                      .setDeleteOldRDN(true);
      connection.modifyDNAsync(modifyDNRequest)
                .thenOnResult(ASSERTION_RESULT_HANDLER);
    }
  }
}
opendj-server-legacy/src/test/java/org/opends/server/replication/InitOnLineTest.java
@@ -25,6 +25,7 @@
import org.assertj.core.api.Assertions;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.opendj.ldap.SearchScope;
@@ -49,7 +50,6 @@
import org.opends.server.replication.service.ReplicationBroker;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.util.Base64;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -351,8 +351,7 @@
                   + "cn: "+useri+"_cn"+"\n"
                   + "sn: "+useri+"_sn"+"\n"
                   + "uid: "+useri+"_uid"+"\n"
                   + "description:: "+ Base64.encode(
                       new String(bigAttributeValue).getBytes())+"\n"
                   + "description:: "+ Base64.encode(new String(bigAttributeValue).getBytes()) +"\n"
                   + "entryUUID: 21111111-1111-1111-1111-"+useri+
                   filler.substring(0, 12-useri.length())+"\n"
                   + "\n";
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java
@@ -22,6 +22,7 @@
import static org.forgerock.opendj.ldap.SearchScope.*;
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
@@ -43,7 +44,7 @@
import org.opends.server.replication.protocol.LDAPUpdateMsg;
import org.opends.server.replication.protocol.ModifyMsg;
import org.opends.server.replication.service.ReplicationBroker;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.types.Attribute;
import org.opends.server.types.Attributes;
import org.opends.server.types.DirectoryException;
@@ -614,6 +615,6 @@
  private void ldapmodify(String[] args)
  {
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
  }
}
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/ReplicationRepairControlTest.java
@@ -12,14 +12,16 @@
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2008-2010 Sun Microsystems, Inc.
 * Portions Copyright 2015 ForgeRock AS.
 * Portions Copyright 2015-2016 ForgeRock AS.
 */
package org.opends.server.replication.plugin;
import org.opends.server.TestCaseUtils;
import org.opends.server.replication.ReplicationTestCase;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.testng.annotations.Test;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
import static org.opends.server.TestCaseUtils.*;
@@ -53,11 +55,10 @@
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D", "cn=Directory Manager",
      "-w", "password",
      "-a",
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, null), 53);
    assertEquals(LDAPModify.run(nullPrintStream(), nullPrintStream(), args), 53);
    // Test that we can't add an entry with the ds-sync-hist attribute
    // without specifying the replication repair control.
@@ -81,12 +82,11 @@
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D", "cn=Directory Manager",
      "-w", "password",
      "-a",
      "-f", path1
    };
    assertEquals(LDAPModify.mainModify(args1, false, null, null), 53);
    assertEquals(LDAPModify.run(nullPrintStream(), nullPrintStream(), args1), 53);
    // Now Test specifying the replication repair control makes
    // possible to add an entry with the entryuuid and ds-sync-hist attributes
@@ -113,10 +113,9 @@
      "-D", "cn=Directory Manager",
      "-w", "password",
      "-J", "1.3.6.1.4.1.26027.1.5.2",
      "-a",
      "-f", path2
    };
    assertEquals(LDAPModify.mainModify(args2, false, null, null), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), nullPrintStream(), args2), 0);
  }
}
opendj-server-legacy/src/test/java/org/opends/server/replication/server/MonitorTest.java
@@ -20,6 +20,7 @@
import static org.testng.Assert.*;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.net.SocketException;
import java.util.Arrays;
import java.util.SortedSet;
@@ -39,7 +40,7 @@
import org.opends.server.replication.server.changelog.file.ECLEnabledDomainPredicate;
import org.opends.server.replication.service.DSRSShutdownSync;
import org.opends.server.replication.service.ReplicationBroker;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.types.Entry;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -429,8 +430,7 @@
    oStream.reset();
    eStream.reset();
    int retVal =
      LDAPSearch.mainSearch(args3, false, oStream, eStream);
    int retVal = LDAPSearch.run(new PrintStream(oStream), new PrintStream(eStream), args3);
    String entries = oStream.toString();
    debugInfo("Entries:" + entries);
    assertEquals(retVal, 0, "Returned error: " + eStream);
opendj-server-legacy/src/test/java/org/opends/server/schema/CollationMatchingRuleTest.java
@@ -27,7 +27,7 @@
import org.opends.server.controls.VLVRequestControl;
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.opends.server.types.Control;
import org.opends.server.types.Entry;
import org.opends.server.types.LDAPException;
@@ -41,6 +41,7 @@
import static org.forgerock.opendj.ldap.SearchScope.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
/** Integration tests for collation matching rules. */
@@ -89,10 +90,9 @@
      "-p", String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-D","cn=directory manager",
      "-w","password",
      "-a",
      "-f", filePath,
    };
    int err = LDAPModify.mainModify(args, false, null,null);
    int err = LDAPModify.run(nullPrintStream(), nullPrintStream(), args);
    assertEquals(err,0);
  }
opendj-server-legacy/src/test/java/org/opends/server/tasks/AllowedTaskTestCase.java
@@ -21,7 +21,7 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.protocols.ldap.LDAPResultCode;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.forgerock.opendj.ldap.DN;
import static org.testng.Assert.*;
@@ -76,8 +76,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                 LDAPResultCode.UNWILLING_TO_PERFORM);
    assertEquals(LDAPModify.run(System.out, System.err, args), LDAPResultCode.UNWILLING_TO_PERFORM);
    // Update the set of allowed tasks to include the dummy task.
@@ -105,8 +104,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                 LDAPResultCode.SUCCESS);
    assertEquals(LDAPModify.run(System.out, System.err, args), LDAPResultCode.SUCCESS);
    waitTaskCompletedSuccessfully(DN.valueOf(
         "ds-task-id=testAllowedTask 2,cn=Scheduled Tasks,cn=Tasks"));
@@ -138,8 +136,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, System.out, System.err),
                 LDAPResultCode.UNWILLING_TO_PERFORM);
    assertEquals(LDAPModify.run(System.out, System.err, args), LDAPResultCode.UNWILLING_TO_PERFORM);
  }
}
opendj-server-legacy/src/test/java/org/opends/server/tasks/LockdownModeTaskTestCase.java
@@ -24,10 +24,11 @@
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.tools.LDAPSearch;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.forgerock.opendj.ldap.DN;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
/** Tests the enter and leave lockdown mode tasks. */
@@ -98,7 +99,7 @@
      "--noPropertiesFile",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
    // Create a file that holds the LDIF for putting the server in lockdown
@@ -126,8 +127,7 @@
      "--noPropertiesFile",
      "-f", taskFile
    };
    assertFalse(LDAPModify.mainModify(args, false, null, System.err) == 0);
    assertFalse(LDAPModify.run(nullPrintStream(), System.err, args) == 0);
    // If the local address isn't a loopback address, then verify that we can't
    // put the server in lockdown mode using it.
@@ -140,10 +140,10 @@
        "-Z", "-X",
        "-D", "cn=Directory Manager",
        "-w", "password",
      "--noPropertiesFile",
        "--noPropertiesFile",
        "-f", taskFile
      };
      assertFalse(LDAPModify.mainModify(args, false, null, System.err) == 0);
      assertFalse(LDAPModify.run(nullPrintStream(), System.err, args) == 0);
    }
@@ -159,7 +159,7 @@
      "--noPropertiesFile",
      "-f", taskFile
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    waitTaskCompletedSuccessfully(taskDN);
    assertTrue(DirectoryServer.lockdownMode());
@@ -179,7 +179,7 @@
        "--noPropertiesFile",
        "(objectClass=*)"
      };
      assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
      assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
    }
@@ -195,7 +195,7 @@
      "--noPropertiesFile",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
    // Make sure that we can no longer retrieve the server's root DSE over an
@@ -212,7 +212,7 @@
      "--noPropertiesFile",
      "(objectClass=*)"
    };
    assertFalse(LDAPSearch.mainSearch(args, false, null, null) == 0);
    assertFalse(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args) == 0);
    // Make sure that we can retrieve the server's root DSE over a
@@ -228,7 +228,7 @@
      "--noPropertiesFile",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, null), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), nullPrintStream(), args), 0);
    // Use another task to take the server out of lockdown mode and make sure it
@@ -254,7 +254,7 @@
      "--noPropertiesFile",
      "-f", taskFile
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    waitTaskCompletedSuccessfully(taskDN);
    assertFalse(DirectoryServer.lockdownMode());
@@ -270,7 +270,7 @@
      "--noPropertiesFile",
      "(objectClass=*)"
    };
    assertEquals(LDAPSearch.mainSearch(args, false, null, System.err), 0);
    assertEquals(LDAPSearch.run(nullPrintStream(), System.err, args), 0);
  }
}
opendj-server-legacy/src/test/java/org/opends/server/tools/ArgumentParserToolsTestCase.java
@@ -130,54 +130,6 @@
  }
  @Test(dataProvider = "invalidArgs")
  public void testLDAPCompare(final String[] args)
  {
    assertToolFailsWithUsage(LDAPCompare.mainCompare(args, false, outStream, errStream));
  }
  @Test(dataProvider = "invalidArg")
  public void testLDAPDelete(final String[] args)
  {
    assertToolFailsWithUsage(LDAPDelete.mainDelete(args, false, outStream, errStream));
  }
  @Test(dataProvider = "invalidArg")
  public void testLDAPModify(final String[] args)
  {
    assertToolFailsWithUsage(LDAPModify.mainModify(args, false, outStream, errStream));
  }
  @Test(dataProvider = "invalidArg")
  public void testLDAPPasswordModify(final String[] args)
  {
    assertToolFailsWithUsage(LDAPPasswordModify.mainPasswordModify(args, false, outStream, errStream));
  }
  @Test(dataProvider = "invalidArgs")
  public void testLDAPSearch(final String[] args)
  {
    assertToolFailsWithUsage(LDAPSearch.mainSearch(args, false, outStream, errStream));
  }
  @Test(dataProvider = "invalidArgs")
  public void testLDIFDiff(final String[] args)
  {
    assertToolFailsWithUsage(LDIFDiff.mainDiff(args, false, outStream, errStream));
  }
  @Test(dataProvider = "invalidArgs")
  public void testLDIFModify(final String[] args)
  {
    assertToolFailsWithUsage(LDIFModify.ldifModifyMain(args, false, outStream, errStream));
  }
  @Test(dataProvider = "invalidArg")
  public void testLDIFSearch(final String[] args)
  {
    assertToolFailsWithUsage(LDIFSearch.mainSearch(args, false, outStream, errStream));
  }
  @Test(dataProvider = "invalidArgs")
  public void testListBackends(final String[] args)
  {
    assertToolFailsWithUsage(ListBackends.listBackends(args, false, outStream, errStream));
opendj-server-legacy/src/test/java/org/opends/server/types/EntrySchemaCheckingTestCase.java
@@ -17,6 +17,7 @@
package org.opends.server.types;
import static org.opends.server.types.AcceptRejectWarn.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.testng.Assert.*;
import java.util.LinkedList;
@@ -27,7 +28,7 @@
import org.forgerock.opendj.ldap.schema.CoreSchema;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import org.testng.annotations.Test;
/**
@@ -275,7 +276,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -319,7 +320,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -363,7 +364,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -495,7 +496,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -550,7 +551,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -599,7 +600,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -650,7 +651,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -699,7 +700,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -749,7 +750,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -801,7 +802,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -852,7 +853,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -901,7 +902,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -951,7 +952,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: description=foo,o=test",
@@ -1001,7 +1002,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test+description=foo,o=test",
@@ -1052,7 +1053,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: description=foo,o=test",
@@ -1106,7 +1107,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test+description=foo,o=test",
@@ -1160,7 +1161,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -1211,7 +1212,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test,o=test",
@@ -1264,7 +1265,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: cn=test+description=foo,o=test",
@@ -1317,7 +1318,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
         "dn: description=foo,o=test",
@@ -1383,7 +1384,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    Entry e = TestCaseUtils.makeEntry(
@@ -1411,7 +1412,7 @@
      "-f", path
    };
    assertEquals(LDAPModify.mainModify(args, false, null, System.err), 0);
    assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
    LocalizableMessageBuilder invalidReason = new LocalizableMessageBuilder();
    assertTrue(e.conformsToSchema(null, false, true, true, invalidReason),
opendj-server-legacy/src/test/java/org/opends/server/types/PrivilegeTestCase.java
@@ -60,9 +60,9 @@
import org.opends.server.protocols.internal.InternalSearchOperation;
import org.opends.server.protocols.internal.Requests;
import org.opends.server.protocols.internal.SearchRequest;
import org.opends.server.tools.LDAPModify;
import org.opends.server.tools.LDAPPasswordModify;
import org.opends.server.tools.LDAPSearch;
import com.forgerock.opendj.ldap.tools.LDAPModify;
import com.forgerock.opendj.ldap.tools.LDAPPasswordModify;
import com.forgerock.opendj.ldap.tools.LDAPSearch;
import org.opends.server.tools.RemoteConnection;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
@@ -75,6 +75,7 @@
import static org.opends.server.TestCaseUtils.*;
import static org.opends.server.protocols.internal.InternalClientConnection.*;
import static org.opends.server.protocols.internal.Requests.*;
import static org.opends.server.types.NullOutputStream.nullPrintStream;
import static org.opends.server.types.Privilege.*;
import static org.opends.server.util.CollectionUtils.*;
import static org.testng.Assert.*;
@@ -732,7 +733,7 @@
      "-f", path
    };
    int resultCode = LDAPModify.mainModify(args, false, null, null);
    int resultCode = LDAPModify.run(nullPrintStream(), nullPrintStream(), args);
    if (hasPrivilege)
    {
      assertEquals(resultCode, 0);
@@ -798,7 +799,7 @@
    };
    int resultCode =
             LDAPPasswordModify.mainPasswordModify(args, false, null, null);
             LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args);
    if (hasPrivilege)
    {
      assertEquals(resultCode, 0);
@@ -813,8 +814,7 @@
        "-a", "dn:cn=PWReset Target,o=test",
        "-n", "password"
      };
      assertEquals(LDAPPasswordModify.mainPasswordModify(args, false, null,
                                                         null), 0);
      assertEquals(LDAPPasswordModify.run(nullPrintStream(), nullPrintStream(), args), 0);
    }
    else
    {
@@ -2193,12 +2193,12 @@
  private int runSearch(String[] args)
  {
    return LDAPSearch.mainSearch(args, false, null, null);
    return LDAPSearch.run(nullPrintStream(), nullPrintStream(), args);
  }
  private int runSearchWithSystemErr(String[] args)
  {
    return LDAPSearch.mainSearch(args, false, null, System.err);
    return LDAPSearch.run(nullPrintStream(), System.err, args);
  }
  /**
opendj-server-legacy/src/test/java/org/opends/server/types/SearchFilterTests.java
@@ -23,12 +23,12 @@
import java.util.LinkedHashSet;
import java.util.List;
import org.forgerock.opendj.ldap.Base64;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.opends.server.DirectoryServerTestCase;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.util.Base64;
import org.opends.server.util.StaticUtils;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
@@ -1031,7 +1031,7 @@
          "userCertificate;binary:: "+BASE64_CERT_VALUE
          );
    StringBuilder builder = new StringBuilder();
    RawFilter.valueToFilterString(builder,ByteString.wrap(Base64.decode(BASE64_CERT_VALUE)));
    RawFilter.valueToFilterString(builder, ByteString.wrap(Base64.decode(BASE64_CERT_VALUE).toByteArray()));
    final String CERTIFICATE_ENCODED = builder.toString();
    return new Object[][]{
opendj-server-legacy/src/test/java/org/opends/server/util/TestBase64.java
File was deleted