| | |
| | | import java.io.BufferedReader; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.OutputStream; |
| | | import java.io.PrintStream; |
| | |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import javax.naming.ldap.LdapName; |
| | | |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageDescriptor.Arg0; |
| | | import org.forgerock.i18n.LocalizableMessageDescriptor.Arg1; |
| | | import org.forgerock.i18n.LocalizedIllegalArgumentException; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.config.ManagedObjectDefinition; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.server.config.client.BackendCfgClient; |
| | | import org.forgerock.opendj.server.config.server.BackendCfg; |
| | | import org.opends.messages.QuickSetupMessages; |
| | |
| | | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | |
| | | /** |
| | | * Constructor for the InstallDS object. |
| | | * |
| | |
| | | * the print stream to use for standard output. |
| | | * @param err |
| | | * the print stream to use for standard error. |
| | | * @param in |
| | | * the input stream to use for standard input. |
| | | * @param tempLogFile |
| | | * the temporary log file where messages will be logged. |
| | | */ |
| | | public InstallDS(PrintStream out, PrintStream err, InputStream in, TempLogFile tempLogFile) |
| | | private InstallDS(PrintStream out, PrintStream err, TempLogFile tempLogFile) |
| | | { |
| | | super(out, err); |
| | | this.tempLogFile = tempLogFile; |
| | |
| | | */ |
| | | public static int mainCLI(String[] args, final TempLogFile tempLogFile) |
| | | { |
| | | return mainCLI(args, System.out, System.err, System.in, tempLogFile); |
| | | return mainCLI(args, System.out, System.err, tempLogFile); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param errStream |
| | | * The output stream to use for standard error, or <CODE>null</CODE> |
| | | * if standard error is not needed. |
| | | * @param inStream |
| | | * The input stream to use for standard input. |
| | | * @param tempLogFile |
| | | * the temporary log file where messages will be logged. |
| | | * @return The error code. |
| | | */ |
| | | public static int mainCLI( |
| | | String[] args, OutputStream outStream, OutputStream errStream, InputStream inStream, TempLogFile tempLogFile) |
| | | private static int mainCLI( |
| | | String[] args, OutputStream outStream, OutputStream errStream, TempLogFile tempLogFile) |
| | | { |
| | | final PrintStream out = NullOutputStream.wrapOrNullStream(outStream); |
| | | |
| | | System.setProperty(Constants.CLI_JAVA_PROPERTY, "true"); |
| | | |
| | | final PrintStream err = NullOutputStream.wrapOrNullStream(errStream); |
| | | final InstallDS install = new InstallDS(out, err, inStream, tempLogFile); |
| | | final InstallDS install = new InstallDS(out, err, tempLogFile); |
| | | |
| | | return install.execute(args); |
| | | } |
| | |
| | | * the command-line arguments provided to this program. |
| | | * @return the return code (SUCCESSFUL, USER_DATA_ERROR or BUG). |
| | | */ |
| | | public int execute(String[] args) |
| | | private int execute(String[] args) |
| | | { |
| | | argParser = new InstallDSArgumentParser(InstallDS.class.getName()); |
| | | try |
| | |
| | | return printAndReturnErrorCode(e.getMessageObject()).getReturnCode(); |
| | | } |
| | | |
| | | |
| | | System.setProperty(Constants.CLI_JAVA_PROPERTY, "true"); |
| | | final Installer installer = new Installer(); |
| | | installer.setTempLogFile(tempLogFile); |
| | |
| | | println(); |
| | | } |
| | | |
| | | |
| | | private InstallReturnCode printAndReturnErrorCode(LocalizableMessage message) |
| | | { |
| | | println(message); |
| | |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isQuiet() |
| | | { |
| | | return argParser.quietArg.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isInteractive() |
| | | { |
| | | return !argParser.noPromptArg.isPresent(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isMenuDrivenMode() { |
| | | return true; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isScriptFriendly() { |
| | | return false; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isAdvancedMode() { |
| | | return false; |
| | | } |
| | | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public boolean isVerbose() { |
| | | return argParser.verboseArg.isPresent(); |
| | |
| | | { |
| | | try |
| | | { |
| | | new LdapName(baseDN); |
| | | DN.valueOf(baseDN); |
| | | } |
| | | catch (final Exception e) |
| | | catch (final LocalizedIllegalArgumentException | NullPointerException e) |
| | | { |
| | | errorMessages.add(ERR_INSTALLDS_CANNOT_PARSE_DN.get(baseDN, e.getMessage())); |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | new LdapName(dn); |
| | | DN.valueOf(dn); |
| | | if (dn.trim().length() == 0) |
| | | { |
| | | toRemove.add(dn); |
| | |
| | | final List<String> baseDNs = promptIfRequiredForDNs( |
| | | argParser.baseDNArg, lastResetBaseDN, INFO_INSTALLDS_PROMPT_BASEDN.get(), true); |
| | | return promptIfRequiredForDataOptions(baseDNs); |
| | | |
| | | } |
| | | |
| | | private ManagedObjectDefinition<? extends BackendCfgClient, ? extends BackendCfg> getOrPromptForBackendType() |
| | |
| | | INFO_INSTALLDS_CERT_OPTION_PKCS11.get() |
| | | }; |
| | | |
| | | |
| | | final MenuBuilder<Integer> builder = new MenuBuilder<>(this); |
| | | builder.setPrompt(INFO_INSTALLDS_HEADER_CERT_TYPE.get()); |
| | | |
| | |
| | | { |
| | | return argParser.getConnectTimeout(); |
| | | } |
| | | |
| | | } |