Ejemplo n.º 1
0
  public static void removeApplication(String appPath) throws NotesException {

    Session session = null;
    Database dbUnplugged = null;

    String correctedPath = appPath.replace("\\", "/");

    Logger.debug("Remove Unplugged application for app at " + correctedPath);

    Configuration config = Configuration.get();

    // open unplugged db
    session = Utils.getCurrentSession();
    dbUnplugged = session.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

    // check if an app document for this app already exists and create it if not
    DocumentCollection dcApp =
        dbUnplugged.search("Form=\"UserDatabase\" & Path=\"" + correctedPath + "\"");

    if (dcApp.getCount() == 0) {
      Logger.warn("- Unplugged application document not found");

    } else if (dcApp.getCount() > 1) {
      Logger.error("- Multiple Unplugged application documents found: not removed");

    } else {

      Logger.info("- Unplugged add configuration found");

      dcApp.getFirstDocument().remove(true);
      Logger.info("- Unplugged app configuration removed");
    }
  }
Ejemplo n.º 2
0
 protected org.openntf.domino.Name testName(final String what, final NotesBug... notesbug)
     throws NotesException {
   Session s = Factory.getSession(SessionType.CURRENT);
   lotus.domino.Session ls = s.getFactory().toLotus(s);
   org.openntf.domino.Name o = s.createName(what);
   lotus.domino.Name n = ls.createName(what);
   compareNames(n.getCanonical(), n, o, notesbug);
   return o;
 }
Ejemplo n.º 3
0
  public static void removeUsersAndDevices(String alias) throws NotesException {

    Session session = null;
    Database dbUnplugged = null;

    String alias1 = "/" + alias.toLowerCase();
    String alias2 = "/o=" + alias.toLowerCase();

    Logger.debug("Remove Unplugged users and devices for alias \"" + alias + "\"");

    Configuration config = Configuration.get();

    // open unplugged db
    session = Utils.getCurrentSession();
    dbUnplugged = session.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

    // check if an app document for this app already exists and create it if not
    String q =
        "Form=\"User\":\"Device\" & ( @Contains(@LowerCase(UserName); \""
            + alias1
            + "\") | @Contains(@LowerCase(UserName); \""
            + alias2
            + "\") )";
    DocumentCollection dcApp = dbUnplugged.search(q);

    Logger.info("- finding users and devices with query: " + q);

    if (dcApp.getCount() == 0) {
      Logger.info("- No Unplugged users/ devices found");

    } else {

      Logger.info("- found " + dcApp.getCount() + " users and/or devices");

      Document doc = dcApp.getFirstDocument();
      while (null != doc) {

        Document t = dcApp.getNextDocument(doc);

        Logger.info(
            "- removing "
                + doc.getItemValueString("form")
                + " for "
                + doc.getItemValueString("UserName"));

        doc.remove(true);

        try {
          doc.recycle();
        } catch (Exception e) {

        }
        doc = t;
      }
    }
  }
Ejemplo n.º 4
0
  public static void createAppDefinition(String appPath, boolean hideFromWS, boolean autoLaunch) {

    Session sessionAsSigner = null;
    Database dbUnplugged = null;
    Document docApp = null;

    try {

      String correctedPath = appPath.replace("\\", "/");

      Logger.debug("create unplugged application " + correctedPath);

      Configuration config = Configuration.get();

      // open unplugged db
      sessionAsSigner = Utils.getCurrentSessionAsSigner();
      dbUnplugged =
          sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

      // check if an app document for this app already exists and create it if not
      DocumentCollection dcApp =
          dbUnplugged.search("Form=\"UserDatabase\" & Path=\"" + correctedPath + "\"");

      if (dcApp.getCount() == 0) {

        // create new app document
        Logger.debug("application not found: create new");

        docApp = dbUnplugged.createDocument();
        docApp.replaceItemValue("form", "UserDatabase");
        docApp.replaceItemValue("Path", correctedPath);

      } else {

        throw (new Exception("application for " + correctedPath + " already exists in Unplugged"));
      }

      docApp.replaceItemValue("Active", "1");
      docApp.replaceItemValue("ShowOnWS", (hideFromWS ? "no" : ""));
      docApp.replaceItemValue("AutoLaunchApp", (autoLaunch ? "yes" : ""));
      docApp.replaceItemValue("ReplAttachmentExts", ""); // send all attachments
      docApp.computeWithForm(true, true);
      docApp.save();

      Logger.debug("done");

    } catch (Exception e) {

      Logger.error(e);

    } finally {

      Utils.recycle(docApp, dbUnplugged);
    }
  }
