/** Create LockssKeystore from a config subtree */
  LockssKeyStore createLockssKeyStore(Configuration config) {
    log.debug2("Creating LockssKeyStore from config: " + config);
    String name = config.get(KEYSTORE_PARAM_NAME);
    LockssKeyStore lk = new LockssKeyStore(name);

    String file = config.get(KEYSTORE_PARAM_FILE);
    String resource = config.get(KEYSTORE_PARAM_RESOURCE);
    String url = config.get(KEYSTORE_PARAM_URL);

    if (!StringUtil.isNullString(file)) {
      lk.setLocation(file, LocationType.File);
    } else if (!StringUtil.isNullString(resource)) {
      lk.setLocation(resource, LocationType.Resource);
    } else if (!StringUtil.isNullString(url)) {
      lk.setLocation(url, LocationType.Url);
    }

    lk.setType(config.get(KEYSTORE_PARAM_TYPE, defaultKeyStoreType));
    lk.setProvider(config.get(KEYSTORE_PARAM_PROVIDER, defaultKeyStoreProvider));
    lk.setPassword(config.get(KEYSTORE_PARAM_PASSWORD));
    lk.setKeyPassword(config.get(KEYSTORE_PARAM_KEY_PASSWORD));
    lk.setKeyPasswordFile(config.get(KEYSTORE_PARAM_KEY_PASSWORD_FILE));
    lk.setMayCreate(config.getBoolean(KEYSTORE_PARAM_CREATE, DEFAULT_CREATE));
    return lk;
  }
 void setConfig(Configuration config) {
   log.debug("config: " + config);
   proxyHost = config.get(PARAM_PROXY_HOST);
   proxyPort = config.getInt(PARAM_PROXY_PORT, DEFAULT_PROXY_PORT);
   if (StringUtil.isNullString(proxyHost) || proxyPort <= 0) {
     String http_proxy = System.getenv("http_proxy");
     if (!StringUtil.isNullString(http_proxy)) {
       try {
         HostPortParser hpp = new HostPortParser(http_proxy);
         proxyHost = hpp.getHost();
         proxyPort = hpp.getPort();
       } catch (HostPortParser.InvalidSpec e) {
         log.warning("Can't parse http_proxy environment var, ignoring: " + http_proxy + ": " + e);
       }
     }
   }
   if (StringUtil.isNullString(proxyHost) || proxyPort <= 0) {
     proxyHost = null;
   } else {
     log.info("Proxying through " + proxyHost + ":" + proxyPort);
   }
   userAgent = config.get(PARAM_USER_AGENT);
   if (StringUtil.isNullString(userAgent)) {
     userAgent = null;
   } else {
     log.debug("Setting User-Agent to " + userAgent);
   }
 }
 /** Concatenate params for URL string */
 static String concatParams(String p1, String p2) {
   if (StringUtil.isNullString(p1)) {
     return p2;
   }
   if (StringUtil.isNullString(p2)) {
     return p1;
   }
   return p1 + "&" + p2;
 }
  /**
   * Did the client provide the minimal parameters required?
   *
   * @return true If so
   */
  private boolean verifyMinimumParameters() {
    int count = 0;

    if (!StringUtil.isNullString(getParameter(AP_E_PUBLICATION))) count++;
    if (!StringUtil.isNullString(getParameter(AP_E_CLASSNAME))) count++;
    if (!StringUtil.isNullString(getParameter(AP_E_PLUGIN))) count++;

    return (count > 0);
  }
  /**
   * Decide whether the current title record should be displayed, based on whether it is a duplicate
   * of the previous record, given the combination of output fields included in the ordering. If
   * range fields are included in the output, or if identifying properties change between titles,
   * the title will be shown.
   *
   * <p>If there are neither range fields nor id fields in the output, we can't tell if it is a
   * duplicate so we show it anyway. Output with no id fields is pretty meaningless though.
   *
   * <p>Note that the method also sets the last output title if the response is true. Thus calling
   * this method multiple times on the same title will give false after the first (unless there are
   * no identifying fields).
   *
   * @param currentTitle the current title
   * @return whether to show currentTitle
   */
  public boolean isTitleForOutput(KbartTitle currentTitle) {
    // The approach is to trueify this variable. If it becomes true, at the
    // end of the method the lastOutputTitle is set before the result is
    // returned. Do not return early!
    boolean isOutput = false;
    // Show title if it has no range or id fields by which we can decide duplicates
    if (!rangeFieldsIncludedInDisplay && !idFieldsIncludedInDisplay) {
      isOutput = true;
    }

    // Show the title if it is the first or the output includes range fields
    if (lastOutputTitle == null || rangeFieldsIncludedInDisplay) {
      isOutput = true;
    } else if (!isOutput) { // don't do this check if we've already trueified the var
      // At this point there are no range fields and this is not the first title
      // Show the title if any visible idField differs between titles
      for (Field f : idFields) {
        if (visibleColumnOrdering.getFields().contains(f)
            && !lastOutputTitle.getField(f).equals(currentTitle.getField(f))) {
          isOutput = true;
          break;
        }
      }
    }
    // Finally, we refuse to output the title if it has no id and
    // excludeNoIdTitles is true.
    if (excludeNoIdTitles && StringUtil.isNullString(currentTitle.getField(Field.TITLE_ID)))
      isOutput = false;

    // Record the previous title
    if (isOutput) lastOutputTitle = currentTitle;
    return isOutput;
  }
  /**
   * A target system is required to create an AU - was it provided?
   *
   * @return true If at least one target was specified
   */
  private boolean verifyTarget() {
    if (!isCreateCommand()) {
      return true;
    }

    return !StringUtil.isNullString(getParameter(AP_E_TARGET));
  }
 /**
  * Add javascript to page. Normally adds a link to the script file, but can be told to include the
  * script directly in the page, to accomodate unit testing of individual servlets, when other
  * fetches won't work.
  */
 protected void addJavaScript(Composite comp) {
   String include = (String) context.getAttribute(ATTR_INCLUDE_SCRIPT);
   if (StringUtil.isNullString(include)) {
     linkToJavaScript(comp);
   } else {
     includeJavaScript0(comp);
   }
 }
