/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2007-2010 Sun Microsystems, Inc.
* Portions Copyright 2012-2013 ForgeRock AS
*/
/**
* This class provides a command-line tool which enables
* administrators to configure the Directory Server.
*/
/**
* A menu call-back which runs a sub-command interactively.
*/
// The sub-command handler.
/**
* Creates a new sub-command handler call-back.
*
* @param handler
* The sub-command handler.
*/
}
/**
* {@inheritDoc}
*/
throws CLIException {
try {
return result;
} else {
{
}
// Success or cancel.
return MenuResult.again();
}
} catch (ArgumentException e) {
} catch (ClientException e) {
}
}
}
/**
* The interactive mode sub-menu implementation.
*/
// The menu.
/**
* Creates a new sub-menu implementation.
*
* @param app
* The console application.
* @param rd
* The relation definition.
* @param ch
* The optional create sub-command.
* @param dh
* The optional delete sub-command.
* @param lh
* The optional list sub-command.
* @param sh
* The option set-prop sub-command.
*/
if (rd instanceof InstantiableRelationDefinition<?,?>) {
InstantiableRelationDefinition<?, ?> ir =
(InstantiableRelationDefinition<?, ?>) rd;
} else if (rd instanceof SetRelationDefinition<?,?>) {
SetRelationDefinition<?, ?> sr =
(SetRelationDefinition<?, ?>) rd;
}
} else {
}
}
}
} else {
callback);
}
}
}
builder.addBackOption(true);
}
/**
* {@inheritDoc}
*/
throws CLIException {
try {
return MenuResult.again();
}
return result;
} catch (CLIException e) {
}
}
}
/**
* The type name which will be used for the most generic managed
* object types when they are instantiable and intended for
* customization only.
*/
/**
* The type name which will be used for the most generic managed
* object types when they are instantiable and not intended for
* customization.
*/
/**
* The tracer object for the debug logger.
*/
// This CLI is always using the administration connector with SSL
private static final boolean alwaysSSL = true;
private long sessionStartTime;
private boolean sessionStartTimePrinted = false;
/**
* Provides the command-line arguments to the main application for
* processing.
*
* @param args
* The set of command-line arguments provided to this
* program.
*/
if (exitCode != 0) {
}
}
/**
* Provides the command-line arguments to the main application for
* processing and returns the exit code as an integer.
*
* @param args
* The set of command-line arguments provided to this
* program.
* @param initializeServer
* Indicates whether to perform basic initialization (which
* should not be done if the tool is running in the same
* JVM as the server).
* @param outStream
* The output stream for standard output.
* @param errStream
* The output stream for standard error.
* @return Zero to indicate that the program completed successfully,
* or non-zero to indicate that an error occurred.
*/
// Only initialize the client environment when run as a standalone
// application.
if (initializeServer) {
try {
} catch (InitializationException e) {
// TODO: is this ok as an error message?
return 1;
}
}
// Run the application.
}
// The argument which should be used to request advanced mode.
// Flag indicating whether or not the application environment has
// already been initialized.
private boolean environmentInitialized = false;
// The factory which the application should use to retrieve its
// management context.
// Flag indicating whether or not the global arguments have
// already been initialized.
private boolean globalArgumentsInitialized = false;
// The sub-command handler factory.
// Mapping of sub-commands to their implementations;
// Indicates whether or not a sub-command was provided.
private boolean hasSubCommand = true;
// The argument which should be used to read dsconfig commands from a file.
// The argument which should be used to request non interactive
// behavior.
// The argument that the user must set to display the equivalent
// non-interactive mode argument
// The argument that allows the user to dump the equivalent non-interactive
// command to a file.
// The command-line argument parser.
// The argument which should be used to request quiet output.
// The argument which should be used to request script-friendly
// output.
// The argument which should be used to request usage information.
// The argument which should be used to request verbose output.
// The argument which should be used to indicate the properties file.
// The argument which should be used to indicate that we will not look for
// properties file.
/**
* Creates a new dsconfig application instance.
*
* @param in
* The application input stream.
* @param out
* The application output stream.
* @param err
* The application error stream.
* @param factory
* The factory which this application instance should use
* for obtaining management contexts.
*/
INFO_CONFIGDS_TOOL_DESCRIPTION.get(), false);
}
/**
* Initializes core APIs for use when dsconfig will be run as a
* standalone application.
*
* @throws InitializationException
* If the core APIs could not be initialized.
*/
if (environmentInitialized == false) {
// Bootstrap definition classes.
// Switch off class name validation in client.
// Switch off attribute type name validation in client.
environmentInitialized = true;
}
}
/**
* {@inheritDoc}
*/
public boolean isAdvancedMode() {
return advancedModeArgument.isPresent();
}
/**
* {@inheritDoc}
*/
public boolean isInteractive() {
return !noPromptArgument.isPresent();
}
/**
* {@inheritDoc}
*/
public boolean isMenuDrivenMode() {
return !hasSubCommand;
}
/**
* {@inheritDoc}
*/
public boolean isQuiet() {
return quietArgument.isPresent();
}
/**
* {@inheritDoc}
*/
public boolean isScriptFriendly() {
return scriptFriendlyArgument.isPresent();
}
/**
* {@inheritDoc}
*/
public boolean isVerbose() {
return verboseArgument.isPresent();
}
// Displays the provided message followed by a help usage reference.
println();
}
/**
* Registers the global arguments with the argument parser.
*
* @throws ArgumentException
* If a global argument could not be registered.
*/
throws ArgumentException {
if (globalArgumentsInitialized == false) {
quietArgument = new BooleanArgument(
noPromptArgument = new BooleanArgument(
.get());
false, false, true, INFO_BATCH_FILE_PATH_PLACEHOLDER.get(),
OPTION_LONG_EQUIVALENT_COMMAND_FILE_PATH, false, false, true,
// Register the global arguments.
// Register any global arguments required by the management
// context factory.
globalArgumentsInitialized = true;
}
}
/**
* Registers the sub-commands with the argument parser. This method
* uses the administration framework introspection APIs to determine
* the overall structure of the command-line.
*
* @throws ArgumentException
* If a sub-command could not be created.
*/
if (handlerFactory == null) {
}
};
.getAllSubCommandHandlers()) {
// Add the sub-command to its groups.
}
}
}
// Register the usage arguments.
}
// Register the --help-all argument.
}
}
/**
* Parses the provided command-line arguments and makes the
* appropriate changes to the Directory Server configuration.
*
* @param args
* The command-line arguments provided to this program.
* @return The exit code from the configuration processing. A
* nonzero value indicates that there was some kind of
* problem during the configuration processing.
*/
// Register global arguments and sub-commands.
try {
} catch (ArgumentException e) {
return 1;
}
// Parse the command-line arguments provided to this program.
try {
} catch (ArgumentException ae) {
return 1;
}
// to do anything else.
if (parser.usageOrVersionDisplayed()) {
return 0;
}
// Check for conflicting arguments.
return 1;
}
.getLongIdentifier());
return 1;
}
.getLongIdentifier());
return 1;
}
return 1;
}
{
return 1;
}
// Checks the version - if upgrade required, the tool is unusable
try
{
}
catch (InitializationException e)
{
println(e.getMessageObject());
return 1;
}
// Check that we can write on the provided path where we write the
// equivalent non-interactive commands.
{
{
return 1;
}
else
{
if (f.isDirectory())
{
return 1;
}
}
}
// Make sure that management context's arguments are valid.
try {
} catch (ArgumentException e) {
println(e.getMessageObject());
return 1;
}
// Handle batch file if any
if (batchFileArgument.isPresent()) {
// don't need to do anything else
return 0;
}
int retCode = 0;
hasSubCommand = false;
if (isInteractive()) {
// Top-level interactive mode.
} else {
retCode = 1;
}
} else {
hasSubCommand = true;
// Retrieve the sub-command implementation and run it.
}
try {
// Close the Management context ==> an LDAP UNBIND is sent
} catch (Exception e) {
// Nothing to report in this case
}
return retCode;
}
// Run the top-level interactive console.
private int runInteractiveMode() {
// In interactive mode, redirect all output to stdout.
// Build menu structure.
Comparator<RelationDefinition<?, ?>> c =
new Comparator<RelationDefinition<?, ?>>() {
RelationDefinition<?, ?> rd2) {
}
};
}
}
for (ListSubCommandHandler lh :
}
}
}
// Main menu.
}
try {
// Force retrieval of management context.
} catch (ArgumentException e) {
return 1;
} catch (ClientException e) {
return 1;
}
try {
return 0;
} else {
}
} catch (CLIException e) {
return 1;
}
}
// Run the provided sub-command handler.
try {
if (isInteractive() &&
{
}
} else {
// User must have quit.
return 1;
}
} catch (ArgumentException e) {
println(e.getMessageObject());
return 1;
} catch (CLIException e) {
println(e.getMessageObject());
return 1;
} catch (ClientException e) {
if (cause instanceof ManagedObjectDecodingException) {
println();
println();
} else if (cause instanceof MissingMandatoryPropertiesException) {
println();
println();
} else if (cause instanceof OperationRejectedException) {
println();
displayOperationRejectedException(this, ore);
println();
} else {
// Just display the default message.
println(e.getMessageObject());
}
return 1;
} catch (Exception e) {
if (debugEnabled()) {
}
return 1;
}
}
/**
* Updates the command builder with the global options: script friendly,
* verbose, etc. for a given subcommand. It also adds systematically the
* no-prompt option.
* @param handler the subcommand handler.
*/
{
if (commandName == null)
{
commandName = "dsconfig";
}
{
}
if (verboseArgument.isPresent())
{
}
if (scriptFriendlyArgument.isPresent())
{
}
if (propertiesFileArgument.isPresent())
{
}
{
}
return commandBuilder;
}
/**
* Creates a command builder with the global options: script friendly,
* verbose, etc. for a given subcommand name. It also adds systematically the
* no-prompt option.
* @param subcommandName the subcommand name.
* @return the command builder that has been created with the specified
* subcommandName.
*/
{
if (commandName == null)
{
commandName = "dsconfig";
}
{
}
if (verboseArgument.isPresent())
{
}
if (scriptFriendlyArgument.isPresent())
{
}
if (propertiesFileArgument.isPresent())
{
}
{
}
return commandBuilder;
}
/**
* Prints the contents of a command builder. This method has been created
* since SetPropSubCommandHandler calls it. All the logic of DSConfig is on
* this method. It writes the content of the CommandBuilder to the standard
* output, or to a file depending on the options provided by the user.
* @param commandBuilder the command builder to be printed.
*/
{
{
println();
// We assume that the app we are running is this one.
}
{
try
{
if (!sessionStartTimePrinted)
{
sessionStartTimePrinted = true;
}
}
catch (IOException ioe)
{
}
}
}
/**
* Returns the message to be displayed in the file with the equivalent
* command-line with information about when the session started.
* @return the message to be displayed in the file with the equivalent
* command-line with information about when the session started.
*/
{
{
scriptName = "dsconfig";
}
new Date(sessionStartTime));
toString();
}
try {
// Build a list of initial arguments,
// removing the batch file option + its value
int batchFileArgIndex = -1;
break;
}
}
if (batchFileArgIndex != -1) {
// Remove both the batch file arg and its value
}
//
// Split the CLI string into arguments array
//
// Empty line or comment
continue;
}
// command split in several line support
// command is split into several lines
continue;
} else {
}
// string between quotes support
// "\ " support
// reset command
command = "";
}
// Append initial arguments to the file line
int exitCode =
if (exitCode != 0) {
}
printlnBatchProgress("");
}
} catch (IOException ex) {
}
}
// Replace spaces in quotes by "\ "
boolean inQuotes = false;
if (!inQuotes) {
// enter in a quoted string
inQuotes = true;
} else {
// end of a quoted string
inQuotes = false;
}
continue;
}
newLine += "\\ ";
} else {
}
}
return newLine;
}
}