From b550433da7f957bd8aabbbf5011ecaa80215259d Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 24 Feb 2016 22:30:11 +0000
Subject: [PATCH] OPENDJ-2588 remove prototype setup CLI
---
/dev/null | 87 -------------------------------------------
1 files changed, 0 insertions(+), 87 deletions(-)
diff --git a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/cli/SetupCli.java b/opendj-server/src/main/java/org/forgerock/opendj/server/setup/cli/SetupCli.java
deleted file mode 100644
index d2a22d9..0000000
--- a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/cli/SetupCli.java
+++ /dev/null
@@ -1,538 +0,0 @@
-/*
- * 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 2014-2016 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.cli;
-
-import static com.forgerock.opendj.cli.Utils.filterExitCode;
-import static com.forgerock.opendj.cli.Utils.LINE_SEPARATOR;
-import static com.forgerock.opendj.cli.Utils.checkJavaVersion;
-import static com.forgerock.opendj.cli.CliMessages.*;
-import static com.forgerock.opendj.cli.CliConstants.*;
-import static com.forgerock.opendj.cli.CommonArguments.*;
-
-import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.i18n.LocalizableMessageBuilder;
-import org.forgerock.i18n.slf4j.LocalizedLogger;
-
-import com.forgerock.opendj.cli.Argument;
-import com.forgerock.opendj.cli.ArgumentException;
-import com.forgerock.opendj.cli.BooleanArgument;
-import com.forgerock.opendj.cli.ClientException;
-import com.forgerock.opendj.cli.ConsoleApplication;
-import com.forgerock.opendj.cli.FileBasedArgument;
-import com.forgerock.opendj.cli.IntegerArgument;
-import com.forgerock.opendj.cli.ReturnCode;
-import com.forgerock.opendj.cli.StringArgument;
-import com.forgerock.opendj.cli.SubCommand;
-import com.forgerock.opendj.cli.SubCommandArgumentParser;
-import com.forgerock.opendj.cli.Utils;
-
-/**
- * This class implements the new CLI for OpenDJ3 setup.
- */
-public final class SetupCli extends ConsoleApplication {
-
- /**
- * Setup's logger.
- */
- private static final LocalizedLogger LOG = LocalizedLogger.getLoggerForThisClass();
-
- /**
- * TODO remove that after implementation in config.
- *
- * @return The installation path.
- */
- static String getInstallationPath() {
- return "/home/violette/OpenDJ-3.0.0/";
- }
-
- /**
- * TODO remove that after implementation in config.
- *
- * @return The instance path.
- */
- static String getInstancePath() {
- return "/home/violette/OpenDJ-3.0.0/";
- }
-
-
- private SubCommandArgumentParser argParser;
-
- private BooleanArgument cli;
- private BooleanArgument addBaseEntry;
- private BooleanArgument skipPortCheck;
- private BooleanArgument enableWindowsService;
- private BooleanArgument doNotStart;
- private BooleanArgument enableStartTLS;
- private BooleanArgument generateSelfSignedCertificate;
- private StringArgument hostName;
- private BooleanArgument usePkcs11;
- private FileBasedArgument directoryManagerPwdFile;
- private FileBasedArgument keyStorePasswordFile;
- private IntegerArgument ldapPort;
- private IntegerArgument adminConnectorPort;
- private IntegerArgument ldapsPort;
- private IntegerArgument jmxPort;
- private IntegerArgument sampleData;
- private StringArgument baseDN;
- private StringArgument importLDIF;
- private StringArgument rejectedImportFile;
- private StringArgument skippedImportFile;
- private StringArgument directoryManagerDN;
- private StringArgument directoryManagerPwdString;
- private StringArgument useJavaKeyStore;
- private StringArgument useJCEKS;
- private StringArgument usePkcs12;
- private StringArgument keyStorePassword;
- private StringArgument certNickname;
- private IntegerArgument connectTimeout;
- private BooleanArgument acceptLicense;
-
- /** Sub-commands. */
- private SubCommand createDirectoryServer;
- private SubCommand createProxy;
-
- /** Register the global arguments. */
- private BooleanArgument noPrompt;
- private BooleanArgument quietMode;
- private BooleanArgument verbose;
- private StringArgument propertiesFile;
- private BooleanArgument noPropertiesFile;
- private BooleanArgument showUsage;
-
- private SetupCli() {
- // Nothing to do.
- }
-
- /** To allow tests. */
- SetupCli(PrintStream out, PrintStream err) {
- super(out, err);
- }
-
- /**
- * The main method for setup tool.
- *
- * @param args
- * The command-line arguments provided to this program.
- */
- public static void main(final String[] args) {
- final int retCode = new SetupCli().run(args);
- System.exit(filterExitCode(retCode));
- }
-
- /** Create the command-line argument parser for use with this program. */
- int run(final String[] args) {
- // TODO Activate logger when the instance/installation path will be resolved.
- // SetupLog.initLogFileHandler();
-
- try {
- checkJavaVersion();
- } catch (ClientException e) {
- errPrintln(e.getMessageObject());
- return ReturnCode.JAVA_VERSION_INCOMPATIBLE.get();
- }
-
- try {
- argParser = new SubCommandArgumentParser("setup", INFO_SETUP_DESCRIPTION.get(), true);
- initializeArguments();
- } catch (ArgumentException e) {
- final LocalizableMessage message = ERR_CANNOT_INITIALIZE_ARGS.get(e.getMessage());
- errPrintln(message);
- return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get();
- }
-
- // Parse the command-line arguments provided to this program.
- try {
- argParser.parseArguments(args);
-
- if (argParser.usageOrVersionDisplayed()) {
- // If we should just display usage or version information, then print it and exit.
- return ReturnCode.SUCCESS.get();
- }
- } catch (final ArgumentException e) {
- final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(e.getMessage());
- errPrintln(message);
- return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get();
- }
-
- // Verifying provided informations.
- try {
- final LinkedHashSet<LocalizableMessage> errorMessages = new LinkedHashSet<>();
- checkServerPassword(errorMessages);
- checkProvidedPorts(errorMessages);
- checkImportDataArguments(errorMessages);
- checkSecurityArguments(errorMessages);
- if (errorMessages.size() > 0) {
- throw new ArgumentException(ERR_CANNOT_INITIALIZE_ARGS.get(
- getMessageFromCollection(errorMessages, LINE_SEPARATOR)));
- }
- } catch (final ArgumentException e) {
- errPrintln(e.getMessageObject());
- return ReturnCode.CLIENT_SIDE_PARAM_ERROR.get();
- }
-
- // Starts setup process.
- try {
- fillSetupSettings();
- runSetupInstallation();
- } catch (ClientException ex) {
- return ex.getReturnCode();
- } catch (Exception ex) {
- // TODO
- //println(Style.ERROR, LocalizableMessage.raw("...?"));
- return ReturnCode.ERROR_UNEXPECTED.get();
- }
- return ReturnCode.SUCCESS.get();
- }
-
- /**
- * Initialize setup's arguments by default.
- *
- * @throws ArgumentException
- * If an exception occurs during the initialization of the arguments.
- */
- private void initializeArguments() throws ArgumentException {
- // Options.
- acceptLicense = addGlobal(acceptLicenseArgument());
- cli = addGlobal(cliArgument());
- baseDN = addGlobal(baseDNArgument());
- addBaseEntry = addGlobal(addBaseEntryArgument());
- importLDIF = addGlobal(ldifFileArgument(INFO_DESCRIPTION_IMPORTLDIF.get()));
- rejectedImportFile = addGlobal(rejectedImportLdifArgument());
- skippedImportFile = addGlobal(skippedImportFileArgument());
- sampleData = addGlobal(sampleDataArgument());
- ldapPort = addGlobal(ldapPortArgument(DEFAULT_LDAP_PORT));
- ldapsPort = addGlobal(ldapsPortArgument(DEFAULT_LDAPS_PORT));
- adminConnectorPort = addGlobal(adminLdapPortArgument(DEFAULT_ADMIN_PORT));
- jmxPort = addGlobal(jmxPortArgument(DEFAULT_JMX_PORT));
- skipPortCheck = addGlobal(skipPortCheckArgument());
- directoryManagerDN = addGlobal(rootDNArgument());
- directoryManagerPwdString = addGlobal(rootDNPwdArgument());
- directoryManagerPwdFile = addGlobal(rootDNPwdFileArgument());
- enableWindowsService = addGlobal(enableWindowsServiceArgument());
- doNotStart = addGlobal(doNotStartArgument());
- enableStartTLS = addGlobal(enableTLSArgument());
- generateSelfSignedCertificate = addGlobal(generateSelfSignedArgument());
- hostName = addGlobal(hostNameArgument(Utils.getDefaultHostName()));
- usePkcs11 = addGlobal(usePKCS11KeystoreArgument());
- useJavaKeyStore = addGlobal(useJavaKeyStoreArgument());
- useJCEKS = addGlobal(useJCEKSArgument());
- usePkcs12 = addGlobal(usePKCS12KeyStoreArgument());
- keyStorePassword = addGlobal(keyStorePasswordArgument());
- keyStorePasswordFile = addGlobal(keyStorePasswordFileArgument());
- certNickname = addGlobal(certNickNameArgument());
- connectTimeout = connectTimeOutHiddenArgument();
-
- // Utility Input Output Options.
- noPrompt = addGlobal(noPromptArgument());
- quietMode = addGlobal(quietArgument());
- verbose = addGlobal(verboseArgument());
- propertiesFile = addGlobal(propertiesFileArgument());
- noPropertiesFile = addGlobal(noPropertiesFileArgument());
- showUsage = addGlobal(showUsageArgument());
-
- //Sub-commands && their arguments
- final ArrayList<SubCommand> subCommandList = new ArrayList<>(2);
- createDirectoryServer = new SubCommand(argParser, "create-directory-server",
- INFO_SETUP_SUBCOMMAND_CREATE_DIRECTORY_SERVER.get());
- // TODO to complete.
- createProxy = new SubCommand(argParser, "create-proxy",
- INFO_SETUP_SUBCOMMAND_CREATE_PROXY.get());
- subCommandList.add(createDirectoryServer);
- subCommandList.add(createProxy);
-
- argParser.setUsageGroupArgument(showUsage, subCommandList);
-
- // Register the global arguments.
- argParser.addArgument(showUsage);
- argParser.setUsageArgument(showUsage, getOutputStream());
- argParser.addArgument(noPropertiesFile);
- argParser.setNoPropertiesFileArgument(noPropertiesFile);
- argParser.addArgument(propertiesFile);
- argParser.setFilePropertiesArgument(propertiesFile);
- argParser.addArgument(quietMode);
- argParser.addArgument(verbose);
- argParser.addArgument(noPrompt);
- argParser.addArgument(acceptLicense);
- }
-
- private <A extends Argument> A addGlobal(A arg) throws ArgumentException {
- argParser.addGlobalArgument(arg);
- return arg;
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean isInteractive() {
- return !noPrompt.isPresent();
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean isQuiet() {
- return quietMode.isPresent();
- }
-
- /**
- * Automatically accepts the license if it's present.
- *
- * @return {@code true} if license is accepted by default.
- */
- private boolean isAcceptLicense() {
- return acceptLicense.isPresent();
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean isVerbose() {
- return verbose.isPresent();
- }
-
- /**
- * Returns whether the command was launched in CLI mode or not.
- *
- * @return <CODE>true</CODE> if the command was launched to use CLI mode and <CODE>false</CODE> otherwise.
- */
- public boolean isCli() {
- return cli.isPresent();
- }
-
- /**
- * Returns whether the command was launched to setup proxy or not.
- *
- * @return <CODE>true</CODE> if the command was launched to setup a proxy and <CODE>false</CODE> otherwise.
- */
- public boolean isCreateProxy() {
- return argParser.getSubCommand("create-proxy") != null;
- }
-
- /**
- * Checks that there are no conflicts with the provided ports (like if the user provided the same port for different
- * protocols).
- *
- * @param errorMessages
- * the list of messages to which we add the error messages describing the problems encountered during the
- * execution of the checking.
- */
- private void checkProvidedPorts(final Collection<LocalizableMessage> errorMessages) {
- // Check that the provided ports do not match.
- try {
- final Set<Integer> ports = new HashSet<>();
- ports.add(ldapPort.getIntValue());
-
- checkPortArgument(adminConnectorPort, ports, errorMessages);
-
- if (jmxPort.isPresent()) {
- checkPortArgument(jmxPort, ports, errorMessages);
- }
- if (ldapsPort.isPresent()) {
- checkPortArgument(ldapsPort, ports, errorMessages);
- }
- } catch (ArgumentException ae) {
- LOG.error(LocalizableMessage.raw("Unexpected error. "
- + "Assuming that it is caused by a previous parsing issue: " + ae, ae));
- }
- }
-
- private void checkPortArgument(IntegerArgument portArg, final Set<Integer> ports,
- final Collection<LocalizableMessage> errorMessages) throws ArgumentException {
- if (ports.contains(portArg.getIntValue())) {
- errorMessages.add(ERR_PORT_ALREADY_SPECIFIED.get(portArg.getIntValue()));
- } else {
- ports.add(portArg.getIntValue());
- }
- }
-
- /**
- * Checks that there are no conflicts with the import data arguments.
- *
- * @param errorMessages
- * the list of messages to which we add the error messages describing the problems encountered during the
- * execution of the checking.
- */
- private void checkImportDataArguments(final Collection<LocalizableMessage> errorMessages) {
- // Make sure that the user didn't provide conflicting arguments.
- if (addBaseEntry.isPresent()) {
- if (importLDIF.isPresent()) {
- errorMessages.add(ERR_TOOL_CONFLICTING_ARGS.get(addBaseEntry.getLongIdentifier(),
- importLDIF.getLongIdentifier()));
- } else if (sampleData.isPresent()) {
- errorMessages.add(ERR_TOOL_CONFLICTING_ARGS.get(addBaseEntry.getLongIdentifier(),
- sampleData.getLongIdentifier()));
- }
- } else if (importLDIF.isPresent() && sampleData.isPresent()) {
- errorMessages.add(ERR_TOOL_CONFLICTING_ARGS.get(importLDIF.getLongIdentifier(),
- sampleData.getLongIdentifier()));
- }
-
- if (rejectedImportFile.isPresent() && addBaseEntry.isPresent()) {
- errorMessages.add(ERR_TOOL_CONFLICTING_ARGS.get(addBaseEntry.getLongIdentifier(),
- rejectedImportFile.getLongIdentifier()));
- } else if (rejectedImportFile.isPresent() && sampleData.isPresent()) {
- errorMessages.add(ERR_TOOL_CONFLICTING_ARGS.get(rejectedImportFile.getLongIdentifier(),
- sampleData.getLongIdentifier()));
- }
-
- if (skippedImportFile.isPresent() && addBaseEntry.isPresent()) {
- errorMessages.add(ERR_TOOL_CONFLICTING_ARGS.get(addBaseEntry.getLongIdentifier(),
- skippedImportFile.getLongIdentifier()));
- } else if (skippedImportFile.isPresent() && sampleData.isPresent()) {
- errorMessages.add(ERR_TOOL_CONFLICTING_ARGS.get(skippedImportFile.getLongIdentifier(),
- sampleData.getLongIdentifier()));
- }
-
- if (noPrompt.isPresent() && !baseDN.isPresent() && baseDN.getDefaultValue() == null) {
- final Argument[] args = { importLDIF, addBaseEntry, sampleData };
- for (final Argument arg : args) {
- if (arg.isPresent()) {
- errorMessages.add(ERR_ARGUMENT_NO_BASE_DN_SPECIFIED.get("--" + arg.getLongIdentifier()));
- }
- }
- }
- }
-
- /**
- * Checks that there are no conflicts with the security arguments. If we are in no prompt mode, check that all the
- * information required has been provided (but not if this information is valid: we do not try to open the keystores
- * or to check that the LDAPS port is in use).
- *
- * @param errorMessages
- * the list of messages to which we add the error messages describing the problems encountered during the
- * execution of the checking.
- */
- private void checkSecurityArguments(final Collection<LocalizableMessage> errorMessages) {
- final boolean certificateRequired = ldapsPort.isPresent() || enableStartTLS.isPresent();
-
- int certificateType = 0;
- if (generateSelfSignedCertificate.isPresent()) {
- certificateType++;
- }
- if (useJavaKeyStore.isPresent()) {
- certificateType++;
- }
- if (useJCEKS.isPresent()) {
- certificateType++;
- }
- if (usePkcs11.isPresent()) {
- certificateType++;
- }
- if (usePkcs12.isPresent()) {
- certificateType++;
- }
-
- if (certificateType > 1) {
- errorMessages.add(ERR_SEVERAL_CERTIFICATE_TYPE_SPECIFIED.get());
- }
-
- if (certificateRequired && noPrompt.isPresent() && certificateType == 0) {
- errorMessages.add(ERR_CERTIFICATE_REQUIRED_FOR_SSL_OR_STARTTLS.get());
- }
-
- if (certificateType == 1) {
- if (!generateSelfSignedCertificate.isPresent()) {
- // Check that we have only a password.
- if (keyStorePassword.isPresent() && keyStorePasswordFile.isPresent()) {
- final LocalizableMessage message = ERR_TWO_CONFLICTING_ARGUMENTS.get(
- keyStorePassword.getLongIdentifier(), keyStorePasswordFile.getLongIdentifier());
- errorMessages.add(message);
- }
-
- // Check that we have one password in no prompt mode.
- if (noPrompt.isPresent() && !keyStorePassword.isPresent() && !keyStorePasswordFile.isPresent()) {
- final LocalizableMessage message = ERR_NO_KEYSTORE_PASSWORD.get(
- keyStorePassword.getLongIdentifier(), keyStorePasswordFile.getLongIdentifier());
- errorMessages.add(message);
- }
- }
- if (noPrompt.isPresent() && !ldapsPort.isPresent() && !enableStartTLS.isPresent()) {
- final LocalizableMessage message = ERR_SSL_OR_STARTTLS_REQUIRED.get(ldapsPort.getLongIdentifier(),
- enableStartTLS.getLongIdentifier());
- errorMessages.add(message);
- }
- }
- }
-
- /**
- * Checks that there are no conflicts with the directory manager passwords. If we are in no prompt mode, check that
- * the password was provided.
- *
- * @param errorMessages
- * the list of messages to which we add the error messages describing the problems encountered during the
- * execution of the checking.
- */
- private void checkServerPassword(Collection<LocalizableMessage> errorMessages) {
- if (directoryManagerPwdString.isPresent() && directoryManagerPwdFile.isPresent()) {
- errorMessages.add(ERR_TWO_CONFLICTING_ARGUMENTS.get(
- directoryManagerPwdString.getLongIdentifier(), directoryManagerPwdFile.getLongIdentifier()));
- }
-
- if (noPrompt.isPresent() && !directoryManagerPwdString.isPresent()
- && !directoryManagerPwdFile.isPresent()) {
- errorMessages.add(ERR_NO_ROOT_PASSWORD.get(directoryManagerPwdString.getLongIdentifier(),
- directoryManagerPwdFile.getLongIdentifier()));
- }
- }
-
-
- /**
- * This is a helper method that gets a LocalizableMessage representation of the elements in the Collection of
- * Messages. The LocalizableMessage will display the different elements separated by the separator String.
- * TODO move this function.
- * @param col
- * the collection containing the messages.
- * @param separator
- * the separator String to be used.
- * @return the message representation for the collection; LocalizableMessage.EMPTY if null.
- */
- private static LocalizableMessage getMessageFromCollection(final Collection<LocalizableMessage> col,
- final String separator) {
- if (col == null || col.isEmpty()) {
- return LocalizableMessage.EMPTY;
- } else {
- LocalizableMessageBuilder mb = null;
- for (final LocalizableMessage m : col) {
- if (mb == null) {
- mb = new LocalizableMessageBuilder(m);
- } else {
- mb.append(separator).append(m);
- }
- }
- return mb.toMessage();
- }
- }
-
- /**
- * Fills the setup components according to the arguments provided by the user.
- * @throws ArgumentException
- */
- private void fillSetupSettings() throws ArgumentException {
- // TODO ...
- }
-
- /**
- * Launches the setup process.
- * @throws ClientException
- */
- private void runSetupInstallation() throws ClientException {
- // TODO move that function to another class.
- }
-}
diff --git a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/cli/SetupLog.java b/opendj-server/src/main/java/org/forgerock/opendj/server/setup/cli/SetupLog.java
deleted file mode 100644
index 5547f7b..0000000
--- a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/cli/SetupLog.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-
-package org.forgerock.opendj.server.setup.cli;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.text.SimpleDateFormat;
-import java.util.logging.FileHandler;
-import java.util.logging.Formatter;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
-
-import com.forgerock.opendj.cli.ClientException;
-import com.forgerock.opendj.cli.CliMessages;
-import com.forgerock.opendj.cli.ReturnCode;
-
-/**
- * Creates a historical log about the setup. If file does not exist an attempt will be made to create it.
- */
-final class SetupLog {
-
- private static File logFile;
- private static FileHandler fileHandler;
- static final String LOGNAME = "setup.log";
-
- private SetupLog() {
- // Nothing to do.
- }
- /**
- * Creates a new file handler for writing log messages into {@value #LOGNAME} file.
- */
- static void initLogFileHandler() {
- final Logger logger = Logger.getLogger(SetupCli.class.getName());
-
- final String space = " ";
-
- if (logFile == null) {
- logFile = new File(SetupCli.getInstallationPath() + File.separator + LOGNAME);
- }
- try {
- fileHandler = new FileHandler(logFile.getCanonicalPath(), true);
- } catch (IOException e) {
- logger.severe(e.getMessage());
- }
- fileHandler.setFormatter(new Formatter() {
- /** {@inheritDoc} */
- @Override
- public String format(LogRecord record) {
- // Format the log ~like the errors logger.
- StringBuffer sb = new StringBuffer();
- final SimpleDateFormat dateFormat = new SimpleDateFormat("[dd/MMM/yyyy:HH:mm:ss Z]");
- sb.append(dateFormat.format(record.getMillis())).append(space);
- sb.append("category=SETUP").append(space).append("sq=").append(record.getSequenceNumber())
- .append(space).append("severity=").append(record.getLevel().toString().toUpperCase());
- sb.append(space).append("src=").append(record.getSourceClassName()).append(space)
- .append(record.getSourceMethodName()).append("\n");
- sb.append(space).append("msg=").append(record.getMessage()).append("\n");
- return sb.toString();
- }
- });
- logger.setLevel(Level.CONFIG);
- logger.addHandler(fileHandler);
-
- logger.setUseParentHandlers(false);
- // Log Config info.
- logger.info("**** Setup of OpenDJ3 started ****");
- logger.info(CliMessages.INFO_INSTALLATION_DIRECTORY.get(SetupCli.getInstallationPath()).toString());
- logger.info(CliMessages.INFO_INSTANCE_DIRECTORY.get(SetupCli.getInstancePath()).toString());
- }
-
- /**
- * Returns the print stream of the current logger.
- *
- * @return the print stream of the current logger.
- * @throws ClientException
- * If the file defined by the logger is not found or invalid.
- */
- static PrintStream getPrintStream() throws ClientException {
- try {
- return new PrintStream(new FileOutputStream(logFile, true));
- } catch (FileNotFoundException e) {
- throw new ClientException(ReturnCode.ERROR_UNEXPECTED,
- CliMessages.ERR_INVALID_LOG_FILE.get(e.getMessage()));
- }
- }
-
- /**
- * Gets the name of the log file.
- *
- * @return File representing the log file
- */
- public static File getLogFile() {
- return logFile;
- }
-}
diff --git a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/cli/package-info.java b/opendj-server/src/main/java/org/forgerock/opendj/server/setup/cli/package-info.java
deleted file mode 100644
index b6028e6..0000000
--- a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/cli/package-info.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-/**
- * Contains API for the Opendj3 setup CLI.
- */
-package org.forgerock.opendj.server.setup.cli;
diff --git a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/Certificate.java b/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/Certificate.java
deleted file mode 100644
index 0829372..0000000
--- a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/Certificate.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-import java.io.File;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.opendj.config.server.ConfigException;
-
-/**
- * This class is to create a certificate configuration.
- */
-class Certificate {
- public enum CertificateType {
- /**
- * Self-signed certificate.
- */
- SELF_SIGNED,
- /**
- * Java KeyStore.
- */
- JKS,
- /**
- * Java Cryptography Extension.
- */
- JCEKS,
- /**
- * Public-Key Cryptography Standards 12.
- */
- PKCS12,
- /**
- * Public-Key Cryptography Standards 11 token.
- */
- PKCS11
- }
-
- private CertificateType type;
- private String certNickName;
- private File keyStoreFile;
- private String keyStorePin;
-
- /**
- * Default constructor.
- */
- Certificate() {
- type = CertificateType.SELF_SIGNED;
- certNickName = "";
- keyStorePin = "";
- }
-
- /**
- * Returns the certificate nickname.
- *
- * @return The certificate nickname.
- */
- public String getCertNickName() {
- return certNickName;
- }
-
- /**
- * Sets the certificate nickname.
- *
- * @param certNickName
- * The certificate nickname.
- */
- public void setCertNickName(String certNickName) {
- this.certNickName = certNickName;
- }
-
-
- /**
- * Returns the type of this certificate.
- *
- * @return The type of this certificate.
- */
- public CertificateType getType() {
- return type;
- }
-
- /**
- * Sets the type of this certificate.
- *
- * @param type
- * The type of this certificate (JKS, self-signed...)
- */
- public void setType(CertificateType type) {
- this.type = type;
- }
-
- /**
- * Returns the key store file.
- *
- * @return The key store file.
- */
- public File getKeyStoreFile() {
- return keyStoreFile;
- }
-
- /**
- * Sets the key store file.
- *
- * @param keyStoreFile
- * The key store file.
- */
- public void setKeyStoreFile(File keyStoreFile) {
- this.keyStoreFile = keyStoreFile;
- }
-
- /**
- * Returns the key store PIN.
- *
- * @return The key store PIN.
- */
- public String getKeyStorePin() {
- return keyStorePin;
- }
-
- /**
- * Sets the key store PIN.
- *
- * @param keyStorePin
- * The key store PIN.
- */
- public void setKeyStorePin(String keyStorePin) {
- this.keyStorePin = keyStorePin;
- }
-
- /**
- * Validates the actual configuration for this certificate.
- *
- * @throws ConfigException
- * If this certificate configuration is invalid.
- */
- public void validate() throws ConfigException {
- if (type == CertificateType.JKS || type == CertificateType.JCEKS || type == CertificateType.PKCS12) {
- if (keyStoreFile == null || !keyStoreFile.exists()) {
- throw new ConfigException(LocalizableMessage.raw("Invalid keystore file"));
- }
- if (keyStorePin.isEmpty()) {
- throw new ConfigException(LocalizableMessage.raw("Invalid key pin"));
- }
- } else if (type == CertificateType.PKCS11) {
- if (keyStorePin.isEmpty()) {
- throw new ConfigException(LocalizableMessage.raw("Invalid key pin"));
- }
- }
- }
-}
diff --git a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/DataConfiguration.java b/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/DataConfiguration.java
deleted file mode 100644
index 8ee8b16..0000000
--- a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/DataConfiguration.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-import java.io.File;
-
-class DataConfiguration {
-
- /**
- * This enumeration is used to know what kind of data configuration we want to deploy.
- */
- public enum Type {
- /**
- * Base entry only.
- */
- BASE_ENTRY_ONLY,
- /**
- * Empty database.
- */
- EMPTY_DATABASE,
- /**
- * Import LDIF.
- */
- IMPORT_LDIF,
- /**
- * Automatically generated data entries.
- */
- AUTOMATICALLY_GENERATED
- }
-
- /** Default name of directory base DN. */
- static final String DEFAULT_DIRECTORY_BASE_DN = "dc=example,dc=com";
-
- /** Default value for the generated entries. */
- static final int IMPORT_ENTRIES_DEFAULT_VALUE = 2000;
-
- private String directoryBaseDN;
- private Type type;
- private File ldifImportDataPath;
- private int numberOfUserEntries;
-
- DataConfiguration() {
- directoryBaseDN = DEFAULT_DIRECTORY_BASE_DN;
- type = Type.AUTOMATICALLY_GENERATED;
- numberOfUserEntries = IMPORT_ENTRIES_DEFAULT_VALUE;
- }
-
- public String getDirectoryBaseDN() {
- return directoryBaseDN;
- }
-
- public void setDirectoryBaseDN(String directoryBaseDN) {
- this.directoryBaseDN = directoryBaseDN;
- }
-
- public Type getType() {
- return type;
- }
-
- public void setType(Type type) {
- this.type = type;
- }
-
- public boolean isOnlyBaseEntry() {
- return type == Type.BASE_ENTRY_ONLY;
- }
-
- public boolean isEmptyDatabase() {
- return type == Type.EMPTY_DATABASE;
- }
-
- public boolean isImportLDIF() {
- return type == Type.IMPORT_LDIF;
- }
-
- public boolean isAutomaticallyImportGenerated() {
- return type == Type.AUTOMATICALLY_GENERATED;
- }
-
- public File getLdifImportDataPath() {
- return ldifImportDataPath;
- }
-
- public void setLdifImportDataPath(File ldifImportDataPath) {
- this.ldifImportDataPath = ldifImportDataPath;
- }
-
- public int getNumberOfUserEntries() {
- return numberOfUserEntries;
- }
-
- public void setNumberOfUserEntries(int numberOfUserEntries) {
- this.numberOfUserEntries = numberOfUserEntries;
- }
-}
diff --git a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/ListenerSettings.java b/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/ListenerSettings.java
deleted file mode 100644
index 68b82ef..0000000
--- a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/ListenerSettings.java
+++ /dev/null
@@ -1,442 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import static com.forgerock.opendj.cli.CliConstants.*;
-
-/**
- * This class provides listener settings for the OpenDJ3 setup.
- */
-public class ListenerSettings {
-
- private String hostName;
- private int ldapPort;
- private int ldapsPort;
- private int adminPort;
- private boolean isJMXConnectionHandlerEnabled;
- private int jmxPort;
- private boolean isHTTPConnectionHandlerEnabled;
- private int httpPort;
- private boolean isSNMPConnectionHandlerEnabled;
- private int snmpPort;
- private String rootUserDN;
- private char[] password;
- private File passwordFile;
- private boolean isSSLEnabled;
- private boolean isTLSEnabled;
- private int sslPortNumber;
- private Certificate certificate;
-
- /**
- * Default constructor.
- */
- public ListenerSettings() {
- hostName = "";
- ldapPort = DEFAULT_LDAP_PORT;
- ldapsPort = DEFAULT_LDAPS_PORT;
- adminPort = DEFAULT_ADMIN_PORT;
- jmxPort = DEFAULT_JMX_PORT;
- isJMXConnectionHandlerEnabled = false;
- httpPort = DEFAULT_HTTP_PORT;
- isHTTPConnectionHandlerEnabled = true;
- snmpPort = DEFAULT_SNMP_PORT;
- isSNMPConnectionHandlerEnabled = false;
- rootUserDN = DEFAULT_ROOT_USER_DN;
- isSSLEnabled = false;
- isTLSEnabled = false;
- sslPortNumber = DEFAULT_SSL_PORT;
- certificate = null;
- }
-
- /**
- * Returns the host name.
- *
- * @return The host name of the local machine.
- */
- public String getHostName() {
- return hostName;
- }
-
- /**
- * Sets the host name of the machine.
- *
- * @param hostName
- * The host name of the current machine.
- */
- public void setHostName(String hostName) {
- this.hostName = hostName;
- }
-
- /**
- * Returns the value of the LDAP port.
- *
- * @return The value of the LDAP port.
- */
- public int getLdapPort() {
- return ldapPort;
- }
-
- /**
- * Sets the value of the LDAP port.
- *
- * @param ldapPort
- * The LDAP port's value to set.
- */
- public void setLdapPort(int ldapPort) {
- this.ldapPort = ldapPort;
- }
-
- /**
- * Return the LDAPs port.
- *
- * @return The LDAPs port's value.
- */
- public int getLdapsPort() {
- return ldapsPort;
- }
-
- /**
- * Sets the LDAPs port value.
- *
- * @param ldapsPort
- * The LDAPs port's value to set.
- */
- public void setLdapsPort(int ldapsPort) {
- this.ldapsPort = ldapsPort;
- }
-
- /**
- * Returns the administration connector port.
- *
- * @return The administration connector's port
- */
- public int getAdminPort() {
- return adminPort;
- }
-
- /**
- * Sets the administration connector 's port.
- *
- * @param adminPort
- * The administration connector.
- */
- public void setAdminPort(int adminPort) {
- this.adminPort = adminPort;
- }
-
- /**
- * Returns the JMX's port value.
- *
- * @return The JMX's port value.
- */
- public int getJMXPort() {
- return jmxPort;
- }
-
- /**
- * Sets the JMX port's value.
- *
- * @param jmxPort
- * The JMX port's value.
- */
- public void setJMXPort(int jmxPort) {
- this.jmxPort = jmxPort;
- }
-
- /**
- * Returns {@code true} if the JMX connection handler is enabled.
- *
- * @return {@code true} if the JMX connection handler is enabled.
- */
- public boolean isJMXConnectionHandlerEnabled() {
- return isJMXConnectionHandlerEnabled;
- }
-
- /**
- * Sets the status of the JMX connection handler.
- *
- * @param isJMXConnectionHandlerEnabled
- * true} if the JMX connection handler is enabled.
- */
- public void setJMXConnectionHandlerEnabled(boolean isJMXConnectionHandlerEnabled) {
- this.isJMXConnectionHandlerEnabled = isJMXConnectionHandlerEnabled;
- }
-
- /**
- * Returns the value of the HTTP connection handler port.
- *
- * @return The value of the HTTP connection handler port.
- */
- public int getHTTPPort() {
- return httpPort;
- }
-
- /**
- * Sets the value of the port which is going to be used bu the HTTP connection handler.
- *
- * @param httpPort
- * The value of the HTTP port.
- */
- public void setHTTPPort(int httpPort) {
- this.httpPort = httpPort;
- }
-
- /**
- * Returns {@code true} if the HTTP connection handler is enabled.
- *
- * @return {@code true} if the HTTP connection handler is enabled.
- */
- public boolean isHTTPConnectionHandlerEnabled() {
- return isHTTPConnectionHandlerEnabled;
- }
-
- /**
- * Sets the status of the HTTP connection handler.
- *
- * @param isHTTPConnectionHandlerEnabled
- * true} if the HTTP connection handler is enabled.
- */
- public void setHTTPConnectionHandlerEnabled(boolean isHTTPConnectionHandlerEnabled) {
- this.isHTTPConnectionHandlerEnabled = isHTTPConnectionHandlerEnabled;
- }
-
- /**
- * Returns the value of the port used by SNMP.
- *
- * @return The value of the port used by SNMP.
- */
- public int getSNMPPort() {
- return snmpPort;
- }
-
- /**
- * Sets the value of the port used by SNMP.
- *
- * @param snmpPort
- * The value of the port used by SNMP.
- */
- public void setSNMPPort(int snmpPort) {
- this.snmpPort = snmpPort;
- }
-
- /**
- * Returns {@code true} if the SNMP connection handler is enabled.
- *
- * @return {@code true} if the SNMP connection handler is enabled. {@code false} otherwise.
- */
- public boolean isSNMPConnectionHandlerEnabled() {
- return isSNMPConnectionHandlerEnabled;
- }
-
- /**
- * Sets the status of the HTTP connection handler.
- *
- * @param isSNMPConnectionHandlerEnabled
- * {@code true} if the HTTP connection handler is enabled.
- */
- public void setSNMPConnectionHandlerEnabled(boolean isSNMPConnectionHandlerEnabled) {
- this.isSNMPConnectionHandlerEnabled = isSNMPConnectionHandlerEnabled;
- }
-
- /**
- * Returns the root user DN.
- *
- * @return The root user DN.
- */
- public String getRootUserDN() {
- return rootUserDN;
- }
-
- /**
- * Sets the root user DN.
- *
- * @param rootUserDN
- * The root user DN.
- */
- public void setRootUserDN(String rootUserDN) {
- this.rootUserDN = rootUserDN;
- }
-
- /**
- * Returns the password linked to this root user DN.
- *
- * @return The password linked to this root user DN.
- */
- public String getPassword() {
- if (password != null) {
- return String.valueOf(password);
- }
- return null;
- }
-
- /**
- * Sets the user root's password.
- *
- * @param password
- * The password to set to this user root DN.
- */
- public void setPassword(String password) {
- this.password = password.toCharArray();
- }
-
- /**
- * The file containing the password for the initial root user for the directory server.
- *
- * @return The file containing the password for the initial root user.
- */
- public File getPasswordFile() {
- return passwordFile;
- }
-
- /**
- * Sets the file containing the password for the initial root user for the directory server.
- *
- * @param pwdFile
- * The file containing the password for the initial root user for the directory server.
- */
- public void setPasswordFile(File pwdFile) {
- this.passwordFile = pwdFile;
- }
-
- /**
- * Returns {@code true} is SSL is enabled.
- *
- * @return {@code true} is SSL is enabled, {@code false} otherwise.
- */
- public boolean isSSLEnabled() {
- return isSSLEnabled;
- }
-
- /**
- * Sets a flag is SSL is enabled.
- *
- * @param isSSLEnabled
- * {@code true} is SSL is enabled, {@code false} otherwise.
- */
- public void setSSLEnabled(boolean isSSLEnabled) {
- this.isSSLEnabled = isSSLEnabled;
- }
-
- /**
- * Returns {@code true} is TLS is enabled.
- *
- * @return {@code true} is TLS is enabled, {@code false} otherwise.
- */
- public boolean isTLSEnabled() {
- return isTLSEnabled;
- }
-
- /**
- * Sets a flag is TLS is enabled.
- *
- * @param isTLSEnabled
- * {@code true} is TLS is enabled, {@code false} otherwise.
- */
- public void setTLSEnabled(boolean isTLSEnabled) {
- this.isTLSEnabled = isTLSEnabled;
- }
-
- /**
- * Returns the port number which is used with SSL.
- *
- * @return The SSL port's number.
- */
- public int getSSLPortNumber() {
- return sslPortNumber;
- }
-
- /**
- * Sets the SSL's port number.
- *
- * @param sslPortNumber
- * The port number which should be used with SSL.
- */
- public void setSSLPortNumber(int sslPortNumber) {
- this.sslPortNumber = sslPortNumber;
- }
-
- /**
- * Returns the certificate linked to this setup.
- *
- * @return The certificate linked to this setup.
- */
- public Certificate getCertificate() {
- return certificate;
- }
-
- /**
- * Sets the certificate used in this setup.
- *
- * @param certificate
- * The certificate used in this setup.
- */
- public void setCertificate(Certificate certificate) {
- this.certificate = certificate;
- }
-
- /**
- * Returns the port number which is currently free.
- * @param startPortNumber The port number to start with.
- * @return The port number which is currently free.
- */
- static int getFreeSocketPort(int startPortNumber) {
- return getFreeSocketPort(startPortNumber, new TestPortImpl());
- }
-
- private static int getFreeSocketPort(int startPortNumber, TestPort testPort) {
- int port = startPortNumber;
- while (port >= 0 && port <= 65535) {
- try {
- testPort.canBindToPort(port);
- return port;
- } catch (IOException e) {
- port = port + PORT_INCREMENT;
- }
- }
- throw new IllegalArgumentException("Invalid port.");
- }
-
- interface TestPort {
- void canBindToPort(int portNumber) throws IOException;
- }
-
- static class TestPortImpl implements TestPort {
- public void canBindToPort(int portNumber) throws IOException {
- ServerSocket socket = null;
- try {
- socket = new ServerSocket();
- socket.setReuseAddress(true);
- socket.bind(new InetSocketAddress(portNumber));
- } finally {
- close(socket);
- }
- }
-
- private void close(ServerSocket socket) {
- try {
- if (socket != null) {
- socket.close();
- }
- } catch (final IOException ignored) {
- // Ignore.
- }
- }
- }
-}
diff --git a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/Model.java b/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/Model.java
deleted file mode 100644
index 5ddf785..0000000
--- a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/Model.java
+++ /dev/null
@@ -1,396 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.opendj.config.server.ConfigException;
-import org.forgerock.util.Reject;
-
-/**
- * This class provides configuration's model for the OpenDJ3 setup.
- */
-public abstract class Model {
-
- /**
- * This enumeration is used to know what kind of server we want to set up.
- */
- public enum Type {
- /**
- * Stand alone server.
- */
- STANDALONE,
- /**
- * First server in topology.
- */
- FIRST_IN_TOPOLOGY,
- /**
- * Replicate the new suffix with existing server.
- */
- IN_EXISTING_TOPOLOGY
- }
-
- private Type type;
- private boolean startingServerAfterSetup;
- private boolean isService;
- private String instancePath;
- private String installationPath;
-
- private String license;
- private ListenerSettings settings;
- private RuntimeOptions serverRuntimeSettings;
- private RuntimeOptions importLdifRuntimeSettings;
- private DataConfiguration dataConfiguration;
-
- private ReplicationConfiguration replicationConfiguration;
-
- /**
- * Returns the listener settings.
- *
- * @return The listener settings.
- */
- public ListenerSettings getListenerSettings() {
- return settings;
- }
-
- /**
- * Sets the listener settings.
- *
- * @param lSettings
- * The listener settings to set.
- */
- public void setListenerSettings(final ListenerSettings lSettings) {
- settings = lSettings;
- }
-
- /**
- * Returns {@code true} if this configuration has a non-empty license.
- *
- * @return {@code true} if this configuration has a license.
- */
- public boolean hasLicense() {
- return license != null && !license.isEmpty();
- }
-
- /**
- * Returns {@code true} if this configuration is stand alone data store.
- *
- * @return {@code true} if this configuration is stand alone data store.
- */
- boolean isStandAlone() {
- return type == Type.STANDALONE;
- }
-
- /**
- * Returns {@code true} if this configuration is a first server in a replication topology.
- *
- * @return {@code true} if this configuration is a first server in a replication topology.
- */
- boolean isFirstInTopology() {
- return type == Type.FIRST_IN_TOPOLOGY;
- }
-
- /**
- * Returns {@code true} if this configuration is part of a replication topology.
- *
- * @return {@code true} if this configuration is part of a replication topology.
- */
- boolean isPartOfReplicationTopology() {
- return type == Type.IN_EXISTING_TOPOLOGY;
- }
-
- /**
- * Returns {@code true} if this configuration has a certificate linked to it. That generally means SSL and/or SSL
- * are activated.
- *
- * @return {@code true} if this configuration has a certificate linked to it.
- */
- boolean isSecure() {
- return getListenerSettings() != null
- && getListenerSettings().getCertificate() != null;
- }
-
- /**
- * Sets this configuration as a stand alone data store.
- */
- void setStandAloneDS() {
- setType(Type.STANDALONE);
- }
-
- /**
- * Sets the type of this server as : replication activated and this is the first server in topology.
- */
- void setFirstInTopology() {
- setType(Type.FIRST_IN_TOPOLOGY);
- }
-
- /**
- * Sets the type of this server as : replication activated and this is a server in an existing topology.
- */
- void setInExistingTopology() {
- setType(Type.IN_EXISTING_TOPOLOGY);
- }
-
- /**
- * Returns the type of this configuration.
- *
- * @return The type of this configuration.
- */
- public Type getType() {
- return type;
- }
-
- /**
- * Sets the type of this configuration.
- *
- * @param mtype
- * The type of this configuration (standalone, etc...)
- */
- public void setType(Type mtype) {
- type = mtype;
- }
-
- /**
- * Returns {@code true} if the server must start after the installation.
- *
- * @return {@code true} if the server must start after the installation.
- */
- public boolean isStartingServerAfterSetup() {
- return startingServerAfterSetup;
- }
-
- /**
- * Sets if the server should start after its installation.
- *
- * @param startServerAfterSetup
- * {@code true} if the server must start after the installation.
- */
- public void setStartingServerAfterSetup(boolean startServerAfterSetup) {
- startingServerAfterSetup = startServerAfterSetup;
- }
-
- /**
- * Returns {@code true} if the directory server should start as a service.
- *
- * @return {@code true} if the directory server should start as a service, {@code false} otherwise.
- */
- public boolean isService() {
- return isService;
- }
-
- /**
- * Sets the directory server as a service.
- *
- * @param isAService
- * {@code true} if the directory server should start as a service, {@code false} otherwise.
- */
- public void setService(boolean isAService) {
- isService = isAService;
- }
-
- /**
- * Returns the instance path.
- *
- * @return The instance path where the binaries are installed.
- */
- public String getInstancePath() {
- return instancePath;
- }
-
- /**
- * Sets the current instance path location.
- *
- * @param iPath
- * The instance path.
- */
- public void setInstancePath(String iPath) {
- instancePath = iPath;
- }
-
- /**
- * Returns the license.
- *
- * @return The license.
- */
- public String getLicense() {
- return license;
- }
-
- /**
- * Sets the license linked to this installation.
- *
- * @param theLicense
- * The license to set.
- */
- public void setLicense(String theLicense) {
- license = theLicense;
- }
-
- /**
- * Returns the runtime options that apply to this installation.
- *
- * @return The runtime options that apply to this installation.
- */
- public RuntimeOptions getServerRuntimeSettings() {
- return serverRuntimeSettings;
- }
-
- /**
- * Sets the runtime options that apply to this installation.
- *
- * @param settings
- * The runtime options that apply to this installation.
- */
- public void setServerRuntimeOptions(RuntimeOptions settings) {
- serverRuntimeSettings = settings;
- }
-
- /**
- * Returns the runtime options that apply to the current import LDIF.
- *
- * @return The runtime options that apply to the current import LDIF.
- */
- public RuntimeOptions getImportLdifRuntimeOptions() {
- return importLdifRuntimeSettings;
- }
-
- /**
- * Sets the runtime options that apply to the current import LDIF.
- *
- * @param settings
- * The runtime options that apply to the current import LDIF.
- */
- public void setImportLdifRuntimeOptions(RuntimeOptions settings) {
- importLdifRuntimeSettings = settings;
- }
-
- /**
- * Returns the data configuration of this model.
- *
- * @return The data configuration of this model.
- */
- public DataConfiguration getDataConfiguration() {
- return dataConfiguration;
- }
-
- /**
- * Sets the data configuration of this model.
- *
- * @param dConfiguration
- * The data configuration to set for this model.
- */
- public void setDataConfiguration(DataConfiguration dConfiguration) {
- dataConfiguration = dConfiguration;
- }
-
- /**
- * Returns the replication configuration of this model.
- *
- * @return The replication configuration of this model.
- */
- public ReplicationConfiguration getReplicationConfiguration() {
- return replicationConfiguration;
- }
-
- /**
- * Sets the replication configuration of this model.
- *
- * @param replicationConfiguration
- * The replication configuration to set for this model.
- */
- public void setReplicationConfiguration(ReplicationConfiguration replicationConfiguration) {
- this.replicationConfiguration = replicationConfiguration;
- }
-
- /**
- * Returns the installation path of this model.
- *
- * @return The installation path of this model.
- */
- public String getInstallationPath() {
- return installationPath;
- }
-
- /**
- * Sets the installation path of this model.
- *
- * @param installationPath
- * The installation path of this model.
- */
- public void setInstallationPath(String installationPath) {
- this.installationPath = installationPath;
- }
-
- /**
- * Creates a basic data store model configuration for setup.
- */
- public static class DataStoreModel extends Model {
- /**
- * The default data store model.
- */
- public DataStoreModel() {
- setStandAloneDS();
- setDataConfiguration(new DataConfiguration());
- setListenerSettings(new ListenerSettings());
- setServerRuntimeOptions(RuntimeOptions.getDefault());
- setImportLdifRuntimeOptions(RuntimeOptions.getDefault());
- setStartingServerAfterSetup(true);
- }
- }
-
- /**
- * Checks the validity of the current setup configuration.
- *
- * @throws ConfigException
- * If this configuration is invalid.
- */
- void validate() throws ConfigException {
- if (isFirstInTopology() || isPartOfReplicationTopology()) {
- if (getReplicationConfiguration() == null) {
- throw new ConfigException(LocalizableMessage.raw("No replication configuration found"));
- }
- if (isPartOfReplicationTopology()) {
- Reject.ifNull(getReplicationConfiguration().getAdministrator(),
- "Administrator name should not be null");
- Reject.ifNull(getReplicationConfiguration().getPassword(), "Admin password should not be null");
- Reject.ifNull(getReplicationConfiguration().getGlobalAdministrator(),
- "Global administrator should not be null");
- Reject.ifNull(getReplicationConfiguration().getGlobalAdministratorPassword(),
- "Global administrator should not be null");
- if (getReplicationConfiguration().getSuffixes() == null
- || getReplicationConfiguration().getSuffixes().size() == 0) {
- throw new ConfigException(
- LocalizableMessage.raw("At least one base DN should be selected "
- + "to replicate content with"));
- }
- }
- }
- final ListenerSettings settings = getListenerSettings();
- final DataConfiguration dataConf = getDataConfiguration();
- if (settings == null) {
- throw new ConfigException(LocalizableMessage.raw("Invalid settings"));
- }
- if (dataConf == null) {
- throw new ConfigException(LocalizableMessage.raw("Invalid data configuration"));
- }
- if (dataConf.isImportLDIF() && dataConf.getLdifImportDataPath() == null) {
- throw new ConfigException(LocalizableMessage.raw("Invalid import ldif file."));
- }
- if (settings.getPasswordFile() == null && settings.getPassword() == null) {
- throw new ConfigException(LocalizableMessage.raw("A password must be set for the root DN."));
- }
- }
-
-}
diff --git a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/ModelUtils.java b/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/ModelUtils.java
deleted file mode 100644
index 53020d5..0000000
--- a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/ModelUtils.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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 2014-2015 ForgeRock AS.
- */
-
-package org.forgerock.opendj.server.setup.model;
-
-import java.util.ArrayList;
-
-
-/**
- * This class contains utilities for the OpenDJ3 setup.
- */
-final class ModelUtils {
-
- static final String OBFUSCATED_VALUE = "******";
-
- ArrayList<String> getSetupEquivalentCommandLine(final Model configuration) {
- final ArrayList<String> cmdLines = new ArrayList<>();
- final ListenerSettings settings = configuration.getListenerSettings();
-
- // Starts the server ?
- if (configuration.getType() == Model.Type.STANDALONE
- && !configuration.isStartingServerAfterSetup()) {
- cmdLines.add("--doNotStart");
- }
-
- if (configuration.isSecure()) {
- if (settings.isTLSEnabled()) {
- cmdLines.add("--enableStartTLS");
- }
- if (settings.isSSLEnabled()) {
- cmdLines.add("--ldapsPort");
- cmdLines.add(String.valueOf(settings.getSSLPortNumber()));
- }
-
- final Certificate certificate = settings.getCertificate();
- switch (certificate.getType()) {
- case SELF_SIGNED:
- cmdLines.add("--generateSelfSignedCertificate");
- cmdLines.add("--hostName");
- cmdLines.add(settings.getHostName());
- break;
- case JKS:
- appendKeystoreCliOptionsWithPath(cmdLines, "--useJavaKeystore", certificate);
- break;
- case JCEKS:
- appendKeystoreCliOptionsWithPath(cmdLines, "--useJCEKS", certificate);
- break;
- case PKCS12:
- appendKeystoreCliOptionsWithPath(cmdLines, "--usePkcs12keyStore", certificate);
- break;
- case PKCS11:
- cmdLines.add("--usePkcs11Keystore");
- // do not add a file path because this is a hardware store
- appendKeystoreCliOptions(cmdLines, certificate);
- break;
- }
- }
- cmdLines.add("--no-prompt");
- cmdLines.add("--noPropertiesFile");
- return cmdLines;
- }
-
- private void appendKeystoreCliOptionsWithPath(final ArrayList<String> cmdLines, final String cliOption,
- final Certificate certificate) {
- cmdLines.add(cliOption);
- cmdLines.add(certificate.getKeyStoreFile().getAbsolutePath());
- appendKeystoreCliOptions(cmdLines, certificate);
- }
-
- private void appendKeystoreCliOptions(final ArrayList<String> cmdLines, final Certificate certificate) {
- if (certificate.getKeyStorePin() != null) {
- cmdLines.add("--keyStorePassword");
- cmdLines.add(OBFUSCATED_VALUE);
- }
- if (!certificate.getCertNickName().isEmpty()) {
- cmdLines.add("--certNickname");
- cmdLines.add(certificate.getCertNickName());
- }
- }
-}
diff --git a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/ReplicationConfiguration.java b/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/ReplicationConfiguration.java
deleted file mode 100644
index e9865f3..0000000
--- a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/ReplicationConfiguration.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-import java.util.List;
-
-/**
- * This class provides the model of the replication configuration.
- */
-class ReplicationConfiguration {
-
- /** Default port number for the replication port. */
- static final int DEFAULT_REPLICATION_PORT = 389;
-
- /** First in topology. */
- private int replicationPort;
- private boolean isSecure;
-
- /** Part of topology. */
- private String hostName;
- private int hostPort;
- private String administrator;
- private char[] password;
- private List<String> suffixes;
- private boolean createGlobalAdministrator;
- private String globalAdministrator;
- private char[] globalAdministratorPassword;
-
- ReplicationConfiguration() {
- replicationPort = DEFAULT_REPLICATION_PORT;
- isSecure = false;
- createGlobalAdministrator = false;
- }
-
- /**
- * Returns the replication port.
- *
- * @return The replication port.
- */
- public int getReplicationPort() {
- return replicationPort;
- }
-
- /**
- * Sets the port used in replication.
- *
- * @param port
- * The replication port.
- */
- public void setReplicationPort(int port) {
- replicationPort = port;
- }
-
- /**
- * Returns {@code true} if this connection should be secure.
- *
- * @return {@code true} if this is a secure connection.
- */
- public boolean isSecure() {
- return isSecure;
- }
-
- /**
- * Sets this connection to secure if needed.
- *
- * @param secure
- * {@code true} if the connection needs to be secure.
- */
- public void setSecure(boolean secure) {
- isSecure = secure;
- }
-
- /**
- * Returns the host name.
- *
- * @return The host name.
- */
- public String getHostName() {
- return hostName;
- }
-
- /**
- * Sets the host name.
- *
- * @param hName
- * The host name.
- */
- public void setHostName(String hName) {
- hostName = hName;
- }
-
- /**
- * Returns the host port.
- *
- * @return The host port.
- */
- public int getHostPort() {
- return hostPort;
- }
-
- /**
- * Sets the host port.
- *
- * @param hPort
- * The host port to set.
- */
- public void setHostPort(int hPort) {
- hostPort = hPort;
- }
-
- /**
- * Returns the administrator name.
- *
- * @return The administrator name.
- */
- public String getAdministrator() {
- return administrator;
- }
-
- /**
- * Sets the administrator name.
- *
- * @param adminName
- * The administrator name to set.
- */
- public void setAdministrator(String adminName) {
- administrator = adminName;
- }
-
- /**
- * Returns the password.
- *
- * @return The password.
- */
- public char[] getPassword() {
- return password;
- }
-
- /**
- * Sets the password linked to the administrator name.
- *
- * @param adminPassword
- * The password linked to this administrator name.
- */
- public void setPassword(char[] adminPassword) {
- password = adminPassword;
- }
-
- /**
- * Returns a list of the suffixes.
- *
- * @return A list of suffixes.
- */
- public List<String> getSuffixes() {
- return suffixes;
- }
-
- /**
- * Sets the list of the suffixes.
- *
- * @param lSuffixes
- * The list of the existing suffixes.
- */
- public void setSuffixes(List<String> lSuffixes) {
- suffixes = lSuffixes;
- }
-
- /**
- * Returns the need to create the global administrator.
- *
- * @return {@code true} if the global administrator creation is needed.
- */
- public boolean isCreateGlobalAdministrator() {
- return createGlobalAdministrator;
- }
-
- /**
- * Sets the global administrator creation.
- *
- * @param createGlobalAdministrator
- * {@code true} if the global administrator creation is required.
- */
- public void setCreateGlobalAdministrator(boolean createGlobalAdministrator) {
- this.createGlobalAdministrator = createGlobalAdministrator;
- }
-
- /**
- * Returns the UID of the global administrator.
- *
- * @return The UID of the global administrator.
- */
- public String getGlobalAdministrator() {
- return globalAdministrator;
- }
-
- /**
- * Sets the UID of the global administrator.
- *
- * @param globalAdministratorUID
- * The UID of the global administrator.
- */
- public void setGlobalAdministratorUID(String globalAdministratorUID) {
- this.globalAdministrator = globalAdministratorUID;
- }
-
- /**
- * Returns the password of the global administrator.
- *
- * @return The password of the global administrator.
- */
- public String getGlobalAdministratorPassword() {
- return String.valueOf(globalAdministratorPassword);
- }
-
- /**
- * Sets the password of the global administrator.
- *
- * @param globalAdministratorPwd
- * The password of the global administrator.
- */
- public void setGlobalAdministratorPassword(char[] globalAdministratorPwd) {
- this.globalAdministratorPassword = globalAdministratorPwd;
- }
-
-}
diff --git a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/RuntimeOptions.java b/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/RuntimeOptions.java
deleted file mode 100644
index ca2d669..0000000
--- a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/RuntimeOptions.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-/**
- * This class provides the model of the runtime options which can be used
- * for the server settings or for the import LDIF settings.
- */
-class RuntimeOptions {
-
- static final int INITIAL_MEMORY = 128;
- static final int MAXIMUM_MEMORY = 256;
-
- private int initialMemory = -1;
- private int maximumMemory = -1;
- private String[] additionalArguments = {};
-
- RuntimeOptions() {
- // Nothing to do.
- }
-
- static RuntimeOptions getDefault() {
- final RuntimeOptions ro = new RuntimeOptions();
- ro.initialMemory = 128;
- ro.maximumMemory = 256;
- ro.additionalArguments = new String[] { "-client" };
- return ro;
- }
-
- /**
- * Returns the initial memory allowed to execute the command-line.
- *
- * @return the initial memory allowed to execute the command-line.
- */
- public int getInitialMemory() {
- return initialMemory;
- }
-
- /**
- * Sets the initial memory allowed to execute the command-line.
- *
- * @param initialMemory
- * the initial memory allowed to execute the command-line.
- */
- public void setInitialMemory(int initialMemory) {
- this.initialMemory = initialMemory;
- }
-
- /**
- * Returns the maximum memory allowed to execute the command-line.
- *
- * @return the maximum memory allowed to execute the command-line.
- */
- public int getMaximumMemory() {
- return maximumMemory;
- }
-
- public void setMaximumMemory(int maximumMemory) {
- this.maximumMemory = maximumMemory;
- }
-
- /**
- * Returns the additional arguments to be used when executing the command-line.
- *
- * @return the additional arguments to be used when executing the command-line.
- */
- public String[] getAdditionalArguments() {
- return additionalArguments;
- }
-
- /**
- * Sets the additional arguments to be used when executing the command-line.
- *
- * @param additionalArguments
- * the additional arguments to be used when executing the command-line. It cannot be null.
- */
- public void setAdditionalArguments(String... additionalArguments) {
- if (additionalArguments == null) {
- throw new IllegalArgumentException("additionalArguments cannot be null.");
- }
- this.additionalArguments = additionalArguments;
- }
-
- /** {@inheritDoc} */
- @Override
- public boolean equals(Object o) {
- if (o == this) {
- return true;
- }
- if (!(o instanceof RuntimeOptions)) {
- return false;
- }
- final RuntimeOptions other = (RuntimeOptions) o;
- if (initialMemory == other.initialMemory
- && maximumMemory == other.maximumMemory
- && additionalArguments.length == other.additionalArguments.length) {
- final String[] args = other.additionalArguments;
- for (int i = 0; i < args.length; i++) {
- if (!args[i].equals(additionalArguments[i])) {
- return false;
- }
- }
- }
- return true;
- }
-
- /** {@inheritDoc} */
- @Override
- public int hashCode() {
- int hashCode = 44 + initialMemory + maximumMemory;
- for (String arg : additionalArguments) {
- hashCode += arg.hashCode();
- }
- return hashCode;
- }
-
- /** {@inheritDoc} */
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder();
- sb.append("Initial Memory: ").append(initialMemory).append(" Max Memory: ").append(maximumMemory);
- int i = 1;
- for (final String arg : additionalArguments) {
- sb.append(" arg ").append(i).append(": ").append(arg);
- i++;
- }
- return sb.toString();
- }
-
- /**
- * Returns the java argument to specify the initial memory to be used.
- *
- * @param value
- * the value in megabytes to be specified.
- * @return the java argument to specify the initial memory to be used.
- */
- public static String getInitialMemoryArgument(int value) {
- return "-Xms" + value + "m";
- }
-
- /**
- * Returns the java argument to specify the maximum memory that can be used.
- *
- * @param value
- * the value in megabytes to be specified.
- * @return the java argument to specify the maximum memory that can be used.
- */
- public static String getMaxMemoryArgument(int value) {
- return "-Xmx" + value + "m";
- }
-
-}
diff --git a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/package-info.java b/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/package-info.java
deleted file mode 100644
index ebe4023..0000000
--- a/opendj-server/src/main/java/org/forgerock/opendj/server/setup/model/package-info.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-/**
- * Contains API for the Opendj3 setup.
- */
-package org.forgerock.opendj.server.setup.model;
diff --git a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/cli/AbstractSetupCliTestCase.java b/opendj-server/src/test/java/org/forgerock/opendj/server/setup/cli/AbstractSetupCliTestCase.java
deleted file mode 100644
index fc60a4f..0000000
--- a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/cli/AbstractSetupCliTestCase.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.cli;
-
-import org.forgerock.opendj.ldap.SdkTestCase;
-import org.testng.annotations.Test;
-
-/**
- * An abstract class that all setup CLI unit tests should extend.
- */
-@Test(groups = { "precommit", "types", "sdk" })
-public abstract class AbstractSetupCliTestCase extends SdkTestCase {
-
-}
diff --git a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/cli/SetupCliTestCase.java b/opendj-server/src/test/java/org/forgerock/opendj/server/setup/cli/SetupCliTestCase.java
deleted file mode 100644
index e2105d4..0000000
--- a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/cli/SetupCliTestCase.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.cli;
-
-import static com.forgerock.opendj.cli.Utils.MAX_LINE_WIDTH;
-import static com.forgerock.opendj.cli.Utils.wrapText;
-import static com.forgerock.opendj.cli.CliMessages.*;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.forgerock.util.Utils.closeSilently;
-import static org.testng.Assert.assertTrue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.io.UnsupportedEncodingException;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-import com.forgerock.opendj.cli.ReturnCode;
-import com.forgerock.opendj.cli.Utils;
-
-/**
- * This class tests the setup CLI functionality.
- */
-public class SetupCliTestCase extends AbstractSetupCliTestCase {
-
- @DataProvider(name = "validArguments")
- Object[][] createValidArguments() throws Exception {
- return new Object[][] {
- { args("--help"),
- expectedErrOutput(INFO_SETUP_DESCRIPTION.get()) },
- { args("--cli", "create-directory-server", "--doNotStart", "--ldapPort", "1389",
- "--adminConnectorPort", "4444",
- "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
- "-a"), expectedErrOutput(LocalizableMessage.EMPTY) },
- { args("--cli", "--doNotStart", "--ldapPort", "1389", "--adminConnectorPort", "4444",
- "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
- "-a", "--ldapsPort", "1636", "--generateSelfSignedCertificate"), null },
- };
- }
-
- @DataProvider(name = "invalidArguments")
- Object[][] createInValidArguments() throws Exception {
- return new Object[][] {
- { args("-c"),
- expectedErrOutput(
- ERR_ERROR_PARSING_ARGS.get(ERR_SUBCMDPARSER_NO_GLOBAL_ARGUMENT_FOR_SHORT_ID.get("c"))) },
- { args("-N"), expectedErrOutput(ERR_ERROR_PARSING_ARGS.get(
- ERR_ARGPARSER_NO_VALUE_FOR_ARGUMENT_WITH_SHORT_ID.get("N"))) },
- };
- }
-
- @DataProvider(name = "validPorts")
- Object[][] createValidPorts() throws Exception {
- return new Object[][] {
- { args("--cli", "--doNotStart", "--ldapPort", "1389", "--adminConnectorPort", "4444",
- "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
- "-a"), null },
- { args("--cli", "--doNotStart", "--ldapPort", "1389", "--adminConnectorPort", "4444",
- "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
- "-a", "--ldapsPort", "1636"), null },
- { args("--cli", "--doNotStart", "--ldapPort", "1389", "--adminConnectorPort", "4444",
- "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
- "-a", "--jmxPort", "1689"), null },
- };
- }
-
- @DataProvider(name = "invalidPorts")
- Object[][] createInValidPorts() throws Exception {
- return new Object[][] {
- { args("--cli", "--doNotStart", "--ldapPort", "1389", "--adminConnectorPort", "4444",
- "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
- "-a", "--jmxPort", "1389"),
- expectedErrOutput(
- ERR_CANNOT_INITIALIZE_ARGS.get(ERR_PORT_ALREADY_SPECIFIED.get("1389"))) },
- { args("--cli", "--doNotStart", "--ldapPort", "1389", "--adminConnectorPort", "4444",
- "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
- "-a", "--ldapsPort", "1389"),
- expectedErrOutput(
- ERR_CANNOT_INITIALIZE_ARGS.get(ERR_PORT_ALREADY_SPECIFIED.get("1389"))) },
- { args("--cli", "--doNotStart", "--ldapPort", "70000", "--adminConnectorPort", "4444",
- "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
- "-a"),
- expectedErrOutput(ERR_ERROR_PARSING_ARGS.get(
- ERR_ARGPARSER_VALUE_UNACCEPTABLE_FOR_LONG_ID.get(70000, "ldapPort",
- ERR_INTARG_VALUE_ABOVE_UPPER_BOUND.get("ldapPort", 70000, 65535)))) },
- { args("--cli", "--doNotStart", "--ldapPort", "-1", "--adminConnectorPort", "4444",
- "-D", "cn=Directory Manager", "-w", "password", "-b", "dc=example,dc=com",
- "-a"),
- expectedErrOutput(ERR_ERROR_PARSING_ARGS.get(
- ERR_ARGPARSER_VALUE_UNACCEPTABLE_FOR_LONG_ID.get(-1, "ldapPort",
- ERR_INTARG_VALUE_BELOW_LOWER_BOUND.get("ldapPort", -1, 1)))) },
- };
- }
-
- @Test(dataProvider = "validArguments")
- public void testRunValidArguments(String[] arguments, LocalizableMessage expectedErrOutput) throws Exception {
- run(arguments, true, expectedErrOutput);
- }
-
- @Test(dataProvider = "invalidArguments")
- public void testRunInvalidArguments(String[] arguments, LocalizableMessage expectedErrOutput) throws Exception {
- run(arguments, false, expectedErrOutput);
- }
-
- @Test(dataProvider = "validPorts")
- public void testcheckValidProvidedPorts(String[] arguments, LocalizableMessage expectedErrOutput) throws Exception {
- run(arguments, true, expectedErrOutput);
- }
-
- @Test(dataProvider = "invalidPorts")
- public void testcheckInvalidProvidedPorts(String[] arguments, LocalizableMessage expectedErrOutput)
- throws Exception {
- run(arguments, false, expectedErrOutput);
- }
-
- private void run(final String[] arguments, final boolean shouldSucceed, final LocalizableMessage expectedErrOutput)
- throws UnsupportedEncodingException {
- PrintStream outStream = null;
- PrintStream errStream = null;
- int resultCode = 0;
- try {
- final ByteArrayOutputStream out = new ByteArrayOutputStream();
- outStream = new PrintStream(out);
- final ByteArrayOutputStream err = new ByteArrayOutputStream();
- errStream = new PrintStream(err);
-
- final SetupCli setup = new SetupCli(outStream, errStream);
- resultCode = setup.run(arguments);
-
- if (shouldSucceed) {
- if (expectedErrOutput != null) {
- assertThat(out.toString("UTF-8")).contains(wrapText(expectedErrOutput, MAX_LINE_WIDTH));
- }
- assertThat(err.size()).isEqualTo(0);
- assertThat(resultCode).isEqualTo(ReturnCode.SUCCESS.get());
- } else {
- assertThat(resultCode).isNotEqualTo(ReturnCode.SUCCESS.get());
- /*
- * If an application is interactive, all messages should be redirect to the stdout. (info, warnings,
- * errors). Otherwise, standard messages should be displayed in the stdout(info) and errors to the
- * stderr (warnings, errors).
- */
- ByteArrayOutputStream std = setup.isInteractive() ? out : err;
- assertThat(std.size()).isGreaterThan(0);
- String errMsg = getUnWrappedMessage(std.toString("UTF-8"));
- String expectedMsg = getUnWrappedMessage(expectedErrOutput.toString());
- assertTrue(errMsg.contains(expectedMsg), errMsg + "\n >---< \n" + expectedMsg);
- }
- } finally {
- closeSilently(outStream, errStream);
- }
- }
-
- /** Arguments passed to the command. */
- private String[] args(String... arguments) {
- return arguments;
- }
-
- /** A message the error output is expected to contain. */
- private LocalizableMessage expectedErrOutput(LocalizableMessage val) {
- return val;
- }
-
- /**
- * Returns the message to its unwrapped form.
- *
- * @param st
- * The message which need to be unwrapped.
- * @return The unwrapped message.
- */
- private String getUnWrappedMessage(final String st) {
- return st.replaceAll(Utils.LINE_SEPARATOR, " ");
- }
-}
diff --git a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/AbstractSetupTestCase.java b/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/AbstractSetupTestCase.java
deleted file mode 100644
index 2cfe4a1..0000000
--- a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/AbstractSetupTestCase.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-import org.forgerock.opendj.ldap.SdkTestCase;
-import org.testng.annotations.Test;
-
-/**
- * An abstract class that all setup unit tests should extend.
- */
-@Test(groups = { "precommit", "types", "sdk" })
-public abstract class AbstractSetupTestCase extends SdkTestCase {
-
-}
-
-
-
-
diff --git a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/CertificateTestCase.java b/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/CertificateTestCase.java
deleted file mode 100644
index 2ce3230..0000000
--- a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/CertificateTestCase.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.forgerock.opendj.config.server.ConfigException;
-import org.forgerock.opendj.server.setup.model.Certificate.CertificateType;
-import org.testng.annotations.Test;
-
-public class CertificateTestCase extends AbstractSetupTestCase {
-
- /**
- * Default is a self-signed certificate.
- */
- @Test
- public void testGetDefault() {
- final Certificate cert = new Certificate();
- assertThat(cert.getType()).isEqualTo(CertificateType.SELF_SIGNED);
- assertThat(cert.getKeyStoreFile()).isNull();
- assertThat(cert.getKeyStorePin()).isEmpty();
- }
-
- @Test
- public void testValidateDefaultCertificate() throws ConfigException {
- final Certificate cert = new Certificate();
- cert.validate();
- }
-
- /**
- * Certificates which are not self-signed should fail when no key store is provided.
- *
- * @throws ConfigException
- */
- @Test(expectedExceptions = ConfigException.class)
- public void testValidateCertificateFailsWhenNoKeystoreProvided() throws ConfigException {
- final Certificate cert = new Certificate();
- cert.setType(CertificateType.JKS);
- cert.validate();
- }
-
- /**
- * Certificates which are not self-signed should fail when no key store is provided.
- *
- * @throws ConfigException
- */
- @Test(expectedExceptions = ConfigException.class)
- public void testValidatePKCS11CertificateFailsWhenNoKeyPinProvided() throws ConfigException {
- final Certificate cert = new Certificate();
- cert.setType(CertificateType.PKCS11);
- cert.validate();
- }
-
- /**
- * Certificates which are not self-signed should fail when no key pin is provided.
- *
- * @throws ConfigException
- * Occurs if this configuration is invalid.
- * @throws IOException
- * If an exception occurs when creating the keystore.
- */
- @Test(expectedExceptions = ConfigException.class)
- public void testValidateCertificateFailsWhenNoKeyPinProvided() throws ConfigException, IOException {
- final Certificate cert = new Certificate();
- cert.setType(CertificateType.JKS);
- File keystore = null;
- try {
- keystore = File.createTempFile("keystore", ".keystore");
- cert.setKeyStoreFile(keystore);
- cert.validate();
- } catch (IOException e) {
- throw e;
- } finally {
- if (keystore != null) {
- keystore.delete();
- }
- }
- }
-
- /**
- * Builds a new JKS certificate.
- *
- * @throws ConfigException
- * Occurs if this configuration is invalid.
- * @throws IOException
- * If an exception occurs when creating the temp keystore.
- */
- @Test
- public void testValidateJKSCertificate() throws ConfigException, IOException {
- final Certificate cert = new Certificate();
- cert.setType(CertificateType.JKS);
- File keystore = null;
- try {
- keystore = File.createTempFile("keystore", ".keystore");
- cert.setKeyStoreFile(keystore);
- cert.setKeyStorePin("key pin");
- cert.validate();
- } finally {
- if (keystore != null) {
- keystore.delete();
- }
- }
- }
-
-}
diff --git a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/DataConfigurationTestCase.java b/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/DataConfigurationTestCase.java
deleted file mode 100644
index 04b2e9e..0000000
--- a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/DataConfigurationTestCase.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.forgerock.opendj.server.setup.model.DataConfiguration.Type;
-import org.testng.annotations.Test;
-
-/**
- * This class tests the data store functionality.
- */
-public class DataConfigurationTestCase extends AbstractSetupTestCase {
-
- /**
- * Creates a default data configuration.
- */
- @Test
- public void testGetDefaultDataConfiguration() {
- final DataConfiguration data = new DataConfiguration();
- assertThat(data.getDirectoryBaseDN()).isEqualTo(DataConfiguration.DEFAULT_DIRECTORY_BASE_DN);
- assertFalse(data.isEmptyDatabase());
- assertFalse(data.isImportLDIF());
- assertFalse(data.isOnlyBaseEntry());
- assertTrue(data.isAutomaticallyImportGenerated());
-
- assertThat(data.getLdifImportDataPath()).isNull();
- assertThat(data.getNumberOfUserEntries()).isEqualTo(DataConfiguration.IMPORT_ENTRIES_DEFAULT_VALUE);
- }
-
- /**
- * Creates a custom data configuration.
- *
- * @throws IOException
- */
- @Test
- public void testCustomDataConfiguration() throws IOException {
- final DataConfiguration data = new DataConfiguration();
- final int userEntries = 300;
- data.setNumberOfUserEntries(userEntries);
- assertThat(data.getNumberOfUserEntries()).isEqualTo(userEntries);
- assertTrue(data.isAutomaticallyImportGenerated());
- assertFalse(data.isImportLDIF());
- assertFalse(data.isEmptyDatabase());
- assertFalse(data.isOnlyBaseEntry());
- // Set another config
- data.setType(Type.IMPORT_LDIF);
- File importLdifFile = null;
- try {
- importLdifFile = File.createTempFile("import_ldif_file", ".ldif");
- data.setLdifImportDataPath(importLdifFile);
- assertTrue(data.isImportLDIF());
- assertThat(data.getLdifImportDataPath().exists());
- // Return to previous config.
- data.setType(Type.AUTOMATICALLY_GENERATED);
- assertThat(data.getNumberOfUserEntries()).isEqualTo(userEntries);
- assertTrue(data.isAutomaticallyImportGenerated());
- assertFalse(data.isImportLDIF());
- } finally {
- if (importLdifFile != null) {
- importLdifFile.delete();
- }
- }
- }
-
- /**
- * Tests the type of the data configuration to make sure the boolean types are correctly assigned.
- */
- @Test
- public void testDataConfigurationType() {
- final DataConfiguration data = new DataConfiguration();
- assertTrue(data.isAutomaticallyImportGenerated());
- assertFalse(data.isImportLDIF());
- assertFalse(data.isEmptyDatabase());
- assertFalse(data.isOnlyBaseEntry());
- assertThat(data.getType() == Type.AUTOMATICALLY_GENERATED);
- // Import LDIF
- data.setType(Type.IMPORT_LDIF);
- assertTrue(data.isImportLDIF());
- assertFalse(data.isAutomaticallyImportGenerated());
- assertFalse(data.isEmptyDatabase());
- assertFalse(data.isOnlyBaseEntry());
- assertThat(data.getType() == Type.IMPORT_LDIF);
- // Empty database
- data.setType(Type.EMPTY_DATABASE);
- assertFalse(data.isAutomaticallyImportGenerated());
- assertFalse(data.isImportLDIF());
- assertTrue(data.isEmptyDatabase());
- assertFalse(data.isOnlyBaseEntry());
- assertThat(data.getType() == Type.EMPTY_DATABASE);
- // Only base entry
- data.setType(Type.BASE_ENTRY_ONLY);
- assertTrue(data.isOnlyBaseEntry());
- assertFalse(data.isAutomaticallyImportGenerated());
- assertFalse(data.isImportLDIF());
- assertFalse(data.isEmptyDatabase());
- assertThat(data.getType() == Type.BASE_ENTRY_ONLY);
- }
-}
diff --git a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/ListenerSettingsTestCase.java b/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/ListenerSettingsTestCase.java
deleted file mode 100644
index c1add50..0000000
--- a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/ListenerSettingsTestCase.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-
-import static com.forgerock.opendj.cli.CliConstants.*;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import org.forgerock.opendj.ldap.TestCaseUtils;
-import org.testng.annotations.Test;
-
-public class ListenerSettingsTestCase extends AbstractSetupTestCase {
-
- /**
- * Retrieves default settings.
- */
- @Test
- public void testGetDefault() {
- final ListenerSettings dsSettings = new ListenerSettings();
- assertThat(dsSettings.getAdminPort()).isEqualTo(DEFAULT_ADMIN_PORT);
- assertThat(dsSettings.getHTTPPort()).isEqualTo(DEFAULT_HTTP_PORT);
- assertThat(dsSettings.getJMXPort()).isEqualTo(DEFAULT_JMX_PORT);
- assertThat(dsSettings.getLdapPort()).isEqualTo(DEFAULT_LDAP_PORT);
- assertThat(dsSettings.getLdapsPort()).isEqualTo(DEFAULT_LDAPS_PORT);
- assertThat(dsSettings.getSNMPPort()).isEqualTo(DEFAULT_SNMP_PORT);
- assertThat(dsSettings.getSSLPortNumber()).isEqualTo(DEFAULT_SSL_PORT);
-
- assertThat(dsSettings.getHostName()).isEmpty();
- assertThat(dsSettings.getRootUserDN()).isEqualTo(DEFAULT_ROOT_USER_DN);
- assertThat(dsSettings.getPassword()).isNull();
- assertFalse(dsSettings.isSSLEnabled());
- assertThat(dsSettings.getCertificate()).isNull();
- assertFalse(dsSettings.isTLSEnabled());
- assertFalse(dsSettings.isJMXConnectionHandlerEnabled());
- assertFalse(dsSettings.isSNMPConnectionHandlerEnabled());
- assertTrue(dsSettings.isHTTPConnectionHandlerEnabled());
- }
-
- /**
- * Tries to retrieve a free port number.
- *
- * @throws Exception
- */
- @Test
- public void testGetFreePort() throws Exception {
- // Finds a free socket
- final InetSocketAddress isa = TestCaseUtils.findFreeSocketAddress();
- // Bound the free socket
- final int port = isa.getPort();
- final ServerSocket boundSocket = new ServerSocket(port);
- // Verify the new port number is different from the free socket and verify it's free.
- final int newPort = ListenerSettings.getFreeSocketPort(port);
- assertThat(newPort).isNotEqualTo(port);
- assertTrue(Math.abs(newPort - port) % PORT_INCREMENT == 0);
-
- boundSocket.close();
- }
-
- /**
- * Port number is invalid when inferior to 0 or superior to 65535.
- *
- * @throws Exception
- */
- @Test(expectedExceptions = IllegalArgumentException.class)
- public void testInvalidPort() throws Exception {
- ListenerSettings.getFreeSocketPort(65536);
- }
-
- /**
- * Port number is invalid when inferior to 0 or superior to 65535.
- *
- * @throws Exception
- */
- @Test(expectedExceptions = IllegalArgumentException.class)
- public void testInvalidNegativePort() throws Exception {
- ListenerSettings.getFreeSocketPort(-1);
- }
-}
diff --git a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/ModelTestCase.java b/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/ModelTestCase.java
deleted file mode 100644
index e035470..0000000
--- a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/ModelTestCase.java
+++ /dev/null
@@ -1,390 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-import static com.forgerock.opendj.cli.CliConstants.*;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.LinkedList;
-
-import org.forgerock.opendj.config.server.ConfigException;
-import org.forgerock.opendj.server.setup.model.Certificate.CertificateType;
-import org.forgerock.opendj.server.setup.model.Model.DataStoreModel;
-import org.forgerock.opendj.server.setup.model.Model.Type;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-/**
- * This class tests the model functionality.
- */
-public class ModelTestCase extends AbstractSetupTestCase {
-
- /**
- * Generates a model and verifies if the configuration is valid.
- *
- * @throws ConfigException
- */
- @Test
- public void testCreateDefaultDS() throws ConfigException {
- final Model ds = new DataStoreModel();
-
- Assert.assertTrue(ds.isStandAlone());
-
- final ListenerSettings dsSettings = ds.getListenerSettings();
-
- // Verify connection handler by default
- assertTrue(dsSettings.isHTTPConnectionHandlerEnabled());
- assertFalse(dsSettings.isSSLEnabled());
- assertFalse(dsSettings.isTLSEnabled());
- assertFalse(dsSettings.isJMXConnectionHandlerEnabled());
- ds.getListenerSettings().setPassword("password");
-
- // Verify ports
- assertThat(dsSettings.getAdminPort()).isEqualTo(DEFAULT_ADMIN_PORT);
- assertThat(dsSettings.getHTTPPort()).isEqualTo(DEFAULT_HTTP_PORT);
- assertThat(dsSettings.getJMXPort()).isEqualTo(DEFAULT_JMX_PORT);
- assertThat(dsSettings.getLdapPort()).isEqualTo(DEFAULT_LDAP_PORT);
- assertThat(dsSettings.getLdapsPort()).isEqualTo(DEFAULT_LDAPS_PORT);
- assertThat(dsSettings.getSNMPPort()).isEqualTo(DEFAULT_SNMP_PORT);
- assertThat(dsSettings.getSSLPortNumber()).isEqualTo(DEFAULT_SSL_PORT);
-
- assertFalse(ds.isService());
- assertTrue(ds.isStartingServerAfterSetup());
- assertFalse(ds.isPartOfReplicationTopology());
- assertTrue(ds.isStartingServerAfterSetup());
-
- assertThat(ds.getDataConfiguration()).isNotNull();
- assertThat(ds.getServerRuntimeSettings()).isEqualTo(RuntimeOptions.getDefault());
- assertFalse(ds.hasLicense());
-
- assertThat(ds.getType()).isEqualTo(Type.STANDALONE);
- assertFalse(ds.isSecure());
-
- ds.validate();
-
- }
-
- /**
- * Configure a DS with null listener settings should fail.
- *
- * @throws ConfigException
- * If this configuration is invalid.
- */
- @Test(expectedExceptions = ConfigException.class,
- expectedExceptionsMessageRegExp = "Invalid settings")
- public void testIsValidDSDoesNotAllowNullListenerSettings() throws ConfigException {
- final Model ds = new DataStoreModel();
- ds.setListenerSettings(null);
- ds.validate();
- }
-
- /**
- * Configure a DS with null data configuration should fail.
- *
- * @throws ConfigException
- * If this configuration is invalid.
- */
- @Test(expectedExceptions = ConfigException.class,
- expectedExceptionsMessageRegExp = "Invalid data configuration")
- public void testIsValidDSDoesNotAllowNullDataConfiguration() throws ConfigException {
- final Model ds = new DataStoreModel();
- ds.setDataConfiguration(null);
- ds.validate();
- }
-
- /**
- * Configure a DS - import LDIF data with no path configured for the import LDIF.
- *
- * @throws ConfigException
- * If this configuration is invalid.
- */
- @Test(expectedExceptions = ConfigException.class,
- expectedExceptionsMessageRegExp = "Invalid import ldif file.")
- public void testIsValidDSImportLDIFDoesNotAllowNullImportLDIFPath() throws ConfigException {
- final Model ds = new DataStoreModel();
- ds.getDataConfiguration().setType(DataConfiguration.Type.IMPORT_LDIF);
-
- ds.validate();
- }
-
- /**
- * Configure a DS - A password must be set for the root DN (password or password file).
- *
- * @throws ConfigException
- * If this configuration is invalid.
- */
- @Test(expectedExceptions = ConfigException.class,
- expectedExceptionsMessageRegExp = "A password must be set for the root DN.")
- public void testIsValidDSDoesNotAllowNullPassword() throws ConfigException {
- final Model ds = new DataStoreModel();
-
- ds.validate();
- }
-
- /**
- * Configure a DS - A password must be set for the root DN (password or password file).
- *
- * @throws ConfigException
- * If this configuration is invalid.
- */
- @Test(expectedExceptions = ConfigException.class,
- expectedExceptionsMessageRegExp = "A password must be set for the root DN.")
- public void testIsValidDSDoesNotAllowNullPasswordFile() throws ConfigException {
- final Model ds = new DataStoreModel();
- ds.getListenerSettings().setPasswordFile(null);
- ds.validate();
- }
-
- /**
- * Configure a DS - A password must be set for the root DN (password or password file).
- *
- * @throws ConfigException
- * If this configuration is invalid.
- * @throws IOException
- * If an error occurred when the temporary file is created.
- */
- @Test
- public void testIsValidDSAllowsPasswordFile() throws ConfigException, IOException {
- final Model ds = new DataStoreModel();
- File passwordFile = null;
-
- try {
- passwordFile = File.createTempFile("passwordFile", ".pwd");
- ds.getListenerSettings().setPasswordFile(passwordFile);
- } catch (IOException e) {
- throw e;
- } finally {
- if (passwordFile != null) {
- passwordFile.delete();
- }
- }
-
- ds.validate();
- }
-
- @Test
- public void testCreateDSAllowsNullCertificate() throws ConfigException {
- final Model ds = new DataStoreModel();
- ds.getListenerSettings().setCertificate(null);
- assertFalse(ds.isSecure());
- }
-
- @Test
- public void testCreateSecureDS() throws ConfigException {
- final Model ds = new DataStoreModel();
- final Certificate cert = new Certificate();
- cert.setType(CertificateType.SELF_SIGNED);
- ds.getListenerSettings().setCertificate(cert);
-
- assertTrue(ds.isSecure());
- }
-
-
- /**
- * Configure a DS - replication enabled with null replication configuration should fail.
- *
- * @throws ConfigException
- * If this configuration is invalid.
- */
- @Test(expectedExceptions = ConfigException.class,
- expectedExceptionsMessageRegExp = "No replication configuration found")
- public void testCreateDSFirstInTopologyDoesNotAllowEmptyReplicationConfiguration() throws ConfigException {
- final Model ds = new DataStoreModel();
- ds.setType(Type.FIRST_IN_TOPOLOGY);
- assertTrue(ds.isFirstInTopology());
- assertThat(ds.getReplicationConfiguration()).isNull();
-
- ds.validate();
- }
-
- /**
- * The replication configuration doesn't set a valid administrator name.
- *
- * @throws NullPointerException
- * If the administrator's name is null.
- */
- @Test(expectedExceptions = NullPointerException.class)
- public void testCreateDefaultDSExistingTopologyDoesNotAllowNullAdministrator() throws ConfigException {
- final Model ds = new DataStoreModel();
- ReplicationConfiguration rConfig = new ReplicationConfiguration();
- ds.setReplicationConfiguration(rConfig);
- ds.setType(Type.IN_EXISTING_TOPOLOGY);
- assertTrue(ds.isPartOfReplicationTopology());
- assertThat(ds.getReplicationConfiguration()).isNotNull();
-
- ds.validate();
- }
-
- /**
- * The replication configuration doesn't allow null password.
- *
- * @throws NullPointerException
- * If the password is null.
- */
- @Test(expectedExceptions = NullPointerException.class)
- public void testCreateDefaultDSExistingTopologyDoesNotAllowNullPassword() throws ConfigException {
- final Model ds = new DataStoreModel();
- final ReplicationConfiguration rConfig = new ReplicationConfiguration();
- rConfig.setAdministrator("admin");
-
- ds.setReplicationConfiguration(rConfig);
- ds.setInExistingTopology();
- assertTrue(ds.isPartOfReplicationTopology());
- assertThat(ds.getReplicationConfiguration()).isNotNull();
-
- ds.validate();
- }
-
-
- /**
- * The replication configuration doesn't set a valid administrator name.
- *
- * @throws NullPointerException
- * If the administrator's name is null.
- */
- @Test(expectedExceptions = NullPointerException.class)
- public void testCreateDefaultDSExistingTopologyDoesNotAllowNullGlobalAdministrator() throws ConfigException {
- final Model ds = new DataStoreModel();
- ReplicationConfiguration rConfig = new ReplicationConfiguration();
- rConfig.setAdministrator("admin");
- rConfig.setPassword("password".toCharArray());
- ds.setReplicationConfiguration(rConfig);
- ds.setType(Type.IN_EXISTING_TOPOLOGY);
- assertTrue(ds.isPartOfReplicationTopology());
- assertThat(ds.getReplicationConfiguration()).isNotNull();
-
- ds.validate();
- }
-
- /**
- * The replication configuration doesn't allow null password for the global administrator.
- *
- * @throws NullPointerException
- * If the password is null.
- */
- @Test(expectedExceptions = NullPointerException.class)
- public void testCreateDefaultDSExistingTopologyDoesNotAllowNullPasswordForGlobalAdministrator()
- throws ConfigException {
- final Model ds = new DataStoreModel();
- final ReplicationConfiguration rConfig = new ReplicationConfiguration();
- rConfig.setAdministrator("admin");
- rConfig.setPassword("password".toCharArray());
- rConfig.setGlobalAdministratorUID("GlobalAdmin");
- ds.setReplicationConfiguration(rConfig);
- ds.setInExistingTopology();
- assertTrue(ds.isPartOfReplicationTopology());
- assertThat(ds.getReplicationConfiguration()).isNotNull();
-
- ds.validate();
- }
-
- /**
- * The replication configuration doesn't allow null suffixes.
- *
- * @throws ConfigException
- * If the password is null.
- */
- @Test(expectedExceptions = ConfigException.class)
- public void testCreateDefaultDSExistingTopologyDoesNotAllowNullSuffixes() throws ConfigException {
- final Model ds = new DataStoreModel();
-
- final ReplicationConfiguration rConfig = new ReplicationConfiguration();
- rConfig.setAdministrator("admin");
- rConfig.setPassword("password".toCharArray());
- rConfig.setGlobalAdministratorUID("GlobalAdmin");
- rConfig.setGlobalAdministratorPassword("password2".toCharArray());
-
- ds.setReplicationConfiguration(rConfig);
- ds.setInExistingTopology();
- assertTrue(ds.isPartOfReplicationTopology());
- assertThat(ds.getReplicationConfiguration()).isNotNull();
-
- ds.validate();
- }
-
- /**
- * The replication configuration doesn't allow empty suffixes.
- *
- * @throws ConfigException
- * If the password is null.
- */
- @Test(expectedExceptions = ConfigException.class)
- public void testCreateDefaultDSExistingTopologyDoesNotAllowEmptySuffixes() throws ConfigException {
- final Model ds = new DataStoreModel();
-
- final ReplicationConfiguration rConfig = new ReplicationConfiguration();
- rConfig.setAdministrator("admin");
- rConfig.setPassword("password".toCharArray());
-
- rConfig.setGlobalAdministratorUID("GlobalAdmin");
- rConfig.setGlobalAdministratorPassword("password2".toCharArray());
- rConfig.setSuffixes(new LinkedList<String>());
-
- ds.setReplicationConfiguration(rConfig);
- ds.setInExistingTopology();
- assertTrue(ds.isPartOfReplicationTopology());
- assertThat(ds.getReplicationConfiguration()).isNotNull();
-
- ds.validate();
- }
-
- /**
- * Creates a valid first DS in topology.
- *
- * @throws ConfigException
- * If a configuration exception occurs.
- */
- @Test
- public void testCreateDSFirstInTopology() throws ConfigException {
- final Model ds = new DataStoreModel();
- ds.getListenerSettings().setPassword("password");
- ds.setFirstInTopology();
- assertTrue(ds.isFirstInTopology());
- assertThat(ds.getReplicationConfiguration()).isNull();
-
- // Sets the replication configuration
- final ReplicationConfiguration rconf = new ReplicationConfiguration();
- rconf.setAdministrator("admin");
- rconf.setPassword("password".toCharArray());
- ds.setReplicationConfiguration(rconf);
-
- assertThat(ds.getReplicationConfiguration().getReplicationPort()).isEqualTo(
- ReplicationConfiguration.DEFAULT_REPLICATION_PORT);
- assertFalse(ds.getReplicationConfiguration().isSecure());
-
- ds.validate();
- }
-
- /**
- * Demonstrates how to set the license for a DS.
- *
- * @throws ConfigException
- * If a configuration exception occurs.
- */
- @Test
- public void testCreateDefaultDSWithLicense() throws ConfigException {
- final Model ds = new DataStoreModel();
- final String license = "This is a CDDL License";
- ds.setLicense(license);
- ds.getListenerSettings().setPassword("password");
- assertTrue(ds.hasLicense());
- ds.validate();
- }
-}
diff --git a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/RuntimeOptionsTestCase.java b/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/RuntimeOptionsTestCase.java
deleted file mode 100644
index 88a7169..0000000
--- a/opendj-server/src/test/java/org/forgerock/opendj/server/setup/model/RuntimeOptionsTestCase.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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 2014 ForgeRock AS.
- */
-package org.forgerock.opendj.server.setup.model;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.forgerock.opendj.server.setup.model.RuntimeOptions.INITIAL_MEMORY;
-import static org.forgerock.opendj.server.setup.model.RuntimeOptions.MAXIMUM_MEMORY;
-
-import org.testng.annotations.Test;
-
-/**
- * This class contains some tests to demonstrate the use of the runtime options in the setup.
- */
-public class RuntimeOptionsTestCase extends AbstractSetupTestCase {
-
- @Test
- public void testGetDefault() {
- final RuntimeOptions options = RuntimeOptions.getDefault();
- assertThat(options.getInitialMemory()).isEqualTo(INITIAL_MEMORY);
- assertThat(options.getMaximumMemory()).isEqualTo(MAXIMUM_MEMORY);
- assertThat(options.getAdditionalArguments()).contains("-client");
- }
-
- @Test(expectedExceptions = IllegalArgumentException.class)
- public void testRuntimeOptionsDoesNotAllowNullAdditionalArguments() {
- final RuntimeOptions options = new RuntimeOptions();
- options.setInitialMemory(INITIAL_MEMORY);
- options.setMaximumMemory(MAXIMUM_MEMORY);
- options.setAdditionalArguments((String[]) null);
- }
-
- @Test
- public void testEqualitySucceed() {
- final RuntimeOptions options = RuntimeOptions.getDefault();
- assertThat(options.getInitialMemory()).isEqualTo(INITIAL_MEMORY);
- assertThat(options.getMaximumMemory()).isEqualTo(MAXIMUM_MEMORY);
- assertThat(options.getAdditionalArguments()).contains("-client");
-
- final RuntimeOptions options2 = new RuntimeOptions();
- options2.setInitialMemory(INITIAL_MEMORY);
- options2.setMaximumMemory(MAXIMUM_MEMORY);
- options2.setAdditionalArguments(new String[] { "-client" });
-
- assertThat(options).isEqualTo(options2);
- }
-
- @Test
- public void testEqualityFails() {
- final RuntimeOptions options = RuntimeOptions.getDefault();
- assertThat(options.getInitialMemory()).isEqualTo(INITIAL_MEMORY);
- assertThat(options.getMaximumMemory()).isEqualTo(MAXIMUM_MEMORY);
- assertThat(options.getAdditionalArguments()).contains("-client");
-
- final RuntimeOptions options2 = new RuntimeOptions();
- options2.setInitialMemory(INITIAL_MEMORY);
- options2.setMaximumMemory(MAXIMUM_MEMORY);
- options2.setAdditionalArguments(new String[] { "" });
-
- assertThat(options).isNotEqualTo(options2);
- }
-
- @Test
- public void testRuntimeOptionsToString() {
-
- final RuntimeOptions options = new RuntimeOptions();
- options.setInitialMemory(INITIAL_MEMORY);
- options.setMaximumMemory(MAXIMUM_MEMORY);
- options.setAdditionalArguments(new String[] { "-client" });
-
- assertThat(options.toString()).contains(String.valueOf(INITIAL_MEMORY));
- assertThat(options.toString()).contains(String.valueOf(MAXIMUM_MEMORY));
- assertThat(options.toString()).contains("-client");
- }
-}
--
Gitblit v1.10.0