mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

lutoff
14.08.2007 e37e08cc3e556fb78be9d69f2c1ac8e2399189dd
Add bindPassword Argument 
3 files modified
75 ■■■■■ changed files
opends/src/server/org/opends/server/admin/client/cli/DsServiceCliMain.java 8 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/client/cli/DsServiceCliParser.java 59 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/client/cli/DsServiceCliReturnCode.java 8 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/client/cli/DsServiceCliMain.java
@@ -208,6 +208,14 @@
      return ReturnCode.ERROR_PARSING_ARGS.getReturnCode();
    }
    // Validate args
    int ret = argParser.validateGlobalOption(err);
    if (ret != ReturnCode.SUCCESSFUL_NOP.getReturnCode())
    {
      return ret;
    }
    // Get connection parameters
    String host = argParser.getHostName() ;
    String port = argParser.getPort() ;
opends/src/server/org/opends/server/admin/client/cli/DsServiceCliParser.java
@@ -92,6 +92,11 @@
  private FileBasedArgument bindPasswordFileArg = null;
  /**
   * The 'bindPassword' global argument.
   */
  private StringArgument bindPasswordArg = null;
  /**
   * The 'verbose' global argument.
   */
  private BooleanArgument verboseArg = null;
@@ -190,6 +195,11 @@
        "cn=Directory Manager", null, MSGID_DESCRIPTION_BINDDN);
    addGlobalArgument(bindDnArg);
    bindPasswordArg = new StringArgument("bindPassword",
        OPTION_SHORT_BINDPWD, OPTION_LONG_BINDPWD, false, false, true,
        OPTION_VALUE_BINDPWD, null, null, MSGID_DESCRIPTION_BINDPASSWORD);
    addGlobalArgument(bindPasswordArg);
    bindPasswordFileArg = new FileBasedArgument("bindPasswordFile",
        OPTION_SHORT_BINDPWD_FILE, OPTION_LONG_BINDPWD_FILE, false, false,
        OPTION_VALUE_BINDPWD_FILE, null, null,
@@ -272,6 +282,30 @@
   */
  public String getBindPassword(String dn, PrintStream out, PrintStream err)
  {
    if (bindPasswordArg.isPresent())
    {
      String bindPasswordValue = bindPasswordArg.getValue();
      if(bindPasswordValue != null && bindPasswordValue.equals("-"))
      {
        // read the password from the stdin.
        try
        {
          out.print(getMessage(MSGID_LDAPAUTH_PASSWORD_PROMPT, dn));
          char[] pwChars = PasswordReader.readPassword();
          bindPasswordValue = new String(pwChars);
        } catch(Exception ex)
        {
          if (debugEnabled())
          {
            TRACER.debugCaught(DebugLogLevel.ERROR, ex);
          }
          err.println(wrapText(ex.getMessage(), MAX_LINE_WIDTH));
          return null;
        }
      }
      return bindPasswordValue;
    }
    else
    if (bindPasswordFileArg.isPresent())
    {
      return bindPasswordFileArg.getValue();
@@ -348,4 +382,29 @@
      return false ;
    }
  }
  /**
   * Indication if provided global options are validate.
   *
   * @param err the stream to be used to print error message.
   *
   * @return return code.
   */
  public int validateGlobalOption(PrintStream err)
  {
    ReturnCode returnCode = ReturnCode.SUCCESSFUL_NOP;
    // Couldn't have at the same time bindPassword and bibdPasswordFile
    if(bindPasswordArg.isPresent() && bindPasswordFileArg.isPresent())
    {
      int    msgID   = MSGID_TOOL_CONFLICTING_ARGS;
      String message = getMessage(msgID, bindPasswordArg.getLongIdentifier(),
                                  bindPasswordFileArg.getLongIdentifier());
      err.println(wrapText(message, MAX_LINE_WIDTH));
      return returnCode.CONFLICTING_ARGS.getReturnCode();
    }
    return ReturnCode.SUCCESSFUL_NOP.getReturnCode();
  }
}
opends/src/server/org/opends/server/admin/client/cli/DsServiceCliReturnCode.java
@@ -27,6 +27,7 @@
package org.opends.server.admin.client.cli;
import static org.opends.server.messages.AdminMessages.*;
import static org.opends.server.messages.ToolMessages.*;
import java.util.HashMap;
@@ -136,7 +137,12 @@
    /**
     * Unexpected error (potential bug).
     */
    ERROR_UNEXPECTED(17, MSGID_ADMIN_ERROR_UNEXPECTED);
    ERROR_UNEXPECTED(17, MSGID_ADMIN_ERROR_UNEXPECTED),
    /**
     * Unexpected error (potential bug).
     */
    CONFLICTING_ARGS(18, MSGID_ADMIN_NO_MESSAGE);
    // The retunCodevalue of the value.
    private final int returnCode;