Example #8
0
 /**
  * Create a response that maps the event to the named new state.
  *
  * @param event the pattern event against which incoming events are matched
  * @param newState name of state to transition to if matching event is signalled.
  */
 public PsmResponse(PsmEvent event, String newState) {
   if (event == null) {
     throw new PsmException.IllegalStateMachine("event is null");
   }
   if (StringUtil.isNullString(newState)) {
     throw new PsmException.IllegalStateMachine("newState is null string");
   }
   this.event = event;
   this.newState = newState;
 }
Example #9
0
 ArchivalUnit getAu() {
   if (StringUtil.isNullString(formAuid)) {
     errMsg = "Select an AU";
     return null;
   }
   ArchivalUnit au = pluginMgr.getAuFromId(formAuid);
   if (au == null) {
     errMsg = "No such AU.  Select an AU";
     return null;
   }
   return au;
 }
Example #10
0
 /** Concatenate params for URL string */
 String concatParams(Properties props) {
   if (props == null) {
     return null;
   }
   java.util.List list = new ArrayList();
   for (Iterator iter = props.keySet().iterator(); iter.hasNext(); ) {
     String key = (String) iter.next();
     String val = props.getProperty(key);
     if (!StringUtil.isNullString(val)) {
       list.add(key + "=" + urlEncode(val));
     }
   }
   return StringUtil.separatedString(list, "&");
 }
