private JsonValue readJsonFile(String path) throws AuditException {
   try {
     InputStream is = AuditServiceProviderImpl.class.getResourceAsStream(path);
     String contents = IOUtils.readStream(is);
     return JsonValueBuilder.toJsonValue(contents.replaceAll("\\s", ""));
   } catch (IOException e) {
     debug.error("Unable to read configuration file {}", path, e);
     throw new AuditException("Unable to read configuration file " + path, e);
   }
 }
Пример #2
0
  @BeforeClass
  public void setupScript() throws Exception {
    String rawScript =
        IOUtils.readStream(
            this.getClass().getClassLoader().getResourceAsStream("oidc-claims-extension.groovy"));
    SupportedScriptingLanguage scriptType = SupportedScriptingLanguage.GROOVY;

    this.script = new ScriptObject("oidc-claims-script", rawScript, scriptType, null);

    StandardScriptEngineManager scriptEngineManager = new StandardScriptEngineManager();
    scriptEngineManager.registerEngineName(
        SupportedScriptingLanguage.GROOVY_ENGINE_NAME, new GroovyScriptEngineFactory());
    scriptEvaluator = new StandardScriptEvaluator(scriptEngineManager);
  }
Пример #3
0
  /**
   * Sets up embedded OpenDJ during initial installation :
   *
   * <ul>
   *   <li>lays out the filesystem directory structure needed by OpenDJ
   *   <li>sets up port numbers for ldap and replication
   *   <li>invokes <code>EmbeddedUtils</code> to start the embedded server.
   * </ul>
   *
   * @param map Map of properties collected by the configurator.
   * @param servletCtx Servlet Context to read deployed war contents.
   * @throws Exception on encountering errors.
   */
  public static void setup(Map map, ServletContext servletCtx) throws Exception {
    // Determine Cipher to be used
    SetupProgress.reportStart("emb.installingemb.null", null);
    String xform = getSupportedTransformation();

    if (xform == null) {
      SetupProgress.reportEnd("emb.noxform", null);
      throw new Exception("No transformation found");
    } else {
      map.put(OPENDS_TRANSFORMATION, xform);
      Object[] params = {xform};
      SetupProgress.reportEnd("emb.success.param", params);
    }

    String basedir = (String) map.get(SetupConstants.CONFIG_VAR_BASE_DIR);
    String odsRoot = getOpenDJBaseDir(map);
    new File(basedir).mkdir();
    new File(odsRoot).mkdir();

    SetupProgress.reportStart("emb.opends.start", null);
    String zipFileName = "/WEB-INF/template/opendj/opendj.zip";
    BufferedInputStream bin =
        new BufferedInputStream(AMSetupServlet.getResourceAsStream(servletCtx, zipFileName), 10000);
    BufferedOutputStream bout =
        new BufferedOutputStream(new FileOutputStream(odsRoot + "/opendj.zip"), 10000);

    try {
      while (bin.available() > 0) {
        bout.write(bin.read());
      }
    } catch (IOException ioe) {
      Debug.getInstance(SetupConstants.DEBUG_NAME)
          .error("EmbeddedOpenDS.setup(): Error copying zip file", ioe);
      throw ioe;
    } finally {
      IOUtils.closeIfNotNull(bin);
      IOUtils.closeIfNotNull(bout);
    }

    ZipFile opendsZip = new ZipFile(odsRoot + "/opendj.zip");
    Enumeration files = opendsZip.entries();
    // Process the OpenDJ Archive File.
    while (files.hasMoreElements()) {
      ZipEntry file = (ZipEntry) files.nextElement();
      File f = new File(odsRoot + "/" + file.getName());

      if (file.isDirectory()) {
        f.mkdir();
        continue;
      }

      BufferedInputStream is = new BufferedInputStream(opendsZip.getInputStream(file), 10000);
      BufferedOutputStream fos = new BufferedOutputStream(new java.io.FileOutputStream(f), 10000);

      try {
        while (is.available() > 0) {
          fos.write(is.read());
        }
      } catch (IOException ioe) {
        Debug.getInstance(SetupConstants.DEBUG_NAME)
            .error("EmbeddedOpenDS.setup(): Error loading ldifs", ioe);
        throw ioe;
      } finally {
        IOUtils.closeIfNotNull(is);
        IOUtils.closeIfNotNull(fos);
      } // End of Inner Finally.

      if (file.getName().endsWith("sh") || file.getName().startsWith("bin")) {
        f.setExecutable(true);
      }
    } // End of File Elements from Zip for OpenDJ.

    // create tag swapped files
    String[] tagSwapFiles = {"template/ldif/openam_suffix.ldif.template"};

    for (int i = 0; i < tagSwapFiles.length; i++) {
      String fileIn = odsRoot + "/" + tagSwapFiles[i];
      FileReader fin = new FileReader(fileIn);

      StringBuilder sbuf = new StringBuilder();
      char[] cbuf = new char[1024];
      int len;
      while ((len = fin.read(cbuf)) > 0) {
        sbuf.append(cbuf, 0, len);
      }
      FileWriter fout = null;

      try {
        fout =
            new FileWriter(
                odsRoot + "/" + tagSwapFiles[i].substring(0, tagSwapFiles[i].indexOf(".template")));
        String inpStr = sbuf.toString();
        fout.write(ServicesDefaultValues.tagSwap(inpStr));
      } catch (IOException e) {
        Debug.getInstance(SetupConstants.DEBUG_NAME)
            .error("EmbeddedOpenDS.setup(): Error tag swapping files", e);
        throw e;
      } finally {
        IOUtils.closeIfNotNull(fin);
        IOUtils.closeIfNotNull(fout);
      }
    }

    // remove zip
    File toDelete = new File(odsRoot + "/opendj.zip");
    if (!toDelete.delete()) {
      Debug.getInstance(SetupConstants.DEBUG_NAME)
          .error("EmbeddedOpenDS.setup(): Unable to delete zip file:" + toDelete.getAbsolutePath());
    }

    SetupProgress.reportEnd("emb.opends.stop", null);

    // now setup OpenDJ
    System.setProperty("org.opends.quicksetup.Root", odsRoot);
    System.setProperty(ServerConstants.PROPERTY_SERVER_ROOT, odsRoot);
    System.setProperty(ServerConstants.PROPERTY_INSTANCE_ROOT, odsRoot);
    EmbeddedOpenDS.setupOpenDS(map);

    Object[] params = {odsRoot};
    SetupProgress.reportStart("emb.installingemb", params);
    EmbeddedOpenDS.startServer(odsRoot);

    // Check: If adding a new server to a existing cluster
    if (!isMultiServer(map)) {
      // Default: single / first server.
      SetupProgress.reportStart("emb.creatingfamsuffix", null);
      int ret = EmbeddedOpenDS.loadLDIF(map, odsRoot, odsRoot + "/ldif/openam_suffix.ldif");

      if (ret == 0) {
        SetupProgress.reportEnd("emb.creatingfamsuffix.success", null);
      } else {
        Object[] error = {Integer.toString(ret)};
        SetupProgress.reportEnd("emb.creatingfamsuffix.failure", error);
        Debug.getInstance(SetupConstants.DEBUG_NAME)
            .error("EmbeddedOpenDS.setupOpenDS. Error loading OpenAM suffix");
        throw new ConfiguratorException("emb.creatingfamsuffix.failure");
      }
    } // End of single / first server check.
  }