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

    try {
      Map<String, Set<String>> mapAppToResources = getApplicationResourcesMap(rc, realm);
      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);

      ApplicationPrivilege appPrivilege = apm.getPrivilege(name);
      Map<String, Set<String>> origAppToResources = getApplicationToResources(appPrivilege);
      Map map = (bAdd) ? mergeMap(origAppToResources, mapAppToResources) : mapAppToResources;
      appPrivilege.setApplicationResources(map);
      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);
    }
  }