Package org.nasutekds.server.util.args

Examples of org.nasutekds.server.util.args.SubCommand


      booleanValues.add(INFO_MULTICHOICE_TRUE_VALUE.get().toString());
      booleanValues.add(INFO_MULTICHOICE_FALSE_VALUE.get().toString());


      Message msg = INFO_DESCRIPTION_PWPSTATE_GET_ALL.get();
      new SubCommand(argParser, SC_GET_ALL, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_PASSWORD_POLICY_DN.get();
      new SubCommand(argParser, SC_GET_PASSWORD_POLICY_DN, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_ACCOUNT_DISABLED_STATE.get();
      new SubCommand(argParser, SC_GET_ACCOUNT_DISABLED_STATE, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_SET_ACCOUNT_DISABLED_STATE.get();
      SubCommand sc = new SubCommand(argParser, SC_SET_ACCOUNT_DISABLED_STATE,
                                     msg);
      sc.addArgument(new MultiChoiceArgument(ARG_OP_VALUE, 'O',
                              "operationValue", true, false, true,
                              INFO_TRUE_FALSE_PLACEHOLDER.get(), null, null,
                              booleanValues, false,
                              INFO_DESCRIPTION_OPERATION_BOOLEAN_VALUE.get()));

      msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_ACCOUNT_DISABLED_STATE.get();
      new SubCommand(argParser, SC_CLEAR_ACCOUNT_DISABLED_STATE, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_ACCOUNT_EXPIRATION_TIME.get();
      new SubCommand(argParser, SC_GET_ACCOUNT_EXPIRATION_TIME, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_SET_ACCOUNT_EXPIRATION_TIME.get();
      sc = new SubCommand(argParser, SC_SET_ACCOUNT_EXPIRATION_TIME, msg);
      sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
                              false, false, true, INFO_TIME_PLACEHOLDER.get(),
                              null, null,
                              INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_ACCOUNT_EXPIRATION_TIME.get();
      sc = new SubCommand(argParser, SC_CLEAR_ACCOUNT_EXPIRATION_TIME, msg);
      sc.setHidden(true);

      msg =
              INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_ACCOUNT_EXPIRATION
                      .get();
      new SubCommand(argParser,
              SC_GET_SECONDS_UNTIL_ACCOUNT_EXPIRATION,
              msg);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_PASSWORD_CHANGED_TIME.get();
      new SubCommand(argParser, SC_GET_PASSWORD_CHANGED_TIME, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_SET_PASSWORD_CHANGED_TIME.get();
      sc = new SubCommand(argParser, SC_SET_PASSWORD_CHANGED_TIME, msg);
      sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
                              false, false, true, INFO_TIME_PLACEHOLDER.get(),
                              null, null,
                              INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_PASSWORD_CHANGED_TIME.get();
      sc = new SubCommand(argParser, SC_CLEAR_PASSWORD_CHANGED_TIME, msg);
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_PASSWORD_EXPIRATION_WARNED_TIME
              .get();
      new SubCommand(argParser, SC_GET_PASSWORD_EXP_WARNED_TIME, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_SET_PASSWORD_EXPIRATION_WARNED_TIME
              .get();
      sc = new SubCommand(argParser, SC_SET_PASSWORD_EXP_WARNED_TIME, msg);
      sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
                              false, false, true, INFO_TIME_PLACEHOLDER.get(),
                              null, null,
                              INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_PASSWORD_EXPIRATION_WARNED_TIME
              .get();
      sc = new SubCommand(argParser, SC_CLEAR_PASSWORD_EXP_WARNED_TIME, msg);
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_PASSWORD_EXP.get();
      new SubCommand(argParser, SC_GET_SECONDS_UNTIL_PASSWORD_EXPIRATION,
                     msg);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_PASSWORD_EXP_WARNING
              .get();
      new SubCommand(argParser,
                     SC_GET_SECONDS_UNTIL_PASSWORD_EXPIRATION_WARNING, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_AUTH_FAILURE_TIMES.get();
      new SubCommand(argParser, SC_GET_AUTHENTICATION_FAILURE_TIMES, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_ADD_AUTH_FAILURE_TIME.get();
      sc = new SubCommand(argParser, SC_ADD_AUTHENTICATION_FAILURE_TIME,
              msg);
      sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
                              false, true, true, INFO_TIME_PLACEHOLDER.get(),
                              null, null,
                              INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_SET_AUTH_FAILURE_TIMES.get();
      sc = new SubCommand(argParser, SC_SET_AUTHENTICATION_FAILURE_TIMES,
                          msg);
      sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
                              false, true, true, INFO_TIME_PLACEHOLDER.get(),
                              null, null,
                              INFO_DESCRIPTION_OPERATION_TIME_VALUES.get()));
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_AUTH_FAILURE_TIMES.get();
      sc = new SubCommand(argParser, SC_CLEAR_AUTHENTICATION_FAILURE_TIMES,
                          msg);
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_AUTH_FAILURE_UNLOCK
              .get();
      new SubCommand(argParser,
                     SC_GET_SECONDS_UNTIL_AUTHENTICATION_FAILURE_UNLOCK,
                     msg);

      msg =
              INFO_DESCRIPTION_PWPSTATE_GET_REMAINING_AUTH_FAILURE_COUNT.get();
      new SubCommand(argParser, SC_GET_REMAINING_AUTHENTICATION_FAILURE_COUNT,
                     msg);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_LAST_LOGIN_TIME.get();
      new SubCommand(argParser, SC_GET_LAST_LOGIN_TIME, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_SET_LAST_LOGIN_TIME.get();
      sc = new SubCommand(argParser, SC_SET_LAST_LOGIN_TIME, msg);
      sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
                              false, false, true, INFO_TIME_PLACEHOLDER.get(),
                              null, null,
                              INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_LAST_LOGIN_TIME.get();
      sc = new SubCommand(argParser, SC_CLEAR_LAST_LOGIN_TIME, msg);
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_IDLE_LOCKOUT.get();
      new SubCommand(argParser, SC_GET_SECONDS_UNTIL_IDLE_LOCKOUT, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_PASSWORD_RESET_STATE.get();
      new SubCommand(argParser, SC_GET_PASSWORD_RESET_STATE, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_SET_PASSWORD_RESET_STATE.get();
      sc = new SubCommand(argParser, SC_SET_PASSWORD_RESET_STATE, msg);
      sc.addArgument(new MultiChoiceArgument(ARG_OP_VALUE, 'O',
                              "operationValue", true, false, true,
                              INFO_TRUE_FALSE_PLACEHOLDER.get(), null, null,
                              booleanValues, false,
                              INFO_DESCRIPTION_OPERATION_BOOLEAN_VALUE.get()));
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_PASSWORD_RESET_STATE.get();
      sc = new SubCommand(argParser, SC_CLEAR_PASSWORD_RESET_STATE, msg);
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_RESET_LOCKOUT.get();
      new SubCommand(argParser, SC_GET_SECONDS_UNTIL_PASSWORD_RESET_LOCKOUT,
                     msg);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_GRACE_LOGIN_USE_TIMES.get();
      new SubCommand(argParser, SC_GET_GRACE_LOGIN_USE_TIMES, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_ADD_GRACE_LOGIN_USE_TIME.get();
      sc = new SubCommand(argParser, SC_ADD_GRACE_LOGIN_USE_TIME, msg);
      sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
                              false, true, true, INFO_TIME_PLACEHOLDER.get(),
                              null, null,
                              INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_SET_GRACE_LOGIN_USE_TIMES.get();
      sc = new SubCommand(argParser, SC_SET_GRACE_LOGIN_USE_TIMES, msg);
      sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
                              false, true, true, INFO_TIME_PLACEHOLDER.get(),
                              null, null,
                              INFO_DESCRIPTION_OPERATION_TIME_VALUES.get()));
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_GRACE_LOGIN_USE_TIMES.get();
      sc = new SubCommand(argParser, SC_CLEAR_GRACE_LOGIN_USE_TIMES, msg);
      sc.setHidden(true);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_REMAINING_GRACE_LOGIN_COUNT.get();
      new SubCommand(argParser, SC_GET_REMAINING_GRACE_LOGIN_COUNT,
                     msg);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_PW_CHANGED_BY_REQUIRED_TIME.get();
      new SubCommand(argParser, SC_GET_PASSWORD_CHANGED_BY_REQUIRED_TIME,
                     msg);

      msg = INFO_DESCRIPTION_PWPSTATE_SET_PW_CHANGED_BY_REQUIRED_TIME.get();
      sc = new SubCommand(argParser, SC_SET_PASSWORD_CHANGED_BY_REQUIRED_TIME,
                          msg);
      sc.addArgument(new StringArgument(ARG_OP_VALUE, 'O', "operationValue",
                              false, false, true, INFO_TIME_PLACEHOLDER.get(),
                              null, null,
                              INFO_DESCRIPTION_OPERATION_TIME_VALUE.get()));
      sc.setHidden(true);

      msg =
              INFO_DESCRIPTION_PWPSTATE_CLEAR_PW_CHANGED_BY_REQUIRED_TIME.get();
      sc = new SubCommand(argParser, SC_CLEAR_PASSWORD_CHANGED_BY_REQUIRED_TIME,
                          msg);
      sc.setHidden(true);

      msg =
              INFO_DESCRIPTION_PWPSTATE_GET_SECONDS_UNTIL_REQUIRED_CHANGE_TIME
                      .get();
      new SubCommand(argParser, SC_GET_SECONDS_UNTIL_REQUIRED_CHANGE_TIME,
                     msg);

      msg = INFO_DESCRIPTION_PWPSTATE_GET_PASSWORD_HISTORY.get();
      new SubCommand(argParser, SC_GET_PASSWORD_HISTORY, msg);

      msg = INFO_DESCRIPTION_PWPSTATE_CLEAR_PASSWORD_HISTORY.get();
      sc = new SubCommand(argParser, SC_CLEAR_PASSWORD_HISTORY, msg);
      sc.setHidden(true);
    }
    catch (ArgumentException ae)
    {
      Message message = ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage());
View Full Code Here


   *
   * @return  A result code indicating the results of the processing.
   */
  private static int processSubcommand(ASN1Writer writer) throws IOException
  {
    SubCommand subCommand = argParser.getSubCommand();
    if (subCommand == null)
    {
      Message message = ERR_PWPSTATE_NO_SUBCOMMAND.get();
      err.println(wrapText(message, MAX_LINE_WIDTH));
      err.println(argParser.getUsage());
      return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
    }

    String subCommandName = subCommand.getName();
    if (subCommandName.equals(SC_GET_ALL))
    {
      // The list should stay empty for this one.
    }
    else if (subCommandName.equals(SC_GET_PASSWORD_POLICY_DN))
    {
      encode(writer, OP_GET_PASSWORD_POLICY_DN, NO_VALUE);
    }
    else if (subCommandName.equals(SC_GET_ACCOUNT_DISABLED_STATE))
    {
      encode(writer, OP_GET_ACCOUNT_DISABLED_STATE, NO_VALUE);
    }
    else if (subCommandName.equals(SC_SET_ACCOUNT_DISABLED_STATE))
    {
      Argument a = subCommand.getArgumentForName(ARG_OP_VALUE);
      if ((a != null) && a.isPresent())
      {
        String valueStr = a.getValue();
        if (isTrueValue(valueStr))
        {
          encode(writer, OP_SET_ACCOUNT_DISABLED_STATE, "true");
        }
        else if (isFalseValue(valueStr))
        {
          encode(writer, OP_SET_ACCOUNT_DISABLED_STATE, "false");
        }
        else
        {
          Message message = ERR_PWPSTATE_INVALID_BOOLEAN_VALUE.get(valueStr);
          err.println(wrapText(message, MAX_LINE_WIDTH));
          return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
        }
      }
      else
      {
        Message message = ERR_PWPSTATE_NO_BOOLEAN_VALUE.get();
        err.println(wrapText(message, MAX_LINE_WIDTH));
        return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
      }
    }
    else if (subCommandName.equals(SC_CLEAR_ACCOUNT_DISABLED_STATE))
    {
      encode(writer, OP_CLEAR_ACCOUNT_DISABLED_STATE, NO_VALUE);
    }
    else if (subCommandName.equals(SC_GET_ACCOUNT_EXPIRATION_TIME))
    {
      encode(writer, OP_GET_ACCOUNT_EXPIRATION_TIME, NO_VALUE);
    }
    else if (subCommandName.equals(SC_SET_ACCOUNT_EXPIRATION_TIME))
    {
      Argument a = subCommand.getArgumentForName(ARG_OP_VALUE);
      if ((a != null) && a.isPresent())
      {
        encode(writer, OP_SET_ACCOUNT_EXPIRATION_TIME, a.getValue());
      }
      else
      {
        encode(writer, OP_SET_ACCOUNT_EXPIRATION_TIME, NO_VALUE);
      }
    }
    else if (subCommandName.equals(SC_CLEAR_ACCOUNT_EXPIRATION_TIME))
    {
      encode(writer, OP_CLEAR_ACCOUNT_EXPIRATION_TIME, NO_VALUE);
    }
    else if (subCommandName.equals(SC_GET_SECONDS_UNTIL_ACCOUNT_EXPIRATION))
    {
      encode(writer, OP_GET_SECONDS_UNTIL_ACCOUNT_EXPIRATION, NO_VALUE);
    }
    else if (subCommandName.equals(SC_GET_PASSWORD_CHANGED_TIME))
    {
      encode(writer, OP_GET_PASSWORD_CHANGED_TIME, NO_VALUE);
    }
    else if (subCommandName.equals(SC_SET_PASSWORD_CHANGED_TIME))
    {
      Argument a = subCommand.getArgumentForName(ARG_OP_VALUE);
      if ((a != null) && a.isPresent())
      {
        encode(writer, OP_SET_PASSWORD_CHANGED_TIME, a.getValue());
      }
      else
      {
        encode(writer, OP_SET_PASSWORD_CHANGED_TIME, NO_VALUE);
      }
    }
    else if (subCommandName.equals(SC_CLEAR_PASSWORD_CHANGED_TIME))
    {
      encode(writer, OP_CLEAR_PASSWORD_CHANGED_TIME, NO_VALUE);
    }
    else if(subCommandName.equals(SC_GET_PASSWORD_EXP_WARNED_TIME))
    {
      encode(writer, OP_GET_PASSWORD_EXPIRATION_WARNED_TIME, NO_VALUE);
    }
    else if(subCommandName.equals(SC_SET_PASSWORD_EXP_WARNED_TIME))
    {
      Argument a = subCommand.getArgumentForName(ARG_OP_VALUE);
      if ((a != null) && a.isPresent())
      {
        encode(writer, OP_SET_PASSWORD_EXPIRATION_WARNED_TIME,
                              a.getValue());
      }
      else
      {
        encode(writer, OP_SET_PASSWORD_EXPIRATION_WARNED_TIME,
                              NO_VALUE);
      }
    }
    else if(subCommandName.equals(SC_CLEAR_PASSWORD_EXP_WARNED_TIME))
    {
      encode(writer, OP_CLEAR_PASSWORD_EXPIRATION_WARNED_TIME,
                            NO_VALUE);
    }
    else if(subCommandName.equals(SC_GET_SECONDS_UNTIL_PASSWORD_EXPIRATION))
    {
      encode(writer, OP_GET_SECONDS_UNTIL_PASSWORD_EXPIRATION,
                            NO_VALUE);
    }
    else if(subCommandName.equals(
                 SC_GET_SECONDS_UNTIL_PASSWORD_EXPIRATION_WARNING))
    {
      encode(writer, OP_GET_SECONDS_UNTIL_PASSWORD_EXPIRATION_WARNING,
                            NO_VALUE);
    }
    else if(subCommandName.equals(SC_GET_AUTHENTICATION_FAILURE_TIMES))
    {
      encode(writer, OP_GET_AUTHENTICATION_FAILURE_TIMES, NO_VALUE);
    }
    else if(subCommandName.equals(SC_ADD_AUTHENTICATION_FAILURE_TIME))
    {
      Argument a = subCommand.getArgumentForName(ARG_OP_VALUE);
      if ((a != null) && a.isPresent())
      {
        encode(writer, OP_ADD_AUTHENTICATION_FAILURE_TIME,
                              a.getValue());
      }
      else
      {
        encode(writer, OP_ADD_AUTHENTICATION_FAILURE_TIME, NO_VALUE);
      }
    }
    else if(subCommandName.equals(SC_SET_AUTHENTICATION_FAILURE_TIMES))
    {
      Argument a = subCommand.getArgumentForName(ARG_OP_VALUE);
      if ((a != null) && a.isPresent())
      {
        ArrayList<String> valueList = new ArrayList<String>(a.getValues());
        String[] values = new String[valueList.size()];
        valueList.toArray(values);

        encode(writer, OP_SET_AUTHENTICATION_FAILURE_TIMES, values);
      }
      else
      {
        encode(writer, OP_SET_AUTHENTICATION_FAILURE_TIMES, NO_VALUE);
      }
    }
    else if(subCommandName.equals(SC_CLEAR_AUTHENTICATION_FAILURE_TIMES))
    {
      encode(writer, OP_CLEAR_AUTHENTICATION_FAILURE_TIMES, NO_VALUE);
    }
    else if(subCommandName.equals(
                 SC_GET_SECONDS_UNTIL_AUTHENTICATION_FAILURE_UNLOCK))
    {
      encode(writer, OP_GET_SECONDS_UNTIL_AUTHENTICATION_FAILURE_UNLOCK,
                            NO_VALUE);
    }
    else if(subCommandName.equals(
                 SC_GET_REMAINING_AUTHENTICATION_FAILURE_COUNT))
    {
      encode(writer, OP_GET_REMAINING_AUTHENTICATION_FAILURE_COUNT,
                            NO_VALUE);
    }
    else if(subCommandName.equals(SC_GET_LAST_LOGIN_TIME))
    {
      encode(writer, OP_GET_LAST_LOGIN_TIME, NO_VALUE);
    }
    else if(subCommandName.equals(SC_SET_LAST_LOGIN_TIME))
    {
      Argument a = subCommand.getArgumentForName(ARG_OP_VALUE);
      if ((a != null) && a.isPresent())
      {
        encode(writer, OP_SET_LAST_LOGIN_TIME, a.getValue());
      }
      else
      {
        encode(writer, OP_SET_LAST_LOGIN_TIME, NO_VALUE);
      }
    }
    else if(subCommandName.equals(SC_CLEAR_LAST_LOGIN_TIME))
    {
      encode(writer, OP_CLEAR_LAST_LOGIN_TIME, NO_VALUE);
    }
    else if(subCommandName.equals(SC_GET_SECONDS_UNTIL_IDLE_LOCKOUT))
    {
      encode(writer, OP_GET_SECONDS_UNTIL_IDLE_LOCKOUT, NO_VALUE);
    }
    else if(subCommandName.equals(SC_GET_PASSWORD_RESET_STATE))
    {
      encode(writer, OP_GET_PASSWORD_RESET_STATE, NO_VALUE);
    }
    else if(subCommandName.equals(SC_SET_PASSWORD_RESET_STATE))
    {
      Argument a = subCommand.getArgumentForName(ARG_OP_VALUE);
      if ((a != null) && a.isPresent())
      {
        String valueStr = a.getValue();
        if (isTrueValue(valueStr))
        {
          encode(writer, OP_SET_PASSWORD_RESET_STATE, "true");
        }
        else if (isFalseValue(valueStr))
        {
          encode(writer, OP_SET_PASSWORD_RESET_STATE, "false");
        }
        else
        {
          Message message = ERR_PWPSTATE_INVALID_BOOLEAN_VALUE.get(valueStr);
          err.println(wrapText(message, MAX_LINE_WIDTH));
          return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
        }
      }
      else
      {
        Message message = ERR_PWPSTATE_NO_BOOLEAN_VALUE.get();
        err.println(wrapText(message, MAX_LINE_WIDTH));
        return LDAPResultCode.CLIENT_SIDE_PARAM_ERROR;
      }
    }
    else if(subCommandName.equals(SC_CLEAR_PASSWORD_RESET_STATE))
    {
      encode(writer, OP_GET_PASSWORD_RESET_STATE, NO_VALUE);
    }
    else if(subCommandName.equals(SC_GET_SECONDS_UNTIL_PASSWORD_RESET_LOCKOUT))
    {
      encode(writer, OP_GET_SECONDS_UNTIL_PASSWORD_RESET_LOCKOUT,
                            NO_VALUE);
    }
    else if(subCommandName.equals(SC_GET_GRACE_LOGIN_USE_TIMES))
    {
      encode(writer, OP_GET_GRACE_LOGIN_USE_TIMES, NO_VALUE);
    }
    else if(subCommandName.equals(SC_ADD_GRACE_LOGIN_USE_TIME))
    {
      Argument a = subCommand.getArgumentForName(ARG_OP_VALUE);
      if ((a != null) && a.isPresent())
      {
        encode(writer, OP_ADD_GRACE_LOGIN_USE_TIME, a.getValue());
      }
      else
      {
        encode(writer, OP_ADD_GRACE_LOGIN_USE_TIME, NO_VALUE);
      }
    }
    else if(subCommandName.equals(SC_SET_GRACE_LOGIN_USE_TIMES))
    {
      Argument a = subCommand.getArgumentForName(ARG_OP_VALUE);
      if ((a != null) && a.isPresent())
      {
        ArrayList<String> valueList = new ArrayList<String>(a.getValues());
        String[] values = new String[valueList.size()];
        valueList.toArray(values);

        encode(writer, OP_SET_GRACE_LOGIN_USE_TIMES, values);
      }
      else
      {
        encode(writer, OP_SET_GRACE_LOGIN_USE_TIMES, NO_VALUE);
      }
    }
    else if(subCommandName.equals(SC_CLEAR_GRACE_LOGIN_USE_TIMES))
    {
      encode(writer, OP_CLEAR_GRACE_LOGIN_USE_TIMES, NO_VALUE);
    }
    else if(subCommandName.equals(SC_GET_REMAINING_GRACE_LOGIN_COUNT))
    {
      encode(writer, OP_GET_REMAINING_GRACE_LOGIN_COUNT, NO_VALUE);
    }
    else if(subCommandName.equals(SC_GET_PASSWORD_CHANGED_BY_REQUIRED_TIME))
    {
      encode(writer, OP_GET_PASSWORD_CHANGED_BY_REQUIRED_TIME,
                            NO_VALUE);
    }
    else if(subCommandName.equals(SC_SET_PASSWORD_CHANGED_BY_REQUIRED_TIME))
    {
      Argument a = subCommand.getArgumentForName(ARG_OP_VALUE);
      if ((a != null) && a.isPresent())
      {
        encode(writer, OP_SET_PASSWORD_CHANGED_BY_REQUIRED_TIME,
                              a.getValue());
      }
View Full Code Here

    StringArgument  encodedFile      = null;
    StringArgument  rawData          = null;
    StringArgument  rawFile          = null;
    StringArgument  toEncodedFile    = null;
    StringArgument  toRawFile        = null;
    SubCommand      decodeSubCommand = null;
    SubCommand      encodeSubCommand = null;

    try
    {
      decodeSubCommand = new SubCommand(argParser, "decode",
                                        INFO_BASE64_DECODE_DESCRIPTION.get());

      encodeSubCommand = new SubCommand(argParser, "encode",
                                        INFO_BASE64_ENCODE_DESCRIPTION.get());


      encodedData = new StringArgument("encodeddata", 'd', "encodedData", false,
                             false, true, INFO_DATA_PLACEHOLDER.get(), null,
                             null,
                             INFO_BASE64_ENCODED_DATA_DESCRIPTION.get());
      decodeSubCommand.addArgument(encodedData);


      encodedFile = new StringArgument("encodedfile", 'f', "encodedDataFile",
                             false, false, true, INFO_PATH_PLACEHOLDER.get(),
                             null, null,
                             INFO_BASE64_ENCODED_FILE_DESCRIPTION.get());
      decodeSubCommand.addArgument(encodedFile);


      toRawFile = new StringArgument("torawfile", 'o', "toRawFile", false,
                                     false, true, INFO_PATH_PLACEHOLDER.get(),
                                     null, null,
                                     INFO_BASE64_TO_RAW_FILE_DESCRIPTION.get());
      decodeSubCommand.addArgument(toRawFile);


      rawData = new StringArgument("rawdata", 'd', "rawData", false, false,
                                   true, INFO_DATA_PLACEHOLDER.get(), null,
                                   null,
                                   INFO_BASE64_RAW_DATA_DESCRIPTION.get());
      encodeSubCommand.addArgument(rawData);


      rawFile = new StringArgument("rawfile", 'f', "rawDataFile", false, false,
                                   true, INFO_PATH_PLACEHOLDER.get(), null,
                                   null,
                                   INFO_BASE64_RAW_FILE_DESCRIPTION.get());
      encodeSubCommand.addArgument(rawFile);


      toEncodedFile = new StringArgument("toencodedfile", 'o', "toEncodedFile",
                               false, false, true, INFO_PATH_PLACEHOLDER.get(),
                               null, null,
                               INFO_BASE64_TO_ENCODED_FILE_DESCRIPTION.get());
      encodeSubCommand.addArgument(toEncodedFile);


      ArrayList<SubCommand> subCommandList = new ArrayList<SubCommand>(2);
      subCommandList.add(decodeSubCommand);
      subCommandList.add(encodeSubCommand);


      showUsage = new BooleanArgument("help", 'H', "help",
                                      INFO_BASE64_HELP_DESCRIPTION.get());
      argParser.addGlobalArgument(showUsage);
      argParser.setUsageGroupArgument(showUsage, subCommandList);
      argParser.setUsageArgument(showUsage, NullOutputStream.printStream());
    }
    catch (ArgumentException ae)
    {
      System.err.println(ERR_CANNOT_INITIALIZE_ARGS.get(ae.getMessage()));
      System.exit(1);
    }

    try
    {
      argParser.parseArguments(args);
    }
    catch (ArgumentException ae)
    {
      System.err.println(
          ERR_ERROR_PARSING_ARGS.get(ae.getMessage()).toString());
      System.exit(1);
    }

    SubCommand subCommand = argParser.getSubCommand();
    if (argParser.isUsageArgumentPresent())
    {
      if (subCommand == null)
      {
        System.out.println(argParser.getUsage());
      }
      else
      {
        MessageBuilder messageBuilder = new MessageBuilder();
        argParser.getSubCommandUsage(messageBuilder, subCommand);
        System.out.println(messageBuilder.toString());
      }

      return;
    }

    if (argParser.isVersionArgumentPresent())
    {
      // We have to print the version since we have set a NullOutputStream on
      // the parser
      try
      {
        DirectoryServer.printVersion(System.out);
        System.exit(0);
      }
      catch (Throwable t)
      {
        // Bug
        System.err.println(ERR_UNEXPECTED.get(t.toString()).toString());
        System.exit(1);
      }
    }

    if (subCommand == null)
    {
      System.err.println(argParser.getUsage());
      System.exit(1);
    }
    if (subCommand.getName().equals(encodeSubCommand.getName()))
    {
      byte[] dataToEncode = null;
      if (rawData.isPresent())
      {
        try
        {
          dataToEncode = rawData.getValue().getBytes("UTF-8");
        }
        catch(UnsupportedEncodingException ex)
        {
          System.err.println(ERR_UNEXPECTED.get(ex.toString()).toString());
          System.exit(1);
        }
      }
      else
      {
        try
        {
          boolean shouldClose;
          InputStream inputStream;
          if (rawFile.isPresent())
          {
            inputStream = new FileInputStream(rawFile.getValue());
            shouldClose = true;
          }
          else
          {
            inputStream = System.in;
            shouldClose = false;
          }

          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          byte[] buffer = new byte[8192];
          while (true)
          {
            int bytesRead = inputStream.read(buffer);
            if (bytesRead < 0)
            {
              break;
            }
            else
            {
              baos.write(buffer, 0, bytesRead);
            }
          }

          if (shouldClose)
          {
            inputStream.close();
          }

          dataToEncode = baos.toByteArray();
        }
        catch (Exception e)
        {
          System.err.println(ERR_BASE64_CANNOT_READ_RAW_DATA.get(
                                  getExceptionMessage(e)).toString());
          System.exit(1);
        }
      }

      String base64Data = encode(dataToEncode);
      if (toEncodedFile.isPresent())
      {
        try
        {
          BufferedWriter writer =
               new BufferedWriter(new FileWriter(toEncodedFile.getValue()));
          writer.write(base64Data);
          writer.newLine();
          writer.close();
        }
        catch (Exception e)
        {
          System.err.println(ERR_BASE64_CANNOT_WRITE_ENCODED_DATA.get(
                                  getExceptionMessage(e)).toString());
          System.exit(1);
        }
      }
      else
      {
        System.out.println(base64Data);
      }
    }
    else if (subCommand.getName().equals(decodeSubCommand.getName()))
    {
      String dataToDecode = null;
      if (encodedData.isPresent())
      {
        dataToDecode = encodedData.getValue();
      }
      else
      {
        try
        {
          boolean shouldClose;
          BufferedReader reader;
          if (encodedFile.isPresent())
          {
            reader = new BufferedReader(new FileReader(encodedFile.getValue()));
            shouldClose = true;
          }
          else
          {
            reader = new BufferedReader(new InputStreamReader(System.in));
            shouldClose = false;
          }

          StringBuilder buffer = new StringBuilder();
          while (true)
          {
            String line = reader.readLine();
            if (line == null)
            {
              break;
            }

            StringTokenizer tokenizer = new StringTokenizer(line);
            while (tokenizer.hasMoreTokens())
            {
              buffer.append(tokenizer.nextToken());
            }
          }

          if (shouldClose)
          {
            reader.close();
          }

          dataToDecode = buffer.toString();
        }
        catch (Exception e)
        {
          System.err.println(ERR_BASE64_CANNOT_READ_ENCODED_DATA.get(
                                  getExceptionMessage(e)).toString());
          System.exit(1);
        }
      }

      byte[] decodedData = null;
      try
      {
        decodedData = decode(dataToDecode);
      }
      catch (ParseException pe)
      {
        System.err.println(pe.getMessage());
        System.exit(1);
      }

      try
      {
        if (toRawFile.isPresent())
        {
          FileOutputStream outputStream =
               new FileOutputStream(toRawFile.getValue());
          outputStream.write(decodedData);
          outputStream.close();
        }
        else
        {
          System.out.write(decodedData);
          System.out.println();
          System.out.flush();
        }
      }
      catch (Exception e)
      {
        System.err.println(ERR_BASE64_CANNOT_WRITE_RAW_DATA.get(
                                getExceptionMessage(e)).toString());
        System.exit(1);
      }
    }
    else
    {
      System.err.println(ERR_BASE64_UNKNOWN_SUBCOMMAND.get(
                              subCommand.getName()).toString());
      System.exit(1);
    }
  }
View Full Code Here

      Map<Tag, SortedSet<SubCommand>> groups =
        new TreeMap<Tag, SortedSet<SubCommand>>();
      SortedSet<SubCommand> allSubCommands = new TreeSet<SubCommand>(c);
      for (SubCommandHandler handler : handlerFactory
          .getAllSubCommandHandlers()) {
        SubCommand sc = handler.getSubCommand();

        handlers.put(sc, handler);
        allSubCommands.add(sc);

        // Add the sub-command to its groups.
View Full Code Here

    // Create the sub-command.
    String name = "set-" + r.getName() + "-prop";
    Message description = INFO_DSCFG_DESCRIPTION_SUBCMD_SETPROP.get(r
        .getChildDefinition().getUserFriendlyName());
    this.subCommand = new SubCommand(parser, name, false, 0, 0, null,
        description);

    // Create the naming arguments.
    this.namingArgs = createNamingArgs(subCommand, path, false);
View Full Code Here

    isHidden = true;
    groupName = "ads";
    this.argParser = argParser;

    // Create-ads subcommand
    createAdsSubCmd = new SubCommand(argParser, SubCommandNameEnum.CREATE_ADS
        .toString(), INFO_ADMIN_SUBCMD_CREATE_ADS_DESCRIPTION.get());
    createAdsSubCmd.setHidden(true);
    subCommands.add(createAdsSubCmd);

    createAdsBackendNameArg = new StringArgument("backendName",
        OPTION_SHORT_BACKENDNAME, OPTION_LONG_BACKENDNAME, false, true,
        INFO_BACKENDNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_BACKENDNAME_DESCRIPTION.get());
    createAdsSubCmd.addArgument(createAdsBackendNameArg);

    // delete-ads
    deleteAdsSubCmd = new SubCommand(argParser,SubCommandNameEnum.DELETE_ADS
        .toString(), INFO_ADMIN_SUBCMD_DELETE_ADS_DESCRIPTION.get());
    deleteAdsSubCmd.setHidden(true);
    subCommands.add(deleteAdsSubCmd);

    deleteAdsBackendNameArg = new StringArgument("backendName",
View Full Code Here

    // Create the sub-command.
    String name = "get-" + r.getName() + "-prop";
    Message message = INFO_DSCFG_DESCRIPTION_SUBCMD_GETPROP.get(r
        .getChildDefinition().getUserFriendlyName());
    this.subCommand = new SubCommand(parser, name, false, 0, 0, null, message);

    // Create the naming arguments.
    this.namingArgs = createNamingArgs(subCommand, path, false);

    // Register common arguments.
View Full Code Here

    // Create the sub-command.
    String name = "delete-" + r.getName();
    Message ufpn = r.getChildDefinition().getUserFriendlyPluralName();
    Message description = INFO_DSCFG_DESCRIPTION_SUBCMD_DELETE.get(ufpn);
    this.subCommand = new SubCommand(parser, name, false, 0, 0, null,
        description);

    // Create the naming arguments.
    this.namingArgs = createNamingArgs(subCommand, c, false);
View Full Code Here

    isHidden = false;
    groupName = "server";
    this.argParser = argParser;

    // list-server-properties subcommand
    listServerPropertiesSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.LIST_SERVER_PROPERTIES.toString(),
        INFO_ADMIN_SUBCMD_LIST_SERVER_PROPS_DESCRIPTION.get());
    subCommands.add(listServerPropertiesSubCmd);

    // register-server subcommand
    registerServerSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.REGISTER_SERVER.toString(),
        INFO_ADMIN_SUBCMD_REGISTER_SERVER_DESCRIPTION.get());
    subCommands.add(registerServerSubCmd);

    registerServerServerIdArg = new StringArgument("serverID", null,
        OPTION_LONG_SERVERID, false, true, INFO_SERVERID_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_SERVERID_DESCRIPTION.get());
    registerServerSubCmd.addArgument(registerServerServerIdArg);

    registerServerSetArg = new StringArgument(OPTION_LONG_SET,
        OPTION_SHORT_SET, OPTION_LONG_SET, false, true, true,
        INFO_VALUE_SET_PLACEHOLDER.get(), null, null,
        INFO_DSCFG_DESCRIPTION_PROP_VAL.get());
    registerServerSubCmd.addArgument(registerServerSetArg);

    // unregister-server subcommand
    unregisterServerSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.UNREGISTER_SERVER.toString(),
        INFO_ADMIN_SUBCMD_UNREGISTER_SERVER_DESCRIPTION.get());
    subCommands.add(unregisterServerSubCmd);

    unregisterServerServerIDArg = new StringArgument("serverID", null,
        OPTION_LONG_SERVERID, false, true, INFO_SERVERID_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_SERVERID_DESCRIPTION.get());
    unregisterServerSubCmd.addArgument(unregisterServerServerIDArg);

    // list-servers subcommand
    listServersSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.LIST_SERVERS.toString(),
        INFO_ADMIN_SUBCMD_LIST_SERVERS_DESCRIPTION.get());
    subCommands.add(listServersSubCmd);

    // get-server-properties subcommand
    getServerPropertiesSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.GET_SERVER_PROPERTIES.toString(),
        INFO_ADMIN_SUBCMD_GET_SERVER_PROPERTIES_DESCRIPTION.get());
    subCommands.add(getServerPropertiesSubCmd);

    getServerPropertiesServerIdArg = new StringArgument("serverID", null,
        OPTION_LONG_SERVERID, false, true, INFO_SERVERID_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_SERVERID_DESCRIPTION.get());
    getServerPropertiesServerIdArg.setMultiValued(true);
    getServerPropertiesSubCmd.addArgument(getServerPropertiesServerIdArg);


    // set-server-properties subcommand
    setServerPropertiesSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.SET_SERVER_PROPERTIES.toString(),
        INFO_ADMIN_SUBCMD_SET_SERVER_PROPERTIES_DESCRIPTION.get());
    subCommands.add(setServerPropertiesSubCmd);

    setServerPropertiesServerIdArg = new StringArgument("serverID", null,
View Full Code Here

    groupName = "server-group";
    this.argParser = argParser;


    // Create-group subcommand
    createGroupSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.CREATE_GROUP.toString(),
        INFO_ADMIN_SUBCMD_CREATE_GROUP_DESCRIPTION.get());
    subCommands.add(createGroupSubCmd);

    createGroupDescriptionArg = new StringArgument("description",
        OPTION_SHORT_DESCRIPTION, OPTION_LONG_DESCRIPTION, false, false,
        true, INFO_DESCRIPTION_PLACEHOLDER.get(), "", null,
        INFO_ADMIN_ARG_DESCRIPTION_DESCRIPTION.get());
    createGroupSubCmd.addArgument(createGroupDescriptionArg);

    createGroupGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_CREATE_GROUP_GROUPNAME_DESCRIPTION.get());
    createGroupSubCmd.addArgument(createGroupGroupNameArg);

    // modify-group
    modifyGroupSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.MODIFY_GROUP.toString(),
        INFO_ADMIN_SUBCMD_MODIFY_GROUP_DESCRIPTION.get());
    subCommands.add(modifyGroupSubCmd);

    modifyGroupDescriptionArg = new StringArgument("new-description",
        OPTION_SHORT_DESCRIPTION, OPTION_LONG_DESCRIPTION, false, false,
        true, INFO_DESCRIPTION_PLACEHOLDER.get(), "", null,
        INFO_ADMIN_ARG_NEW_DESCRIPTION_DESCRIPTION.get());
    modifyGroupSubCmd.addArgument(modifyGroupDescriptionArg);

    modifyGroupGroupIdArg = new StringArgument("new-groupName",
        OPTION_SHORT_NEWGROUPNAME, OPTION_LONG_NEWGROUPNAME, false, false, true,
        INFO_GROUPNAME_PLACEHOLDER.get(), "", null,
        INFO_ADMIN_ARG_NEW_GROUPNAME_DESCRIPTION.get());
    modifyGroupSubCmd.addArgument(modifyGroupGroupIdArg);

    modifyGroupGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_GROUPNAME_DESCRIPTION.get());
    modifyGroupSubCmd.addArgument(modifyGroupGroupNameArg);

    // delete-group
    deleteGroupSubCmd = new SubCommand(argParser,SubCommandNameEnum.DELETE_GROUP
        .toString(), INFO_ADMIN_SUBCMD_DELETE_GROUP_DESCRIPTION.get());
    subCommands.add(deleteGroupSubCmd);

    deleteGroupGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_GROUPNAME_DESCRIPTION.get());
    deleteGroupSubCmd.addArgument(deleteGroupGroupNameArg);

    // list-groups
    listGroupSubCmd = new SubCommand(argParser, "list-groups",
        INFO_ADMIN_SUBCMD_LIST_GROUPS_DESCRIPTION.get());
    subCommands.add(listGroupSubCmd);

    // add-to-group
    addToGroupSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.ADD_TO_GROUP.toString(),
        INFO_ADMIN_SUBCMD_ADD_TO_GROUP_DESCRIPTION.get());
    subCommands.add(addToGroupSubCmd);

    addToGoupMemberNameArg = new StringArgument("memberName",
        OPTION_SHORT_MEMBERNAME, OPTION_LONG_MEMBERNAME, true, true,
        INFO_MEMBERNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_ADD_MEMBERNAME_DESCRIPTION.get());
    addToGroupSubCmd.addArgument(addToGoupMemberNameArg);

    addToGroupGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_GROUPNAME_DESCRIPTION.get());
    addToGroupSubCmd.addArgument(addToGroupGroupNameArg);

    // remove-from-group
    removeFromGroupSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.REMOVE_FROM_GROUP.toString(),
        INFO_ADMIN_SUBCMD_REMOVE_FROM_GROUP_DESCRIPTION.get());
    subCommands.add(removeFromGroupSubCmd);

    removeFromGoupMemberNameArg = new StringArgument("memberName",
        OPTION_SHORT_MEMBERNAME, OPTION_LONG_MEMBERNAME, true, true,
        INFO_MEMBERNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_REMOVE_MEMBERNAME_DESCRIPTION.get());
    removeFromGroupSubCmd.addArgument(removeFromGoupMemberNameArg);

    removeFromGroupGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_GROUPNAME_DESCRIPTION.get());
    removeFromGroupSubCmd.addArgument(removeFromGroupGroupNameArg);


    // list-members
    listMembersSubCmd = new SubCommand(argParser,SubCommandNameEnum.LIST_MEMBERS
        .toString(), INFO_ADMIN_SUBCMD_LIST_MEMBERS_DESCRIPTION.get());
    subCommands.add(listMembersSubCmd);

    listMembersGroupNameArg = new StringArgument("groupName",
        OPTION_SHORT_GROUPNAME, OPTION_LONG_GROUPNAME, true, true,
        INFO_GROUPNAME_PLACEHOLDER.get(),
        INFO_ADMIN_ARG_GROUPNAME_DESCRIPTION.get());
    listMembersSubCmd.addArgument(listMembersGroupNameArg);

    // list-membership
    listMembershipSubCmd = new SubCommand(argParser,
        SubCommandNameEnum.LIST_MEMBERSHIP.toString(),
        INFO_ADMIN_SUBCMD_LIST_MEMBERSHIP_DESCRIPTION.get());
    subCommands.add(listMembershipSubCmd);

    listMembershipMemberNameArg = new StringArgument("memberName",
View Full Code Here

TOP

Related Classes of org.nasutekds.server.util.args.SubCommand

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.