Ejemplo n.º 5
0
 @Override
 public int executeCode(Session arg0, Database arg1) {
   try {
     setCurrentTaskStatus("Task started");
     setTaskCompletion(0);
     System.out.println(arg0.getCommonUserName());
     System.out.println(arg0.getEffectiveUserName());
     System.out.println(arg1.getFilePath());
     setCurrentTaskStatus("Task finished");
     setTaskCompletion(100);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return 0;
 }
Ejemplo n.º 6
0
  static {
    try {
      session = NotesFactory.createSession((String) null, (String) null, Authentication.getInfo());
      thisDb = session.getCurrentDatabase();

    } catch (NotesException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Ejemplo n.º 7
0
 /**
  * Whether or not the effective user of the Session has access to read logs
  *
  * @param session Session (remember you can use sessionAsSigner / sessionAsSignerWithFullAccess)
  * @return boolean whether user has access
  * @since org.openntf.domino.xsp 2.5.0
  */
 private boolean canReadLogs(final lotus.domino.Session session) {
   boolean result = false;
   try {
     String username = session.getEffectiveUserName();
     DominoServer server = new DominoServer();
     result = server.checkServerAccess(username, ServerAccess.PROG_UNRESTRICTED);
     result = result || server.checkServerAccess(username, ServerAccess.VIEW_ONLY_ADMIN);
   } catch (NotesException ne) {
     ne.printStackTrace();
   }
   return result;
 }
  /**
   * Registers the definitions at the XPage Scheduler.
   *
   * @param req
   * @param res
   * @throws SchedulerException
   */
  private void registerTransponder(final ServletRequest req, final ServletResponse res) {

    // the root of the definition is the META-INF/services file which MUST have a valid signature

    String clazzFile = "META-INF/services/" + TransponderData.class.getName();
    if (!setSigner(clazzFile)) return;

    NotesContext ctx = NotesContext.getCurrent();
    NSFComponentModule module = ctx.getRunningModule();

    String signer = null;
    try {
      Session signerSession = ctx.getSessionAsSigner();
      signer = signerSession.getEffectiveUserName();
    } catch (NotesException e) {
    }
    // here wo do some security checks (I like signers!)
    if (signer == null) {
      log_.severe("!!! The file " + module.getDatabasePath() + "/" + clazzFile + " is not signed!");
      TransponderRegistry.unRegister(module.getDatabasePath());

    } else {
      List<TransponderData> defs = ServiceLocator.findServices(TransponderData.class, Scope.NONE);
      // everything must be signed by the SAME user!!! - check it after loading all services
      if (ctx.getSessionAsSigner() == null) {
        log_.severe(
            "!!! One or more classes listed in "
                + module.getDatabasePath()
                + "/"
                + clazzFile
                + " are not properly signed!");
        TransponderRegistry.unRegister(module.getDatabasePath());
      } else {
        TransponderRegistry.register(module.getDatabasePath(), defs);
      }
    }
  }
  protected void execute(
      final String line, final boolean testLotus, final boolean testDoc, final boolean testMap) {
    // TODO Auto-generated method stub

    List<Object> ntfDocResult = null;
    List<Object> ntfMapResult = null;
    List<Object> lotusResult = null;
    Throwable ntfError = null;
    boolean lotusFailed = false;
    boolean parserFailed = false;
    // Setup procedure, prepare the demo docs & maps
    StringBuffer errors = new StringBuffer();

    double rnd = Math.random();
    Document ntfDoc = createDocument();
    Document lotusDoc = createDocument();
    Map<String, Object> ntfMap = new HashMap<String, Object>();

    fillDemoDoc(ntfDoc, rnd);
    fillDemoDoc(lotusDoc, rnd);
    fillDemoDoc(ntfMap, rnd);
    lotus.domino.Session rawSession = Factory.toLotus(Factory.getSession());
    lotus.domino.Document rawDocument = Factory.toLotus(lotusDoc);
    if (testLotus) {
      try {

        lotusResult = rawSession.evaluate(line, rawDocument);
      } catch (NotesException e) {
        errors.append(LOTUS("\tLotus failed: ") + ERROR(e) + "\n");
        lotusFailed = true;
      } catch (Throwable t) {
        System.err.println(ERROR("FATAL") + LOTUS("\tLotus failed: ") + ERROR(t));
      }
    }

    // benchmark the AtFormulaParser
    ASTNode ast = null;
    FormulaParser parser = Formulas.getParser();
    try {
      ast = parser.parse(line);
    } catch (FormulaParseException e) {
      errors.append(NTF("\tParser failed: ") + ERROR(e) + "\n");
      e.printStackTrace();
      parserFailed = true;
    } catch (Throwable t) {
      System.err.println(ERROR("FATAL") + NTF("\tParser failed: ") + ERROR(t));
      t.printStackTrace();
    }

    if (!parserFailed) {
      if (testDoc) {
        try {
          FormulaContext ctx1 = Formulas.createContext(ntfDoc, parser);
          ntfDocResult = ast.solve(ctx1);
        } catch (EvaluateException e) {
          errors.append(NTF("\tDoc-Evaluate failed: ") + ERROR(e) + "\n");
          ntfError = e;
          parserFailed = true;
        } catch (Throwable t) {
          System.err.println(ERROR("FATAL") + NTF("\tDoc-Evaluate failed: ") + ERROR(t));
          t.printStackTrace();
        }
      }
      if (testMap) {
        try {
          // benchmark the evaluate with a map as context
          FormulaContext ctx2 = Formulas.createContext(ntfMap, parser);
          ntfMapResult = ast.solve(ctx2);
        } catch (EvaluateException e) {
          errors.append(NTF("\tMap-Evaluate failed: ") + ERROR(e) + "\n");
          ntfError = e;
          parserFailed = true;
        } catch (Throwable t) {
          System.err.println(ERROR("FATAL") + NTF("\tMap-Evaluate failed: ") + ERROR(t));
          t.printStackTrace();
        }
      }
    }

    if (lotusFailed && parserFailed) {
      System.out.println(SUCCESS() + dump(line + " = UNDEFINED"));

      return;
    }

    if (testLotus && testDoc) {
      if (compareList(ntfDocResult, lotusResult)) {
        System.out.println(SUCCESS() + line + " = " + dump(ntfDocResult));
      } else {
        System.err.println(FAIL() + NTF("DOC:") + line);
        System.err.println(
            "\tResult:   "
                + dump(ntfDocResult)
                + " Size: "
                + ((ntfDocResult == null) ? 0 : ntfDocResult.size()));
        System.err.println(
            "\tExpected: "
                + dump(lotusResult)
                + " Size: "
                + ((lotusResult == null) ? 0 : lotusResult.size()));
        if (parserFailed || lotusFailed) {
          System.err.println(errors.toString());
          if (ntfError != null) {
            ntfError.printStackTrace(System.err);
          }
        }
        BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
        try {
          console.readLine();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    } else {
      if (parserFailed) {
        ntfError.printStackTrace();
      }
      System.err.println(
          "\tDocResult:   "
              + dump(ntfDocResult)
              + " Size: "
              + ((ntfDocResult == null) ? 0 : ntfDocResult.size()));
      System.err.println(
          "\tMapResult:   "
              + dump(ntfMapResult)
              + " Size: "
              + ((ntfMapResult == null) ? 0 : ntfMapResult.size()));
    }
    System.out.println(NTF("Read fields\t") + ast.getReadFields());
    System.out.println(NTF("Modified fields\t") + ast.getModifiedFields());
    System.out.println(NTF("Variables\t") + ast.getVariables());
    System.out.println(NTF("Functions\t") + ast.getFunctions());
  }
Ejemplo n.º 10
0
  /*
   * Reload the application configuration by reading the settings document
   */
  public void reload() {

    Database dbCurrent = null;
    View vwAllByType = null;
    Document docSettings = null;

    try {

      Session sessionAsSigner = Utils.getCurrentSessionAsSigner();
      dbCurrent = sessionAsSigner.getCurrentDatabase();
      vwAllByType = dbCurrent.getView("vwAllByType");

      docSettings = vwAllByType.getDocumentByKey("fSettings", true);

      if (docSettings == null) {

        System.out.println("could not read settings document");

      } else {

        String dataVersion = docSettings.getItemValueString("dataVersion");

        if (!dataVersion.equals(DATA_VERSION)) {

          convert(dataVersion, DATA_VERSION, dbCurrent, vwAllByType, docSettings);
        }

        serverName = dbCurrent.getServer();
        continuityDbPath = dbCurrent.getFilePath();
        continuityDbUrl = "/" + continuityDbPath.replace("\\", "/");

        settingsUnid = docSettings.getUniversalID();
        organisationName = docSettings.getItemValueString("organisationName");
        organisationId = docSettings.getItemValueString("organisationId");
        directoryDbPath = docSettings.getItemValueString("directoryDbPath");
        unpluggedDbPath = docSettings.getItemValueString("unpluggedDbPath");

        callTreeType = docSettings.getItemValueString("callTreeType");

        if (callTreeType.length() == 0) {
          callTreeType = CALLTREE_TYPE_ROLE; // default: role based
        }

        senderEmail = docSettings.getItemValueString("senderEmail");
        senderName = docSettings.getItemValueString("senderName");

        // defaults
        if (senderEmail.length() == 0) {
          senderEmail = "*****@*****.**";
        }
        if (senderName.length() == 0) {
          senderName = "Continuity";
        }

        // labels
        String riskNaming = docSettings.getItemValueString("riskNaming");
        String incidentNaming = docSettings.getItemValueString("incidentNaming");

        if (riskNaming.equals("activities")) {
          labels.put("assets", "Activities");
          labels.put("asset", "Activity");
        } else if (riskNaming.equals("sites")) {
          labels.put("assets", "Sites");
          labels.put("asset", "Site");
        } else if (riskNaming.equals("locations")) {
          labels.put("assets", "Locations");
          labels.put("asset", "Location");
        } else {
          labels.put("assets", "Assets");
          labels.put("asset", "Asset");
        }

        if (incidentNaming.equals("crises")) {
          labels.put("incidents", "Crises");
          labels.put("incident", "Crisis");
        } else if (incidentNaming.equals("emergencies")) {
          labels.put("incidents", "Emergencies");
          labels.put("incident", "Emergency");
        } else {
          labels.put("incidents", "Incidents");
          labels.put("incident", "Incident");
        }

        labels.put("miniConfigGuide", getMiniConfigGuide());
        labels.put("contactsImportGuide", getContactsImportGuide());
      }

    } catch (Exception e) {
      e.printStackTrace();
    } finally {

      Utils.recycle(docSettings, vwAllByType, dbCurrent);
    }
  }
Ejemplo n.º 11
0
  // removes the specified applications for the user from Unplugged
  @SuppressWarnings("unchecked")
  public static void deleteApplication(String userName, Vector<String> appPaths) {

    Session sessionAsSigner = null;
    Database dbUnplugged = null;
    Document docUser = null;
    View vwUsers = null;
    Name nmUser = null;
    Document docApp = null;

    try {

      Configuration config = Configuration.get();

      // open unplugged db
      sessionAsSigner = Utils.getCurrentSessionAsSigner();
      dbUnplugged =
          sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

      nmUser = sessionAsSigner.createName(userName);

      // get all application documents for this user
      DocumentCollection dcApp =
          dbUnplugged.search("Form=\"UserDatabase\" & @IsMember(\"" + userName + "\"; UserName)");

      Document docTemp = null;

      int numRemoved = 0;

      // update app documents
      docApp = dcApp.getFirstDocument();
      while (null != docApp) {

        String path = docApp.getItemValueString("Path");

        if (appPaths.contains(path)) {
          // remove application
          Vector<String> appUsers = docApp.getItemValue("UserName");

          Logger.debug(nmUser.getCanonical() + " is a user for " + path + " - removing");

          appUsers.remove(nmUser.getCanonical());
          docApp.replaceItemValue("UserName", appUsers);
          docApp.computeWithForm(true, true);
          docApp.save();

          numRemoved++;
        }

        docTemp = dcApp.getNextDocument(docApp);
        docApp.recycle();
        docApp = docTemp;
      }

      if (numRemoved == dcApp.getCount()) { // user removed from all apps - remove user config

        Logger.info(
            "Unplugged user "
                + nmUser.getCanonical()
                + " removed from all applications - remove user config");

        // check for user account
        vwUsers = dbUnplugged.getView(USERS_VIEW);
        docUser = vwUsers.getDocumentByKey(nmUser.getAbbreviated(), true);

        if (docUser != null) {
          docUser.remove(true);
          Logger.info("removed Unplugged user " + nmUser.getCanonical());
        }
      }

    } catch (Exception e) {
      Logger.error(e);
    } finally {

      Utils.recycle(docUser, nmUser, dbUnplugged, sessionAsSigner);
    }
  }
Ejemplo n.º 12
0
  /*
   * Create an Unplugged application definition in the Unplugged database
   * and add the specified user to it. The user is created if Unplugged
   * if he doesn't exist yet.
   */
  @SuppressWarnings("unchecked")
  public static boolean createApplication(String userName, String appPath, boolean isActive) {

    Session sessionAsSigner = null;
    Database dbUnplugged = null;
    Document docApp = null;
    Document docUser = null;
    View vwUsers = null;
    Name nmUser = null;

    try {

      String correctedPath = appPath.replace("\\", "/");

      Logger.debug("create unplugged application " + correctedPath + " for " + userName);

      Configuration config = Configuration.get();

      // open unplugged db
      sessionAsSigner = Utils.getCurrentSessionAsSigner();
      dbUnplugged =
          sessionAsSigner.getDatabase(config.getServerName(), config.getUnpluggedDbPath());

      // create notes name object for user
      nmUser = sessionAsSigner.createName(userName);

      // check if user already exists in Unplugged
      vwUsers = dbUnplugged.getView(USERS_VIEW);
      docUser = vwUsers.getDocumentByKey(nmUser.getAbbreviated(), true);

      if (docUser == null) {

        // user doesn't exist yet: create
        Unplugged.createUser(dbUnplugged, nmUser.getCanonical(), isActive);

      } else if (docUser.getItemValueString("Active").equals("1") && !isActive) {

        // mark user as inactive
        docUser.replaceItemValue("Active", "0");
        docUser.save();

      } else if (!docUser.getItemValueString("Active").equals("1") && isActive) {

        // mark user as active
        docUser.replaceItemValue("Active", "1");
        docUser.save();
      }

      // check if an app document for this app already exists and create it if not
      DocumentCollection dcApp =
          dbUnplugged.search("Form=\"UserDatabase\" & Path=\"" + correctedPath + "\"");

      if (dcApp.getCount() == 0) {

        // create new app document
        Logger.debug("application not found: create new");

        docApp = dbUnplugged.createDocument();
        docApp.replaceItemValue("form", "UserDatabase");
        docApp.replaceItemValue("Path", correctedPath);

      } else {

        // update existing app document
        docApp = dcApp.getFirstDocument();
      }

      Vector<String> appUsers = docApp.getItemValue("UserName");

      if (!appUsers.contains(nmUser.getCanonical())) {

        Logger.debug(nmUser.getCanonical() + " not in list of application users: adding");

        appUsers.add(nmUser.getCanonical());
        docApp.replaceItemValue("UserName", appUsers);
        docApp.replaceItemValue("Active", "1");
        docApp.computeWithForm(true, true);
        docApp.save();
      }

      Logger.debug("done");

    } catch (NotesException e) {

      Logger.error(e);
    } finally {

      Utils.recycle(docUser, docApp, nmUser, dbUnplugged);
    }

    return true;
  }