// Change the component section and save it to disk
  private void setSection(final String section, ODocument sectionDoc) {

    ODocument oldSection = getSection(section);
    try {
      if (configDoc != null) {

        configDoc.field(section, sectionDoc);
        String configFile =
            OSystemVariableResolver.resolveSystemVariables("${ORIENTDB_HOME}/config/security.json");

        // The default "security.json" file can be overridden in the server config file.
        String securityFile = getConfigProperty("server.security.file");
        if (securityFile != null) configFile = securityFile;

        String ssf = OGlobalConfiguration.SERVER_SECURITY_FILE.getValueAsString();
        if (ssf != null) configFile = ssf;

        File f = new File(configFile);
        OIOUtils.writeFile(f, configDoc.toJSON("prettyPrint"));
      }
    } catch (Exception ex) {
      configDoc.field(section, oldSection);
      OLogManager.instance()
          .error(
              this,
              "ODefaultServerSecurity.setSection(%s) Exception: %s",
              section,
              ex.getMessage());
    }
  }
Example #2
0
  public static void installCustomFormatter() {
    final boolean installCustomFormatter =
        Boolean.parseBoolean(
            OSystemVariableResolver.resolveSystemVariables(
                "${" + ENV_INSTALL_CUSTOM_FORMATTER + "}", "true"));

    if (!installCustomFormatter) return;

    try {
      // ASSURE TO HAVE THE ORIENT LOG FORMATTER TO THE CONSOLE EVEN IF NO CONFIGURATION FILE IS
      // TAKEN
      final Logger log = Logger.getLogger("");
      if (log.getHandlers().length == 0) {
        // SET DEFAULT LOG FORMATTER
        final Handler h = new ConsoleHandler();
        h.setFormatter(new OLogFormatter());
        log.addHandler(h);
      } else {
        for (Handler h : log.getHandlers()) {
          if (h instanceof ConsoleHandler
              && !h.getFormatter().getClass().equals(OLogFormatter.class))
            h.setFormatter(new OLogFormatter());
        }
      }
    } catch (Exception e) {
      System.err.println(
          "Error while installing custom formatter. Logging could be disabled. Cause: "
              + e.toString());
    }
  }
  protected String getConfigProperty(final String name) {
    String value = null;

    if (server.getConfiguration() != null && server.getConfiguration().properties != null) {
      for (OServerEntryConfiguration p : server.getConfiguration().properties) {
        if (p.name.equals(name)) {
          value = OSystemVariableResolver.resolveSystemVariables(p.value);
          break;
        }
      }
    }

    return value;
  }
  /** * OServerLifecycleListener Interface * */
  public void onBeforeActivate() {
    createSuperUser();

    // Default
    String configFile =
        OSystemVariableResolver.resolveSystemVariables("${ORIENTDB_HOME}/config/security.json");

    // The default "security.json" file can be overridden in the server config file.
    String securityFile = getConfigProperty("server.security.file");
    if (securityFile != null) configFile = securityFile;

    String ssf = OGlobalConfiguration.SERVER_SECURITY_FILE.getValueAsString();
    if (ssf != null) configFile = ssf;

    configDoc = loadConfig(configFile);
  }
  // "${ORIENTDB_HOME}/config/security.json"
  private ODocument loadConfig(final String cfgPath) {
    ODocument securityDoc = null;

    try {
      if (cfgPath != null) {
        // Default
        String jsonFile = OSystemVariableResolver.resolveSystemVariables(cfgPath);

        File file = new File(jsonFile);

        if (file.exists() && file.canRead()) {
          FileInputStream fis = null;

          try {
            fis = new FileInputStream(file);

            final byte[] buffer = new byte[(int) file.length()];
            fis.read(buffer);

            securityDoc = (ODocument) new ODocument().fromJSON(new String(buffer), "noMap");
          } finally {
            if (fis != null) fis.close();
          }
        } else {
          OLogManager.instance()
              .error(
                  this,
                  "ODefaultServerSecurity.loadConfig() Could not access the security JSON file: %s",
                  jsonFile);
        }
      } else {
        OLogManager.instance()
            .error(this, "ODefaultServerSecurity.loadConfig() Configuration file path is null");
      }
    } catch (Exception ex) {
      OLogManager.instance()
          .error(this, "ODefaultServerSecurity.loadConfig() Exception: %s", ex.getMessage());
    }

    return securityDoc;
  }
Example #6
0
 public OSingleFileSegment(final String iPath, final String iType) throws IOException {
   file =
       OFileFactory.instance()
           .create(iType, OSystemVariableResolver.resolveSystemVariables(iPath), "rw");
 }