/**
   * 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);
    }
  }