Example #11
0
 /**
  * Return a (possibly labelled) checkbox.
  *
  * @param label appears to right of checkbox if non null
  * @param value value included in result set if box checked
  * @param key form key to which result set is assigned
  * @param checked if true, box is initially checked
  * @return a checkbox Element
  */
 Element checkBox(String label, String value, String key, boolean checked) {
   Input in = new Input(Input.Checkbox, key, value);
   if (checked) {
     in.check();
   }
   setTabOrder(in);
   if (StringUtil.isNullString(label)) {
     return in;
   } else {
     Composite c = new Composite();
     c.add(in);
     c.add(" ");
     c.add(label);
     return c;
   }
 }
  /**
   * Are all of the "defining parameters" required to create an AU available?
   *
   * @return true If so
   */
  private boolean verifyDefiningParameters() {
    KeyedList parameters;
    int size;

    if (!isCreateCommand()) {
      return true;
    }

    parameters = ParseUtils.getDynamicFields(getXmlUtils(), getRequestDocument(), AP_MD_AUDEFINING);
    size = parameters.size();

    for (int i = 0; i < size; i++) {
      if (StringUtil.isNullString((String) parameters.getValue(i))) {
        return false;
      }
    }
    return true;
  }
 void checkParamAgreement(String key, PrintfContext context) {
   List<String> printfList = getElementList(key);
   if (printfList == null) {
     return;
   }
   for (String printf : printfList) {
     if (StringUtil.isNullString(printf)) {
       log.warning("Null printf string in " + key);
       continue;
     }
     PrintfUtil.PrintfData p_data = PrintfUtil.stringToPrintf(printf);
     Collection<String> p_args = p_data.getArguments();
     for (String arg : p_args) {
       ConfigParamDescr descr = findAuConfigDescr(arg);
       if (descr == null) {
         throw new PluginException.InvalidDefinition(
             "Not a declared parameter: " + arg + " in " + printf + " in " + getPluginName());
       }
       // ensure range and set params used only in legal context
       switch (context) {
         case Regexp:
         case Display:
           // everything is legal in a regexp or a display string
           break;
         case URL:
           // NUM_RANGE and SET legal because can enumerate.  Can't
           // enumerate RANGE
           switch (descr.getType()) {
             case ConfigParamDescr.TYPE_RANGE:
               throw new PluginException.InvalidDefinition(
                   "Range parameter ("
                       + arg
                       + ") used in illegal context in "
                       + getPluginName()
                       + ": "
                       + key
                       + ": "
                       + printf);
             default:
           }
       }
     }
   }
 }
 /** If in testing mode FOO, copy values from FOO_override map, if any, to main map */
 void processOverrides(TypedEntryMap map) {
   String testMode = getTestingMode();
   if (StringUtil.isNullString(testMode)) {
     return;
   }
   Object o = map.getMapElement(testMode + DefinableArchivalUnit.SUFFIX_OVERRIDE);
   if (o == null) {
     return;
   }
   if (o instanceof Map) {
     Map overrideMap = (Map) o;
     for (Map.Entry entry : (Set<Map.Entry>) overrideMap.entrySet()) {
       String key = (String) entry.getKey();
       Object val = entry.getValue();
       log.debug(getDefaultPluginName() + ": Overriding " + key + " with " + val);
       map.setMapElement(key, val);
     }
   }
 }
Example #15
0
 void insertMatchButton_actionPerformed(ActionEvent e) {
   String key = (String) matchComboBox.getSelectedItem();
   String format = (String) matchesKeys.get(key);
   if (key.equals(STRING_LITERAL)) {
     format =
         escapeReservedChars(
             (String)
                 JOptionPane.showInputDialog(
                     this,
                     "Enter the string you wish to match",
                     "String Literal Input",
                     JOptionPane.OK_CANCEL_OPTION));
     if (StringUtil.isNullString(format)) {
       return;
     }
   }
   if (selectedPane == 0) {
     insertText(format, PLAIN_ATTR, editorPane.getSelectionStart());
   } else {
     // add the combobox data value to the edit box
     int pos = formatTextArea.getCaretPosition();
     formatTextArea.insert(format, pos);
   }
 }
  private void checkFact(Object fact, String name, String criticalServiceName, String message) {
    if (fact == null && criticalServiceName != null) {
      String msg =
          StringUtil.isNullString(name)
              ? ("No keystore name given for critical keystore"
                  + " needed for service "
                  + criticalServiceName
                  + ", daemon exiting")
              : ("Critical keystore "
                  + name
                  + " "
                  + ((message != null) ? message : "not found or not loadable")
                  + " for service "
                  + criticalServiceName
                  + ", daemon exiting");
      log.critical(msg);

      if (paramExitIfMissingKeyStore) {
        System.exit(Constants.EXIT_CODE_KEYSTORE_MISSING);
      } else {
        throw new IllegalArgumentException(msg);
      }
    }
  }
