From 231d7b6cf5fde6c921812ad52877832773392e98 Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Thu, 06 Mar 2014 14:37:45 +0000
Subject: [PATCH] Checkpoint OPENDJ-1343 Migrate dsconfig - Removed the PasswordReader class as now we only support >JDK6 - Replaced calls to PasswordReader.readPassword to ConsoleApplication.readPassword() - Minor code cleanup / removed unused on the SecureConnectionCli class.
---
/dev/null | 264 ----------------------
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPDelete.java | 6
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java | 6
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java | 11
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPCompare.java | 6
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPPasswordModify.java | 6
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java | 94 ++-----
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java | 257 ---------------------
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPSearch.java | 6
opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java | 13
10 files changed, 71 insertions(+), 598 deletions(-)
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
index ccd64f4..dca3b9e 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
@@ -27,21 +27,15 @@
package org.opends.server.admin.client.cli;
import static com.forgerock.opendj.cli.ArgumentConstants.OPTION_LONG_ADMIN_UID;
-import static com.forgerock.opendj.cli.CliMessages.INFO_DESCRIPTION_ADMIN_PORT;
+import static com.forgerock.opendj.cli.CliMessages.*;
import static com.forgerock.opendj.cli.ReturnCode.CONFLICTING_ARGS;
import static com.forgerock.opendj.cli.ReturnCode.SUCCESS;
import static com.forgerock.opendj.cli.Utils.LINE_SEPARATOR;
-import static org.opends.server.util.ServerConstants.MAX_LINE_WIDTH;
-import static org.opends.server.util.StaticUtils.close;
-import static org.opends.server.util.StaticUtils.wrapText;
-import static org.opends.messages.AdminToolMessages.*;
-import static org.opends.messages.ToolMessages.*;
+import static org.forgerock.util.Utils.closeSilently;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import java.io.OutputStream;
-import java.io.PrintStream;
import java.net.InetAddress;
import java.security.KeyStore;
import java.security.KeyStoreException;
@@ -50,15 +44,11 @@
import java.util.ArrayList;
import java.util.LinkedHashSet;
-import javax.net.ssl.KeyManager;
-
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
-import org.opends.admin.ads.util.ApplicationKeyManager;
import org.opends.admin.ads.util.ApplicationTrustManager;
import org.opends.admin.ads.util.ConnectionUtils;
-import org.opends.quicksetup.Constants;
import org.opends.server.admin.AdministrationConnector;
import org.opends.server.admin.server.ServerManagementContext;
import org.opends.server.admin.std.server.AdministrationConnectorCfg;
@@ -67,12 +57,11 @@
import org.opends.server.admin.std.server.TrustManagerProviderCfg;
import org.opends.server.config.ConfigException;
import org.opends.server.core.DirectoryServer;
-import org.opends.server.util.PasswordReader;
-import org.opends.server.util.SelectableCertificateKeyManager;
import com.forgerock.opendj.cli.Argument;
import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.cli.BooleanArgument;
+import com.forgerock.opendj.cli.CliConstants;
import com.forgerock.opendj.cli.CommonArguments;
import com.forgerock.opendj.cli.FileBasedArgument;
import com.forgerock.opendj.cli.IntegerArgument;
@@ -265,145 +254,6 @@
}
/**
- * Get the password which has to be used for the command.
- *
- * @param dn
- * The user DN for which to password could be asked.
- * @param out
- * The input stream to used if we have to prompt to the
- * user.
- * @param err
- * The error stream to used if we have to prompt to the
- * user.
- * @param clearArg
- * The password StringArgument argument.
- * @param fileArg
- * The password FileBased argument.
- * @return The password stored into the specified file on by the
- * command line argument, or prompts it if not specified.
- */
- public String getBindPassword(String dn,
- OutputStream out, OutputStream err, StringArgument clearArg,
- FileBasedArgument fileArg)
- {
- if (clearArg.isPresent())
- {
- String bindPasswordValue = clearArg.getValue();
- if(bindPasswordValue != null && "-".equals(bindPasswordValue))
- {
- // read the password from the stdin.
- try
- {
- out.write(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString().getBytes());
- out.flush();
- char[] pwChars = PasswordReader.readPassword();
- bindPasswordValue = new String(pwChars);
- } catch(Exception ex)
- {
- logger.traceException(ex);
- try
- {
- err.write(wrapText(ex.getMessage(), MAX_LINE_WIDTH).getBytes());
- err.write(LINE_SEPARATOR.getBytes());
- }
- catch (IOException e)
- {
- }
- return null;
- }
- }
- return bindPasswordValue;
- }
- else
- if (fileArg.isPresent())
- {
- return fileArg.getValue();
- }
- else
- {
- // read the password from the stdin.
- try
- {
- out.write(
- INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString().getBytes());
- out.flush();
- char[] pwChars = PasswordReader.readPassword();
- return new String(pwChars);
- }
- catch (Exception ex)
- {
- logger.traceException(ex);
- try
- {
- err.write(wrapText(ex.getMessage(), MAX_LINE_WIDTH).getBytes());
- err.write(LINE_SEPARATOR.getBytes());
- }
- catch (IOException e)
- {
- }
- return null;
- }
- }
-
- }
-
- /**
- * Get the password which has to be used for the command.
- *
- * @param dn
- * The user DN for which to password could be asked.
- * @param out
- * The input stream to used if we have to prompt to the
- * user.
- * @param err
- * The error stream to used if we have to prompt to the
- * user.
- * @return The password stored into the specified file on by the
- * command line argument, or prompts it if not specified.
- */
- public String getBindPassword(String dn, OutputStream out, OutputStream err)
- {
- return getBindPassword(dn, out, err, bindPasswordArg, bindPasswordFileArg);
- }
-
- /**
- * Get the password which has to be used for the command without prompting
- * the user. If no password was specified, return null.
- *
- * @param clearArg
- * The password StringArgument argument.
- * @param fileArg
- * The password FileBased argument.
- * @return The password stored into the specified file on by the
- * command line argument, or null it if not specified.
- */
- public String getBindPassword(StringArgument clearArg,
- FileBasedArgument fileArg)
- {
- if (clearArg.isPresent())
- {
- return clearArg.getValue();
- }
- else if (fileArg.isPresent())
- {
- return fileArg.getValue();
- }
- return null;
- }
-
- /**
- * Get the password which has to be used for the command without prompting
- * the user. If no password was specified, return null.
- *
- * @return The password stored into the specified file on by the
- * command line argument, or null it if not specified.
- */
- public String getBindPassword()
- {
- return getBindPassword(bindPasswordArg, bindPasswordFileArg);
- }
-
- /**
* Initialize Global option.
*
* @throws ArgumentException
@@ -453,7 +303,7 @@
adminUidArg = new StringArgument("adminUID", 'I',
OPTION_LONG_ADMIN_UID, false, false, true,
INFO_ADMINUID_PLACEHOLDER.get(),
- Constants.GLOBAL_ADMIN_UID, null,
+ CliConstants.GLOBAL_ADMIN_UID, null,
INFO_DESCRIPTION_ADMIN_UID.get());
adminUidArg.setPropertyName(OPTION_LONG_ADMIN_UID);
adminUidArg.setHidden(true);
@@ -626,23 +476,6 @@
return SUCCESS.get();
}
- /**
- * Indication if provided global options are validate.
- *
- * @param err the stream to be used to print error message.
- * @return return code.
- */
- public int validateGlobalOptions(PrintStream err)
- {
- LocalizableMessageBuilder buf = new LocalizableMessageBuilder();
- int returnValue = validateGlobalOptions(buf);
- if (buf.length() > 0)
- {
- err.println(wrapText(buf.toString(), MAX_LINE_WIDTH));
- }
- return returnValue;
- }
-
/**
* Indicate if the SSL mode is required.
@@ -756,7 +589,7 @@
}
finally
{
- close(fos);
+ closeSilently(fos);
}
}
trustManager = new ApplicationTrustManager(truststore);
@@ -764,87 +597,7 @@
return trustManager;
}
- /**
- * Handle KeyStore.
- *
- * @return The keyStore manager to be used for the command.
- */
- public KeyManager getKeyManager()
- {
- KeyStore keyStore = null;
- String keyStorePasswordStringValue = null;
- char[] keyStorePasswordValue = null;
- if (keyStorePathArg.isPresent())
- {
- FileInputStream fos = null;
- try
- {
- fos = new FileInputStream(keyStorePathArg.getValue());
- if (keyStorePasswordArg.isPresent())
- {
- keyStorePasswordStringValue = keyStorePasswordArg.getValue();
- }
- else if (keyStorePasswordFileArg.isPresent())
- {
- keyStorePasswordStringValue = keyStorePasswordFileArg.getValue();
- }
- if (keyStorePasswordStringValue != null)
- {
- keyStorePasswordValue = keyStorePasswordStringValue.toCharArray();
- }
- keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
- keyStore.load(fos,keyStorePasswordValue);
- }
- catch (KeyStoreException e)
- {
- // Nothing to do: if this occurs we will systematically refuse
- // the certificates. Maybe we should avoid this and be strict, but
- // we are in a best effort mode.
- logger.warn(LocalizableMessage.raw("Error with the keystore"), e);
- }
- catch (NoSuchAlgorithmException e)
- {
- // Nothing to do: if this occurs we will systematically refuse
- // the certificates. Maybe we should avoid this and be strict, but
- // we are in a best effort mode.
- logger.warn(LocalizableMessage.raw("Error with the keystore"), e);
- }
- catch (CertificateException e)
- {
- // Nothing to do: if this occurs we will systematically refuse
- // the certificates. Maybe we should avoid this and be strict, but
- // we are in a best effort mode.
- logger.warn(LocalizableMessage.raw("Error with the keystore"), e);
- }
- catch (IOException e)
- {
- // Nothing to do: if this occurs we will systematically refuse
- // the certificates. Maybe we should avoid this and be strict, but
- // we are in a best effort mode.
- logger.warn(LocalizableMessage.raw("Error with the keystore"), e);
- }
- finally
- {
- close(fos);
- }
-
- char[] password = null;
- if (keyStorePasswordStringValue != null)
- {
- password = keyStorePasswordStringValue.toCharArray();
- }
- ApplicationKeyManager akm = new ApplicationKeyManager(keyStore,password);
- if (certNicknameArg.isPresent())
- {
- return new SelectableCertificateKeyManager(akm, certNicknameArg
- .getValue());
- }
- return akm;
- }
- return null;
-
- }
/**
* Returns <CODE>true</CODE> if we can read on the provided path and
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
index e47acfa..822f17d 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/admin/client/cli/SecureConnectionCliParser.java
@@ -27,10 +27,11 @@
package org.opends.server.admin.client.cli;
-import static org.opends.server.util.ServerConstants.EOL;
-import static org.opends.server.util.ServerConstants.MAX_LINE_WIDTH;
+import static com.forgerock.opendj.cli.CliMessages.*;
+import static com.forgerock.opendj.cli.Utils.LINE_SEPARATOR;
+import static com.forgerock.opendj.cli.Utils.MAX_LINE_WIDTH;
import static org.opends.server.util.StaticUtils.wrapText;
-import static org.opends.messages.ToolMessages.*;
+import static com.forgerock.opendj.cli.ReturnCode.CONFLICTING_ARGS;
import java.io.IOException;
import java.io.OutputStream;
@@ -38,19 +39,18 @@
import java.util.Collection;
import java.util.LinkedHashSet;
-import javax.net.ssl.KeyManager;
-
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.opends.admin.ads.util.ApplicationTrustManager;
-import org.opends.server.util.PasswordReader;
import com.forgerock.opendj.cli.Argument;
import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.cli.ArgumentGroup;
import com.forgerock.opendj.cli.BooleanArgument;
+import com.forgerock.opendj.cli.ClientException;
import com.forgerock.opendj.cli.CommonArguments;
+import com.forgerock.opendj.cli.ConsoleApplication;
import com.forgerock.opendj.cli.FileBasedArgument;
import com.forgerock.opendj.cli.StringArgument;
import com.forgerock.opendj.cli.SubCommandArgumentParser;
@@ -146,59 +146,32 @@
* @param err
* The error stream to used if we have to prompt to the
* user.
- * @param clearArg
+ * @param pwdArg
* The password StringArgument argument.
* @param fileArg
* The password FileBased argument.
* @return The password stored into the specified file on by the
* command line argument, or prompts it if not specified.
*/
- protected String getBindPassword(String dn,
- OutputStream out, OutputStream err, StringArgument clearArg,
- FileBasedArgument fileArg)
+ protected String getBindPassword(String dn, OutputStream out,
+ OutputStream err, StringArgument pwdArg, FileBasedArgument fileArg)
{
- if (clearArg.isPresent())
- {
- String bindPasswordValue = clearArg.getValue();
- if(bindPasswordValue != null && "-".equals(bindPasswordValue))
- {
- // read the password from the stdin.
- try
- {
- out.write(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString().getBytes());
- out.flush();
- char[] pwChars = PasswordReader.readPassword();
- bindPasswordValue = new String(pwChars);
- } catch(Exception ex)
- {
- logger.traceException(ex);
- try
- {
- err.write(wrapText(ex.getMessage(), MAX_LINE_WIDTH).getBytes());
- err.write(EOL.getBytes());
- }
- catch (IOException e)
- {
- }
- return null;
- }
- }
- return bindPasswordValue;
- }
- else
+ String bindPasswordValue = null;
if (fileArg.isPresent())
{
return fileArg.getValue();
}
- else
+ else if (pwdArg.isPresent())
{
- // read the password from the stdin.
+ bindPasswordValue = pwdArg.getValue();
+ }
+ if ((bindPasswordValue != null && "-".equals(bindPasswordValue))
+ || bindPasswordValue == null)
+ {
+ // Read the password from the STDin.
try
{
- out.write(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString().getBytes());
- out.flush();
- char[] pwChars = PasswordReader.readPassword();
- return new String(pwChars);
+ return readPassword(dn, out);
}
catch (Exception ex)
{
@@ -206,19 +179,28 @@
try
{
err.write(wrapText(ex.getMessage(), MAX_LINE_WIDTH).getBytes());
- err.write(EOL.getBytes());
+ err.write(LINE_SEPARATOR.getBytes());
}
catch (IOException e)
{
+ // Nothing to do.
}
- return null;
}
}
+ return bindPasswordValue;
+ }
+ private String readPassword(String dn, OutputStream out) throws IOException,
+ ClientException
+ {
+ out.write(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn).toString().getBytes());
+ out.flush();
+ char[] pwChars = ConsoleApplication.readPassword();
+ return new String(pwChars);
}
/**
- * Get the password which has to be used for the command.
+ * Gets the password which has to be used for the command.
*
* @param dn
* The user DN for which to password could be asked.
@@ -238,7 +220,7 @@
}
/**
- * Get the password which has to be used for the command without prompting
+ * Gets the password which has to be used for the command without prompting
* the user. If no password was specified, return null.
*
* @return The password stored into the specified file on by the
@@ -366,10 +348,10 @@
.getLongIdentifier());
if (buf.length() > 0)
{
- buf.append(EOL);
+ buf.append(LINE_SEPARATOR);
}
buf.append(message);
- ret = 1;
+ return CONFLICTING_ARGS.get();
}
return ret;
@@ -433,16 +415,6 @@
}
/**
- * Handle KeyStore.
- *
- * @return The keyStore manager to be used for the command.
- */
- public KeyManager getKeyManager()
- {
- return secureArgsList.getKeyManager() ;
- }
-
- /**
* Returns the timeout to be used to connect in milliseconds. The method
* must be called after parsing the arguments.
* @return the timeout to be used to connect in milliseconds. Returns
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java
index 7c71500..2ac18a6 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPAuthenticationHandler.java
@@ -55,6 +55,7 @@
import javax.security.sasl.SaslClient;
import com.forgerock.opendj.cli.ClientException;
+import com.forgerock.opendj.cli.ConsoleApplication;
import com.forgerock.opendj.cli.ReturnCode;
import org.forgerock.i18n.LocalizableMessage;
@@ -69,7 +70,6 @@
import org.opends.server.types.LDAPException;
import org.opends.server.types.Control;
import org.opends.server.util.Base64;
-import org.opends.server.util.PasswordReader;
import static org.opends.messages.ToolMessages.*;
import static org.opends.server.protocols.ldap.LDAPConstants.*;
@@ -3582,7 +3582,14 @@
if (gssapiAuthPW == null)
{
System.out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(gssapiAuthID));
- gssapiAuthPW = PasswordReader.readPassword();
+ try
+ {
+ gssapiAuthPW = ConsoleApplication.readPassword();
+ }
+ catch (ClientException e)
+ {
+ throw new UnsupportedCallbackException(cb, e.getLocalizedMessage());
+ }
}
((PasswordCallback) cb).setPassword(gssapiAuthPW);
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPCompare.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPCompare.java
index 1407982..f95afa2 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPCompare.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPCompare.java
@@ -50,12 +50,12 @@
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.util.Base64;
import org.opends.server.util.EmbeddedUtils;
-import org.opends.server.util.PasswordReader;
import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.cli.ArgumentParser;
import com.forgerock.opendj.cli.BooleanArgument;
import com.forgerock.opendj.cli.CommonArguments;
+import com.forgerock.opendj.cli.ConsoleApplication;
import com.forgerock.opendj.cli.FileBasedArgument;
import com.forgerock.opendj.cli.IntegerArgument;
import com.forgerock.opendj.cli.StringArgument;
@@ -812,7 +812,7 @@
try
{
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDNValue));
- char[] pwChars = PasswordReader.readPassword();
+ char[] pwChars = ConsoleApplication.readPassword();
bindPasswordValue = new String(pwChars);
//As per rfc 4513(section-5.1.2) a client should avoid sending
//an empty password to the server.
@@ -822,7 +822,7 @@
INFO_LDAPAUTH_NON_EMPTY_PASSWORD.get(),
MAX_LINE_WIDTH));
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDNValue));
- pwChars = PasswordReader.readPassword();
+ pwChars = ConsoleApplication.readPassword();
}
bindPasswordValue = new String(pwChars);
} catch(Exception ex)
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPDelete.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPDelete.java
index 6934d12..d768e6b 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPDelete.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPDelete.java
@@ -47,12 +47,12 @@
import org.opends.server.types.*;
import org.forgerock.opendj.ldap.ByteString;
import org.opends.server.util.EmbeddedUtils;
-import org.opends.server.util.PasswordReader;
import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.cli.ArgumentParser;
import com.forgerock.opendj.cli.BooleanArgument;
import com.forgerock.opendj.cli.CommonArguments;
+import com.forgerock.opendj.cli.ConsoleApplication;
import com.forgerock.opendj.cli.FileBasedArgument;
import com.forgerock.opendj.cli.IntegerArgument;
import com.forgerock.opendj.cli.StringArgument;
@@ -625,7 +625,7 @@
try
{
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDNValue));
- char[] pwChars = PasswordReader.readPassword();
+ char[] pwChars = ConsoleApplication.readPassword();
bindPasswordValue = new String(pwChars);
//As per rfc 4513(section-5.1.2) a client should avoid sending
//an empty password to the server.
@@ -635,7 +635,7 @@
INFO_LDAPAUTH_NON_EMPTY_PASSWORD.get(),
MAX_LINE_WIDTH));
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDNValue));
- pwChars = PasswordReader.readPassword();
+ pwChars = ConsoleApplication.readPassword();
}
bindPasswordValue = new String(pwChars);
} catch(Exception ex)
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java
index 184f80e..4bbbaef 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPModify.java
@@ -67,12 +67,12 @@
import org.opends.server.util.LDIFReader;
import org.opends.server.util.ModifyChangeRecordEntry;
import org.opends.server.util.ModifyDNChangeRecordEntry;
-import org.opends.server.util.PasswordReader;
import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.cli.ArgumentParser;
import com.forgerock.opendj.cli.BooleanArgument;
import com.forgerock.opendj.cli.CommonArguments;
+import com.forgerock.opendj.cli.ConsoleApplication;
import com.forgerock.opendj.cli.FileBasedArgument;
import com.forgerock.opendj.cli.IntegerArgument;
import com.forgerock.opendj.cli.StringArgument;
@@ -953,7 +953,7 @@
try
{
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDNValue));
- char[] pwChars = PasswordReader.readPassword();
+ char[] pwChars = ConsoleApplication.readPassword();
bindPasswordValue = new String(pwChars);
//As per rfc 4513(section-5.1.2) a client should avoid sending
//an empty password to the server.
@@ -963,7 +963,7 @@
INFO_LDAPAUTH_NON_EMPTY_PASSWORD.get(),
MAX_LINE_WIDTH));
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDNValue));
- pwChars = PasswordReader.readPassword();
+ pwChars = ConsoleApplication.readPassword();
}
bindPasswordValue = new String(pwChars);
} catch(Exception ex)
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPPasswordModify.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPPasswordModify.java
index b518c26..b0ebf13 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPPasswordModify.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPPasswordModify.java
@@ -48,12 +48,12 @@
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.util.EmbeddedUtils;
-import org.opends.server.util.PasswordReader;
import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.cli.ArgumentParser;
import com.forgerock.opendj.cli.BooleanArgument;
import com.forgerock.opendj.cli.CommonArguments;
+import com.forgerock.opendj.cli.ConsoleApplication;
import com.forgerock.opendj.cli.FileBasedArgument;
import com.forgerock.opendj.cli.IntegerArgument;
import com.forgerock.opendj.cli.StringArgument;
@@ -647,7 +647,7 @@
try
{
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn));
- char[] pwChars = PasswordReader.readPassword();
+ char[] pwChars = ConsoleApplication.readPassword();
//As per rfc 4513(section-5.1.2) a client should avoid sending
//an empty password to the server.
while(pwChars.length==0)
@@ -656,7 +656,7 @@
INFO_LDAPAUTH_NON_EMPTY_PASSWORD.get(),
MAX_LINE_WIDTH));
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(dn));
- pwChars = PasswordReader.readPassword();
+ pwChars = ConsoleApplication.readPassword();
}
pw = new String(pwChars);
} catch(Exception ex)
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPSearch.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPSearch.java
index bb2df06..59ccc5b 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPSearch.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/tools/LDAPSearch.java
@@ -44,12 +44,12 @@
import org.opends.server.types.*;
import org.opends.server.util.Base64;
import org.opends.server.util.EmbeddedUtils;
-import org.opends.server.util.PasswordReader;
import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.cli.ArgumentParser;
import com.forgerock.opendj.cli.BooleanArgument;
import com.forgerock.opendj.cli.CommonArguments;
+import com.forgerock.opendj.cli.ConsoleApplication;
import com.forgerock.opendj.cli.FileBasedArgument;
import com.forgerock.opendj.cli.IntegerArgument;
import com.forgerock.opendj.cli.MultiChoiceArgument;
@@ -1208,7 +1208,7 @@
try
{
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDNValue));
- char[] pwChars = PasswordReader.readPassword();
+ char[] pwChars = ConsoleApplication.readPassword();
bindPasswordValue = new String(pwChars);
//As per rfc 4513(section-5.1.2) a client should avoid sending
//an empty password to the server.
@@ -1218,7 +1218,7 @@
INFO_LDAPAUTH_NON_EMPTY_PASSWORD.get(),
MAX_LINE_WIDTH));
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDNValue));
- pwChars = PasswordReader.readPassword();
+ pwChars = ConsoleApplication.readPassword();
}
bindPasswordValue = new String(pwChars);
} catch(Exception ex)
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/PasswordReader.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/PasswordReader.java
deleted file mode 100644
index 7f1af2f..0000000
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/PasswordReader.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * 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
- * or http://forgerock.org/license/CDDLv1.0.html.
- * 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 2006-2008 Sun Microsystems, Inc.
- * Portions copyright 2013 ForgeRock AS
- */
-package org.opends.server.util;
-
-import java.util.Arrays;
-
-import org.opends.server.api.DirectoryThread;
-
-/**
- * This class provides a means of interactively reading a password from the
- * command-line without echoing it to the console. If it is running on a Java 6
- * or higher VM, then it will use the System.console() method. If it is running
- * on Java 5, then it will use an ugly hack in which one thread will be used to
- * repeatedly send backspace characters to the console while another reads the
- * password. Reflection is used to determine whether the Java 6 method is
- * available and to invoke it if it is so that the code will still compile
- * cleanly on Java 5 systems.
- */
-@org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
- mayInstantiate=false,
- mayExtend=false,
- mayInvoke=true)
-public final class PasswordReader
- extends DirectoryThread
-{
- // Indicates whether the backspace thread should keep looping, sending
- // backspace characters to the console.
- private volatile boolean keepLooping;
-
-
-
- /**
- * Creates a new instance of this password reader. A new instance should only
- * be created from within this class.
- */
- private PasswordReader()
- {
- super("Password Reader Thread");
-
- // No implementation is required. However, this constructor is private to
- // help prevent it being used for external purposes.
- }
-
-
-
- /**
- * Operates in a loop, sending backspace characters to the console to attempt
- * to prevent exposing what the user entered. It sets the priority to the
- * maximum allowed value to reduce the chance of one or more characters being
- * displayed temporarily before they can be erased.
- */
- @org.opends.server.types.PublicAPI(
- stability=org.opends.server.types.StabilityLevel.PRIVATE,
- mayInstantiate=false,
- mayExtend=false,
- mayInvoke=false)
- @Override
- public void run()
- {
- Thread currentThread = Thread.currentThread();
- int initialPriority = currentThread.getPriority();
-
- try
- {
- try
- {
- currentThread.setPriority(Thread.MAX_PRIORITY);
- } catch (Exception e) {}
-
- keepLooping = true;
- while (keepLooping)
- {
- System.out.print("\u0008 ");
-
- try
- {
- Thread.sleep(1);
- }
- catch (InterruptedException ie)
- {
- currentThread.interrupt();
- return;
- }
- }
- }
- finally
- {
- try
- {
- currentThread.setPriority(initialPriority);
- } catch (Exception e) {}
- }
- }
-
-
-
- /**
- * Indicates that the backspace thread should stop looping as the complete
- * password has been entered.
- */
- private void stopLooping()
- {
- keepLooping = false;
- }
-
-
-
- /**
- * Reads a password from the console without echoing it to the client.
- *
- * @return The password as an array of characters.
- */
- public static char[] readPassword()
- {
- try
- {
- char[] password = System.console().readPassword();
- if (password != null)
- {
- return password;
- }
- }
- catch (Exception e)
- {
- // This must mean that we're running on a JVM that doesn't have the
- // System.console() method, or that the call to Console.readPassword()
- // isn't working. Fall back to using backspaces.
- return readPasswordUsingBackspaces();
- }
-
-
- // If we've gotten here, then the System.console() method must not exist.
- // Fall back on using backspaces.
- return readPasswordUsingBackspaces();
- }
-
-
-
- /**
- * Attempts to read a password from the console by repeatedly sending
- * backspace characters to mask whatever the user may have entered. This will
- * be used if the <CODE>java.io.Console</CODE> class is not available.
- *
- * @return The password read from the console.
- */
- private static char[] readPasswordUsingBackspaces()
- {
- char[] pwChars;
- char[] pwBuffer = new char[100];
- int pos = 0;
-
- PasswordReader backspaceThread = new PasswordReader();
- backspaceThread.start();
-
- try
- {
- while (true)
- {
- int charRead = System.in.read();
- if ((charRead == -1) || (charRead == '\n'))
- {
- // This is the end of the value.
- pwChars = new char[pos];
- if (0 < pos)
- {
- System.arraycopy(pwBuffer, 0, pwChars, 0, pos);
- Arrays.fill(pwBuffer, '\u0000');
- }
- return pwChars;
- }
- else if (charRead == '\r')
- {
- int char2 = System.in.read();
- if (char2 == '\n')
- {
- // This is the end of the value.
- if (pos == 0)
- {
- return null;
- }
- else
- {
- pwChars = new char[pos];
- System.arraycopy(pwBuffer, 0, pwChars, 0, pos);
- Arrays.fill(pwBuffer, '\u0000');
- return pwChars;
- }
- }
- else
- {
- // Append the characters to the buffer and continue.
- pwBuffer[pos++] = (char) charRead;
- if (pos >= pwBuffer.length)
- {
- char[] newBuffer = new char[pwBuffer.length+100];
- System.arraycopy(pwBuffer, 0, newBuffer, 0, pwBuffer.length);
- Arrays.fill(pwBuffer, '\u0000');
- pwBuffer = newBuffer;
- }
-
- pwBuffer[pos++] = (char) char2;
- if (pos >= pwBuffer.length)
- {
- char[] newBuffer = new char[pwBuffer.length+100];
- System.arraycopy(pwBuffer, 0, newBuffer, 0, pwBuffer.length);
- Arrays.fill(pwBuffer, '\u0000');
- pwBuffer = newBuffer;
- }
- }
- }
- else
- {
- // Append the value to the buffer and continue.
- pwBuffer[pos++] = (char) charRead;
-
- if (pos >= pwBuffer.length)
- {
- char[] newBuffer = new char[pwBuffer.length+100];
- System.arraycopy(pwBuffer, 0, newBuffer, 0, pwBuffer.length);
- Arrays.fill(pwBuffer, '\u0000');
- pwBuffer = newBuffer;
- }
- }
- }
- }
- catch (Exception e)
- {
- // We must have encountered an error while attempting to read. The only
- // thing we can do is to dump a stack trace and return null.
- e.printStackTrace();
- return null;
- }
- finally
- {
- backspaceThread.stopLooping();
- }
- }
-}
-
diff --git a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java
index 430aec1..31f26a8 100644
--- a/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java
+++ b/opendj-sdk/opendj3-server-dev/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java
@@ -28,14 +28,18 @@
package org.opends.server.util.args;
import org.forgerock.i18n.LocalizableMessage;
+
import static org.opends.messages.ToolMessages.*;
+
import org.opends.server.tools.LDAPConnection;
import org.opends.server.tools.LDAPConnectionOptions;
import org.opends.server.tools.SSLConnectionFactory;
import org.opends.server.tools.SSLConnectionException;
import org.opends.server.tools.LDAPConnectionException;
+
import static org.opends.server.util.ServerConstants.MAX_LINE_WIDTH;
import static org.opends.server.util.StaticUtils.wrapText;
+
import org.opends.server.util.cli.LDAPConnectionConsoleInteraction;
import org.opends.server.admin.client.cli.SecureConnectionCliArgs;
import org.opends.server.types.OpenDsException;
@@ -44,6 +48,7 @@
import com.forgerock.opendj.cli.ArgumentException;
import com.forgerock.opendj.cli.ArgumentParser;
import com.forgerock.opendj.cli.ArgumentGroup;
+import com.forgerock.opendj.cli.ConsoleApplication;
import com.forgerock.opendj.cli.FileBasedArgument;
import com.forgerock.opendj.cli.StringArgument;
@@ -51,12 +56,12 @@
import java.util.LinkedHashSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.io.PrintStream;
+
import javax.net.ssl.SSLException;
-import org.opends.server.util.PasswordReader;
/**
* Creates an argument parser pre-populated with arguments for specifying
- * information for openning and LDAPConnection an LDAP connection.
+ * information for opening and LDAPConnection an LDAP connection.
*/
public class LDAPConnectionArgumentParser extends ArgumentParser {
@@ -498,7 +503,7 @@
try
{
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDN));
- char[] pwChars = PasswordReader.readPassword();
+ char[] pwChars = ConsoleApplication.readPassword();
pwd = new String(pwChars);
//As per rfc 4513(section-5.1.2) a client should avoid sending
//an empty password to the server.
@@ -508,7 +513,7 @@
INFO_LDAPAUTH_NON_EMPTY_PASSWORD.get(),
MAX_LINE_WIDTH));
out.print(INFO_LDAPAUTH_PASSWORD_PROMPT.get(bindDN));
- pwChars = PasswordReader.readPassword();
+ pwChars = ConsoleApplication.readPassword();
}
pwd = new String(pwChars);
} catch(Exception ex)
--
Gitblit v1.10.0