/**
   * Services a Commandline Request.
   *
   * @param rc Request Context.
   * @throws CLIException if the request cannot serviced.
   */
  @Override
  public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String name = getStringOptionValue(PARAM_NAME);
    String[] params = {realm, name};
    Set<SubjectImplementation> newSubjects = getSubjects(rc);
    boolean bAdd = isOptionSet(PARAM_ADD);

    Subject userSubject = SubjectUtils.createSubject(getAdminSSOToken());
    ApplicationPrivilegeManager apm = ApplicationPrivilegeManager.getInstance(realm, userSubject);
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_APPLICATION_PRIVILEGE", params);

    try {
      ApplicationPrivilege appPrivilege = apm.getPrivilege(name);
      Set<SubjectImplementation> origSubjects = appPrivilege.getSubjects();
      Set<SubjectImplementation> subjects =
          (bAdd) ? mergeSubjects(origSubjects, newSubjects) : newSubjects;
      appPrivilege.setSubject(subjects);
      apm.replacePrivilege(appPrivilege);

      Object[] msgParam = {name};
      getOutputWriter()
          .printlnMessage(
              MessageFormat.format(
                  getResourceString("update-application-privilege-succeeded"), msgParam));
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_UPDATE_APPLICATION_PRIVILEGE", params);
    } catch (EntitlementException ex) {
      String[] paramExs = {realm, name, ex.getMessage()};
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_UPDATE_APPLICATION_PRIVILEGE", paramExs);
      throw new CLIException(ex, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
  }
  /**
   * Services a Commandline Request.
   *
   * @param rc Request Context.
   * @throws CLIException if the request cannot serviced.
   */
  @Override
  public void handleRequest(RequestContext rc) throws CLIException {
    super.handleRequest(rc);
    String realm = getStringOptionValue(IArgument.REALM_NAME);
    String name = getStringOptionValue(PARAM_NAME);
    String[] params = {realm, name};

    String description = getStringOptionValue(PARAM_DESCRIPTION);
    boolean hasDescription = (description != null) && description.trim().length() > 0;
    String actions = getStringOptionValue(PARAM_ACTIONS);
    ApplicationPrivilege.PossibleAction action = (actions != null) ? getActions() : null;

    if (!hasDescription && (action == null)) {
      throw new CLIException(
          getResourceString("update-application-privilege-invalid"),
          ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }

    Subject userSubject = SubjectUtils.createSubject(getAdminSSOToken());
    ApplicationPrivilegeManager apm = ApplicationPrivilegeManager.getInstance(realm, userSubject);
    writeLog(LogWriter.LOG_ACCESS, Level.INFO, "ATTEMPT_UPDATE_APPLICATION_PRIVILEGE", params);
    try {
      ApplicationPrivilege appPrivilege = apm.getPrivilege(name);

      if (hasDescription) {
        appPrivilege.setDescription(description);
      }
      if (action != null) {
        appPrivilege.setActionValues(action);
      }

      apm.replacePrivilege(appPrivilege);

      Object[] msgParam = {name};
      getOutputWriter()
          .printlnMessage(
              MessageFormat.format(
                  getResourceString("update-application-privilege-succeeded"), msgParam));
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "SUCCEEDED_UPDATE_APPLICATION_PRIVILEGE", params);
    } catch (EntitlementException ex) {
      String[] paramExs = {realm, name, ex.getMessage()};
      writeLog(LogWriter.LOG_ACCESS, Level.INFO, "FAILED_UPDATE_APPLICATION_PRIVILEGE", paramExs);
      throw new CLIException(ex, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
  }