Example #17
0
  /**
   * Provides the status information of an archival unit in the system.
   *
   * @param auId A String with the identifier of the archival unit.
   * @return an AuStatus with the status information of the archival unit.
   * @throws LockssWebServicesFault
   */
  AuStatus getAuStatus(String auId) throws LockssWebServicesFault {
    final String DEBUG_HEADER = "getAuStatus(): ";

    LockssDaemon theDaemon = LockssDaemon.getLockssDaemon();
    PluginManager pluginMgr = theDaemon.getPluginManager();
    ArchivalUnit au = pluginMgr.getAuFromId(auId);

    if (au == null) {
      throw new LockssWebServicesFault(
          "No Archival Unit with provided identifier",
          new LockssWebServicesFaultInfo("Archival Unit identifier = " + auId));
    }

    AuStatus result = new AuStatus();
    result.setVolume(au.getName());

    TitleConfig tc = au.getTitleConfig();
    if (tc != null) {
      result.setJournalTitle(tc.getJournalTitle());
    }

    Plugin plugin = au.getPlugin();
    result.setPluginName(plugin.getPluginName());

    result.setYear(AuUtil.getTitleAttribute(au, "year"));

    NodeManager nodeMgr = theDaemon.getNodeManager(au);
    AuState state = nodeMgr.getAuState();
    AuState.AccessType atype = state.getAccessType();

    if (atype != null) {
      result.setAccessType(atype.toString());
    }

    long contentSize = AuUtil.getAuContentSize(au, false);

    if (contentSize != -1) {
      result.setContentSize(contentSize);
    }

    long du = AuUtil.getAuDiskUsage(au, false);

    if (du != -1) {
      result.setDiskUsage(du);
    }

    String spec = LockssRepositoryImpl.getRepositorySpec(au);
    String repo =
        LockssRepositoryImpl.mapAuToFileLocation(
            LockssRepositoryImpl.getLocalRepositoryPath(spec), au);
    result.setRepository(repo);

    CachedUrlSet auCus = au.getAuCachedUrlSet();
    NodeState topNode = nodeMgr.getNodeState(auCus);

    if (AuUtil.getProtocolVersion(au) == Poll.V3_PROTOCOL) {
      if (state.getV3Agreement() < 0) {
        if (state.getLastCrawlTime() < 0) {
          result.setStatus("Waiting for Crawl");
        } else {
          result.setStatus("Waiting for Poll");
        }
      } else {
        result.setStatus(doubleToPercent(state.getHighestV3Agreement()) + "% Agreement");
        if (state.getHighestV3Agreement() != state.getV3Agreement()) {
          result.setRecentPollAgreement(state.getV3Agreement());
        }
      }
    } else {
      result.setStatus(topNode.hasDamage() ? "Repairing" : "Ok");
    }

    String publishingPlatform = plugin.getPublishingPlatform();

    if (!StringUtil.isNullString(publishingPlatform)) {
      result.setPublishingPlatform(publishingPlatform);
    }

    String publisher = AuUtil.getTitleAttribute(au, "publisher");

    if (!StringUtil.isNullString(publisher)) {
      result.setPublisher(publisher);
    }

    result.setAvailableFromPublisher(!AuUtil.isPubDown(au));
    result.setSubstanceState(state.getSubstanceState().toString());
    result.setCreationTime(state.getAuCreationTime());

    AuUtil.AuProxyInfo aupinfo = AuUtil.getAuProxyInfo(au);

    if (aupinfo.isAuOverride()) {
      String disp =
          (aupinfo.getHost() == null
              ? "Direct connection"
              : aupinfo.getHost() + ":" + aupinfo.getPort());
      result.setCrawlProxy(disp);
    }

    CrawlWindow window = au.getCrawlWindow();

    if (window != null) {
      String wmsg = window.toString();

      if (wmsg.length() > 140) {
        wmsg = "(not displayable)";
      }

      if (!window.canCrawl()) {
        wmsg = "Currently closed: " + wmsg;
      }

      result.setCrawlWindow(wmsg);
    }

    String crawlPool = au.getFetchRateLimiterKey();

    if (crawlPool == null) {
      crawlPool = "(none)";
    }

    result.setCrawlPool(crawlPool);

    result.setLastCompletedCrawl(state.getLastCrawlTime());

    long lastCrawlAttempt = state.getLastCrawlAttempt();

    if (lastCrawlAttempt > 0) {
      result.setLastCrawl(lastCrawlAttempt);
      result.setLastCrawlResult(state.getLastCrawlResultMsg());
    }

    long lastTopLevelPollTime = state.getLastTopLevelPollTime();

    if (lastTopLevelPollTime > 0) {
      result.setLastCompletedPoll(lastTopLevelPollTime);
    }

    long lastPollStart = state.getLastPollStart();

    if (lastPollStart > 0) {
      result.setLastPoll(lastPollStart);
      String pollResult = state.getLastPollResultMsg();

      if (!StringUtil.isNullString(pollResult)) {
        result.setLastPollResult(state.getLastPollResultMsg());
      }
    }

    result.setCurrentlyCrawling(
        theDaemon.getCrawlManager().getStatusSource().getStatus().isRunningNCCrawl(au));

    result.setCurrentlyPolling(theDaemon.getPollManager().isPollRunning(au));

    if (theDaemon.isDetectClockssSubscription()) {
      result.setSubscriptionStatus(AuUtil.getAuState(au).getClockssSubscriptionStatusString());
    }

    if (log.isDebug2()) log.debug2(DEBUG_HEADER + "result = " + result);
    return result;
  }
  /** Query the daemon for information required to set up this command */
  private boolean commandSetup() {

    Configuration configuration = null;
    Collection noEditKeys = null;
    String key;
    String value;

    /*
     * Configure a well known publication?
     */
    if ((value = getParameter(AP_E_PUBLICATION)) != null) {
      PluginProxy plugin = getTitlePlugin(value);

      /*
       * Set plugin and Title configuration information
       */
      if (plugin == null) {
        String message = "Unknown Publication:" + value;

        log.warning(message);
        return error(message);
      }

      setPlugin(plugin);
      setTitleConfig(plugin.getTitleConfig(value));

      configuration = getTitleConfig().getConfig();
      noEditKeys = getNoEditKeys();

    } else {
      /*
       * Lookup by Plugin or Class name - set the plugin
       *
       * NB: As of 23-Feb-04, this is not supported from AddAuPage.java.  See
       *     AddAuWithCompleteFunctionalityPage.java for full support.
       */
      if ((value = getParameter(AP_E_PLUGIN)) != null) {
        key = RemoteApi.pluginKeyFromId(value);

      } else if ((value = getParameter(AP_E_CLASSNAME)) != null) {
        key = RemoteApi.pluginKeyFromId(value);

      } else {
        return error("Supply a Publication, Plugin, or Class name");
      }

      if (StringUtil.isNullString(key)) {
        return error("Supply a valid Publication, Plugin, or Class name");
      }

      if (!pluginLoaded(key)) {
        return error("Plugin is not loaded: " + key);
      }

      setPlugin(getPluginProxy(key));
    }

    /*
     * Finally, return an XML rendition of the Plugin and AU key set up
     */
    generateSetupXml(configuration, noEditKeys);
    return true;
  }
