/*
* 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 2011-2015 ForgeRock AS
*/
/**
* The class used to provide some CLI interface to display status.
* This class basically is in charge of parsing the data provided by the
* user in the command line.
*/
{
private boolean displayMustAuthenticateLegend;
private boolean displayMustStartLegend;
/** Prefix for log files. */
/** Suffix for log files. */
private boolean useInteractiveTrustManager;
/** The argument parser. */
/**
* Constructor for the status cli object.
*
* @param out
* 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.
*/
{
}
/**
* The main method for the status CLI tool.
*
* @param args The command-line arguments provided to this program.
*/
{
if(retCode != 0)
{
}
}
/**
* Parses the provided command-line arguments and uses that information to
* run the status tool.
*
* @param args the command-line arguments provided to this program.
*
* @return The return code.
*/
{
}
/**
* Parses the provided command-line arguments and uses that information to run
* the status tool.
*
* @param args
* The command-line arguments provided to this program.
* @param initializeServer
* Indicates whether to initialize the server.
* @param outStream
* The output stream to use for standard output, or {@code null}
* if standard output is not needed.
* @param errStream
* The output stream to use for standard error, or {@code null}
* if standard error is not needed.
* @param inStream
* The input stream to use for standard input.
* @return The return code.
*/
{
try {
} catch (Throwable t) {
t.printStackTrace();
}
if (retCode == 0)
{
}
return retCode;
}
/**
* Parses the provided command-line arguments and uses that information to run
* the status CLI.
*
* @param args
* The command-line arguments provided to this program.
* @return The return code of the process.
*/
try {
} catch (ArgumentException ae) {
}
try
{
}
catch (ConfigException ce)
{
// Ignore.
}
// Validate user provided data
try {
} catch (ArgumentException ae) {
argParser.displayMessageAndUsageReference(getErrStream(), ERR_ERROR_PARSING_ARGS.get(ae.getMessage()));
}
// If we should just display usage or version information,
// then print it and exit.
if (argParser.usageOrVersionDisplayed()) {
}
// Checks the version - if upgrade required, the tool is unusable
try
{
}
catch (InitializationException e)
{
println(e.getMessageObject());
return 1;
}
return v;
}
{
// This is done because we do not need to ask the user about these
// parameters. We force their presence in the
// LDAPConnectionConsoleInteraction, this done, it will not prompt
// the user for them.
try
{
}
catch (Throwable t)
{
}
// We already know if SSL or StartTLS can be used. If we cannot
// use them we will not propose them in the connection parameters
// and if none of them can be used we will just not ask for the
// protocol to be used.
final LDAPConnectionConsoleInteraction ci =
try
{
}
catch (ArgumentException e)
{
}
try
{
if (argParser.isInteractive())
{
}
else
{
}
{
useInteractiveTrustManager = true;
}
} catch (ClientException e) {
println(e.getMessageObject());
} finally {
}
{
try {
}
} catch (NamingException ne) {
// This should not happen but this is useful information to
// diagnose the error.
println();
} catch (ConfigReadException cre) {
// This should not happen but this is useful information to
// diagnose the error.
println();
} finally {
}
} else {
// The user did not provide authentication: just display the
// information we can get reading the config file.
}
} else {
}
}
{
{
}
boolean first = true;
while (period > 0)
{
if (!first)
{
}
if (timeToSleep > 0)
{
}
println();
println();
first = false;
}
}
{
{
};
int labelWidth = 0;
if (!isScriptFriendly())
{
{
}
println();
}
if (!isScriptFriendly())
{
println();
}
if (!isScriptFriendly())
{
}
if (!sameInstallAndInstance)
{
}
if (!isScriptFriendly())
{
println();
}
if (!isScriptFriendly())
{
println();
}
if (!isScriptFriendly())
{
{
println();
}
else if (displayMustAuthenticateLegend)
{
println();
}
}
println();
}
/**
* Writes the status contents displaying with what is specified in the
* provided ServerDescriptor object.
*
* @param desc
* The ServerStatusDescriptor object.
*/
{
}
{
{
case STARTED:
return INFO_SERVER_STARTED_LABEL.get();
case STOPPED:
return INFO_SERVER_STOPPED_LABEL.get();
case STARTING:
return INFO_SERVER_STARTING_LABEL.get();
case STOPPING:
return INFO_SERVER_STOPPING_LABEL.get();
case NOT_CONNECTED_TO_REMOTE:
case UNKNOWN:
return INFO_SERVER_UNKNOWN_STATUS_LABEL.get();
default:
}
}
/**
* Writes the current connection contents displaying with what is specified in
* the provided ServerDescriptor object.
*
* @param desc
* The ServerDescriptor object.
*/
{
}
{
{
if (nConn >= 0)
{
}
{
}
else
{
return getNotAvailableText();
}
}
return getNotAvailableBecauseServerIsDownText();
}
/**
* Writes the host name contents.
*
* @param desc
* The ServerDescriptor object.
* @param maxLabelWidth
* The maximum label width of the left label.
*/
{
}
/**
* Writes the administrative user contents displaying with what is specified
* in the provided ServerStatusDescriptor object.
*
* @param desc
* The ServerStatusDescriptor object.
* @param maxLabelWidth
* The maximum label width of the left label.
*/
{
if (!administrators.isEmpty())
{
{
}
}
else
{
}
}
{
{
}
return getNotAvailableText();
}
/**
* Writes the install path contents displaying with what is specified in the
* provided ServerDescriptor object.
*
* @param desc
* The ServerDescriptor object.
* @param maxLabelWidth
* The maximum label width of the left label.
*/
{
}
/**
* Writes the instance path contents displaying with what is specified in the
* provided ServerDescriptor object.
*
* @param desc
* The ServerDescriptor object.
* @param maxLabelWidth
* The maximum label width of the left label.
*/
{
}
/**
* Updates the server version contents displaying with what is specified in
* the provided ServerDescriptor object. This method must be called from the
* event thread.
*
* @param desc
* The ServerDescriptor object.
*/
{
}
/**
* Updates the java version contents displaying with what is specified in the
* provided ServerDescriptor object. This method must be called from the event
* thread.
*
* @param desc
* The ServerDescriptor object.
* @param maxLabelWidth
* The maximum label width of the left label.
*/
{
}
{
{
{
}
return desc.getJavaVersion();
}
return getNotAvailableBecauseServerIsDownText();
}
/**
* Updates the admin connector contents displaying with what is specified in
* the provided ServerDescriptor object. This method must be called from the
* event thread.
*
* @param desc
* The ServerDescriptor object.
* @param maxLabelWidth
* The maximum label width of the left label.
*/
{
}
/**
* Writes the listeners contents displaying with what is specified in the
* provided ServerDescriptor object.
*
* @param desc
* The ServerDescriptor object.
*/
{
if (!isScriptFriendly())
{
}
if (allHandlers.isEmpty())
{
{
if (!desc.isAuthenticated())
{
}
else
{
}
}
else
{
}
}
else
{
new ConnectionHandlerTableModel(false);
}
}
/**
* Writes the base DN contents displaying with what is specified in the
* provided ServerDescriptor object.
*
* @param desc
* The ServerDescriptor object.
*/
{
if (!isScriptFriendly())
{
}
{
if (!backend.isConfigBackend())
{
}
}
{
{
if (!desc.isAuthenticated())
{
}
else
{
}
}
else
{
}
}
else
{
}
}
/**
* Writes the error label contents displaying with what is specified in the
* provided ServerDescriptor object.
*
* @param desc
* The ServerDescriptor object.
*/
{
{
{
println();
}
}
}
/**
* Returns the not available text explaining that the data is not available
* because the server is down.
*
* @return the text.
*/
{
displayMustStartLegend = true;
}
/**
* Returns the not available text explaining that the data is not available
* because authentication is required.
*
* @return the text.
*/
{
displayMustAuthenticateLegend = true;
}
/**
* Returns the not available text explaining that the data is not available.
*
* @return the text.
*/
{
}
/**
* Writes the contents of the provided table model simulating a table layout
* using text.
*
* @param tableModel
* The connection handler table model.
* @param desc
* The Server Status descriptor.
*/
private void writeConnectionHandlersTableModel(
{
if (isScriptFriendly())
{
{
// Get the host name, it can be multivalued.
{
{
if (j == 0)
{
// It is the hostName
}
else
{
}
}
}
}
}
else
{
{
}
{
// Get the host name, it can be multivalued.
{
{
if (j == 0)
{
// It is the hostName
}
else
{
}
}
}
}
}
}
{
{
}
return v.split("<br>");
}
{
if (v != null)
{
if (v instanceof String)
{
return (String) v;
}
else if (v instanceof Integer)
{
if (nEntries >= 0)
{
}
{
}
else
{
return getNotAvailableText();
}
}
else
{
throw new IllegalStateException("Unknown object type: "+v);
}
}
return getNotAvailableText();
}
/**
* Writes the contents of the provided base DN table model. Every base DN is
* written in a block containing pairs of labels and values.
*
* @param tableModel
* The TableModel.
* @param desc
* The Server Status descriptor.
*/
{
int labelWidth = 0;
int labelWidthWithoutReplicated = 0;
{
if (i != 4 && i != 5)
{
}
}
{
if (isScriptFriendly())
{
}
else if (i > 0)
{
println();
}
{
boolean doWrite = true;
boolean isReplicated =
if (j == 4 || j == 5)
{
// If the suffix is not replicated we do not have to display these lines
}
if (doWrite)
{
}
}
}
}
{
if (v != null)
{
if (v == BaseDNTableModel.NOT_AVAILABLE_SERVER_DOWN)
{
return getNotAvailableBecauseServerIsDownText();
}
else if (v == BaseDNTableModel.NOT_AVAILABLE_AUTHENTICATION_REQUIRED)
{
}
else if (v == BaseDNTableModel.NOT_AVAILABLE)
{
}
else if (v instanceof String)
{
return (String) v;
}
else if (v instanceof LocalizableMessage)
{
return ((LocalizableMessage) v).toString();
}
else if (v instanceof Integer)
{
if (nEntries >= 0)
{
}
}
else
{
throw new IllegalStateException("Unknown object type: " + v);
}
}
return "";
}
{
if (!isRunning)
{
return getNotAvailableBecauseServerIsDownText();
}
{
}
return getNotAvailableText();
}
private void writeLabelValue(final LocalizableMessage label, final String value, final int maxLabelWidth)
{
for (int i = 0; i<extra; i++)
{
}
}
{
{
for (int i=0; i<extra; i++)
{
}
}
return text;
}
/**
* Returns the trust manager to be used by this application.
*
* @return the trust manager to be used by this application.
*/
{
{
return interactiveTrustManager;
}
return argParser.getTrustManager();
}
/** {@inheritDoc} */
public boolean isAdvancedMode()
{
return false;
}
/** {@inheritDoc} */
public boolean isInteractive() {
return argParser.isInteractive();
}
/** {@inheritDoc} */
public boolean isMenuDrivenMode() {
return true;
}
/** {@inheritDoc} */
public boolean isQuiet() {
return false;
}
/** {@inheritDoc} */
public boolean isScriptFriendly() {
return argParser.isScriptFriendly();
}
/** {@inheritDoc} */
public boolean isVerbose() {
return true;
}
/** FIXME Common code with DSConfigand tools*. This method needs to be moved. */
{
// Interact with the user though the console to get
// LDAP connection information
// This connection should always be secure. useSSL = true.
while (true)
{
try
{
break;
}
catch (LdapException e)
{
{
if (trustManager instanceof ApplicationTrustManager)
{ // FIXME use PromptingTrustManager
{
// If the certificate is trusted, update the trust manager.
// Try to connect again.
continue;
}
}
}
if (e.getCause() instanceof SSLException)
{
message);
}
if (e.getCause() instanceof AuthorizationException)
{
}
else if (e.getCause() instanceof AuthenticationException
{
// Status Cli must not fail when un-authenticated.
return null;
}
}
catch (GeneralSecurityException e)
{
}
finally
{
}
}
}
}