Example #19
0
  public void lockssHandleRequest() throws IOException {
    resetVars();
    boolean showForm = true;
    String action = getParameter(KEY_ACTION);

    if (!StringUtil.isNullString(action)) {

      formAuid = getParameter(KEY_AUID);
      formDepth = getParameter(KEY_REFETCH_DEPTH);

      UserAccount acct = getUserAccount();
      if (acct != null && !noAuditActions.contains(action)) {
        acct.auditableEvent("used debug panel action: " + action + " AU ID: " + formAuid);
      }
    }

    if (ACTION_MAIL_BACKUP.equals(action)) {
      doMailBackup();
    }
    if (ACTION_RELOAD_CONFIG.equals(action)) {
      doReloadConfig();
    }
    if (ACTION_SLEEP.equals(action)) {
      doSleep();
    }
    if (ACTION_THROW_IOEXCEPTION.equals(action)) {
      doThrow();
    }
    if (ACTION_START_V3_POLL.equals(action)) {
      doV3Poll();
    }
    if (ACTION_FORCE_START_V3_POLL.equals(action)) {
      forceV3Poll();
    }
    if (ACTION_START_CRAWL.equals(action)) {
      doCrawl(false, false);
    }
    if (ACTION_FORCE_START_CRAWL.equals(action)) {
      doCrawl(true, false);
    }
    if (ACTION_START_DEEP_CRAWL.equals(action)) {
      doCrawl(false, true);
    }
    if (ACTION_FORCE_START_DEEP_CRAWL.equals(action)) {
      doCrawl(true, true);
    }
    if (ACTION_CHECK_SUBSTANCE.equals(action)) {
      doCheckSubstance();
    }
    if (ACTION_CRAWL_PLUGINS.equals(action)) {
      crawlPluginRegistries();
    }
    if (ACTION_FIND_URL.equals(action)) {
      showForm = doFindUrl();
    }
    if (ACTION_REINDEX_METADATA.equals(action)) {
      doReindexMetadata();
    }
    if (ACTION_FORCE_REINDEX_METADATA.equals(action)) {
      forceReindexMetadata();
    }
    if (ACTION_DISABLE_METADATA_INDEXING.equals(action)) {
      doDisableMetadataIndexing();
    }
    if (showForm) {
      displayPage();
    }
  }
Example #20
0
  void insertButton_actionPerformed(ActionEvent e) {
    Object selected = paramComboBox.getSelectedItem();
    ConfigParamDescr descr;
    String key;
    int type = 0;
    String format = "";
    if (selected instanceof ConfigParamDescr) {
      descr = (ConfigParamDescr) selected;
      key = descr.getKey();
      type = descr.getType();
      switch (type) {
        case ConfigParamDescr.TYPE_STRING:
        case ConfigParamDescr.TYPE_URL:
        case ConfigParamDescr.TYPE_BOOLEAN:
          format = "%s";
          break;
        case ConfigParamDescr.TYPE_INT:
        case ConfigParamDescr.TYPE_LONG:
        case ConfigParamDescr.TYPE_POS_INT:
          NumericPaddingDialog dialog = new NumericPaddingDialog();
          Point pos = this.getLocationOnScreen();
          dialog.setLocation(pos.x, pos.y);
          dialog.pack();
          dialog.setVisible(true);
          StringBuilder fbuf = new StringBuilder("%");
          int width = dialog.getPaddingSize();
          boolean is_zero = dialog.useZero();
          if (width > 0) {
            fbuf.append(".");
            if (is_zero) {
              fbuf.append(0);
            }
            fbuf.append(width);
          }
          if (type == ConfigParamDescr.TYPE_LONG) {
            fbuf.append("ld");
          } else {
            fbuf.append("d");
          }
          format = fbuf.toString();
          break;
        case ConfigParamDescr.TYPE_YEAR:
          if (key.startsWith(DefinableArchivalUnit.PREFIX_AU_SHORT_YEAR)) {
            format = "%02d";
          } else {
            format = "%d";
          }
          break;
        case ConfigParamDescr.TYPE_RANGE:
        case ConfigParamDescr.TYPE_NUM_RANGE:
        case ConfigParamDescr.TYPE_SET:
          format = "%s";
          break;
      }
      if (selectedPane == 0) {
        insertParameter(descr, format, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        int pos = formatTextArea.getCaretPosition();
        formatTextArea.insert(format, pos);

        pos = parameterTextArea.getCaretPosition();
        parameterTextArea.insert(", " + key, pos);
      }
    } else {
      key = selected.toString();
      format =
          escapePrintfChars(
              (String)
                  JOptionPane.showInputDialog(
                      this,
                      "Enter the string you wish to input",
                      "String Literal Input",
                      JOptionPane.OK_CANCEL_OPTION));
      if (StringUtil.isNullString(format)) {
        return;
      }
      if (selectedPane == 0) {
        insertText(format, PLAIN_ATTR, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        formatTextArea.insert(format, formatTextArea.getCaretPosition());
      }
    }
  }
Example #21
0
  /** Common request handling. */
  public void service(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    resetState();
    boolean success = false;
    HttpSession session = req.getSession(false);
    try {
      this.req = req;
      this.resp = resp;
      if (log.isDebug()) {
        logParams();
      }
      resp.setContentType("text/html");

      if (!mayPageBeCached()) {
        resp.setHeader("pragma", "no-cache");
        resp.setHeader("Cache-control", "no-cache");
      }

      reqURL = new URL(UrlUtil.getRequestURL(req));
      clientAddr = getLocalIPAddr();

      // check that current user has permission to run this servlet
      if (!isServletAllowed(myServletDescr())) {
        displayWarningInLieuOfPage("You are not authorized to use " + myServletDescr().heading);
        return;
      }

      // check whether servlet is disabled
      String reason = ServletUtil.servletDisabledReason(myServletDescr().getServletName());
      if (reason != null) {
        displayWarningInLieuOfPage("This function is disabled. " + reason);
        return;
      }
      if (session != null) {
        session.setAttribute(SESSION_KEY_RUNNING_SERVLET, getHeading());
        String reqHost = req.getRemoteHost();
        String forw = req.getHeader(HttpFields.__XForwardedFor);
        if (!StringUtil.isNullString(forw)) {
          reqHost += " (proxies for " + forw + ")";
        }
        session.setAttribute(SESSION_KEY_REQUEST_HOST, reqHost);
      }
      lockssHandleRequest();
      success = (errMsg == null);
    } catch (ServletException e) {
      log.error("Servlet threw", e);
      throw e;
    } catch (IOException e) {
      log.error("Servlet threw", e);
      throw e;
    } catch (RuntimeException e) {
      log.error("Servlet threw", e);
      throw e;
    } finally {
      if (session != null) {
        session.setAttribute(SESSION_KEY_RUNNING_SERVLET, null);
        session.setAttribute(LockssFormAuthenticator.__J_AUTH_ACTIVITY, TimeBase.nowMs());
      }
      if ("please".equalsIgnoreCase(req.getHeader("X-Lockss-Result"))) {
        log.debug3("X-Lockss-Result: " + (success ? "Ok" : "Fail"));
        resp.setHeader("X-Lockss-Result", success ? "Ok" : "Fail");
      }
      resetMyLocals();
      resetLocals();
    }
  }
Example #22
0
 protected boolean hasNoRoleParsm(String roleName) {
   String noRoleParam = noRoleParams.get(roleName);
   return (noRoleParam != null && !StringUtil.isNullString(req.getParameter(noRoleParam)));
 }