Java Code Examples for org.apache.directory.server.protocol.shared.store.LdifFileLoader

The following examples show how to use org.apache.directory.server.protocol.shared.store.LdifFileLoader. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: aws-iam-ldap-bridge   Source File: ApacheDSUtils.java    License: Apache License 2.0 5 votes vote down vote up
public void loadLdif(String s) throws LdapException {
    if (getClass().getClassLoader().getResourceAsStream(s) == null) {
        s = new File("E:\\WS\\ApacheDS_AWSIAM\\dist\\apacheds\\" + s).getAbsolutePath();
    }
    LdifFileLoader loader = new LdifFileLoader(service.getAdminSession(), s);
    loader.execute();
}
 
Example 2
Source Project: spring-ldap   Source File: LdapTestUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void loadLdif(DefaultDirectoryService directoryService, Resource ldifFile) throws IOException {
    File tempFile = File.createTempFile("spring_ldap_test", ".ldif");
    try {
        InputStream inputStream = ldifFile.getInputStream();
        IOUtils.copy(inputStream, new FileOutputStream(tempFile));
        LdifFileLoader fileLoader = new LdifFileLoader(directoryService.getSession(), tempFile.getAbsolutePath());
        fileLoader.execute();
    } finally {
        try {
            tempFile.delete();
        } catch (Exception e) {
            // Ignore this
        }
    }
}
 
Example 3
private void importLdifs() throws Exception {
	// Import any ldif files
	Resource[] ldifs;

	if (ctxt == null) {
		// Not running within an app context
		ldifs = new PathMatchingResourcePatternResolver().getResources(ldifResources);
	}
	else {
		ldifs = ctxt.getResources(ldifResources);
	}

	// Note that we can't just import using the ServerContext returned
	// from starting Apache DS, apparently because of the long-running issue
	// DIRSERVER-169.
	// We need a standard context.
	// DirContext dirContext = contextSource.getReadWriteContext();

	if (ldifs == null || ldifs.length == 0) {
		return;
	}

	if (ldifs.length == 1) {
		String ldifFile;

		try {
			ldifFile = ldifs[0].getFile().getAbsolutePath();
		}
		catch (IOException e) {
			ldifFile = ldifs[0].getURI().toString();
		}
		logger.info("Loading LDIF file: " + ldifFile);
		LdifFileLoader loader = new LdifFileLoader(service.getAdminSession(),
				new File(ldifFile), null, getClass().getClassLoader());
		loader.execute();
	}
	else {
		throw new IllegalArgumentException(
				"More than one LDIF resource found with the supplied pattern:"
						+ ldifResources + " Got " + Arrays.toString(ldifs));
	}
}
 
Example 4
Source Project: gemfirexd-oss   Source File: LdapTestServer.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the server. It creates the partition, injects the context
 * entries for the created partitions, and loads an LDIF file (
 * {@link #ldifLoadFile}) for initial entries.
 *
 * @param workDir
 *          the directory to be used for storing the data
 * @throws Exception
 *           if there were some problems while initializing the system
 */
private void initDirectoryService(File workDir) throws Exception {
  // Initialize the LDAP service
  service = new DefaultDirectoryService();
  service.setWorkingDirectory(workDir);

  // first load the schema
  initSchemaPartition();

  // then the system partition
  // this is a MANDATORY partition
  Partition systemPartition = addPartition("system",
      ServerDNConstants.SYSTEM_DN);
  service.setSystemPartition(systemPartition);

  // create the partition for testing
  Partition testingPartition = addPartition("ldapTesting",
      "ou=ldapTesting,dc=pune,dc=gemstone,dc=com");

  // Disable the shutdown hook
  service.setShutdownHookEnabled(false);
  // Disable the ChangeLog system
  service.getChangeLog().setEnabled(false);
  service.setDenormalizeOpAttrsEnabled(true);

  // And start the service
  service.startup();

  // inject the entry for testing
  if (!service.getAdminSession().exists(testingPartition.getSuffixDn())) {
    DN dnTesting = new DN("ou=ldapTesting,dc=pune,dc=gemstone,dc=com");
    ServerEntry entryTesting = service.newEntry(dnTesting);
    entryTesting.add("objectClass", "top", "domain", "extensibleObject");
    entryTesting.add("dc", "pune");
    service.getAdminSession().add(entryTesting);
  }

  // load schema from LDIF
  if (ldifLoadFile != null) {
    LdifFileLoader ldifLoader = new LdifFileLoader(
        service.getAdminSession(), ldifLoadFile);
    int numLoaded = ldifLoader.execute();
    if (numLoaded <= 0) {
      throw new Exception(
          "Failed to load any entries from " + ldifLoadFile);
    } else {
      System.out.println(
          "LDAP loaded " + numLoaded + " entries from " + ldifLoadFile);
    }
  }
}
 
Example 5
Source Project: gemfirexd-oss   Source File: LdapTestServer.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the server. It creates the partition, injects the context
 * entries for the created partitions, and loads an LDIF file (
 * {@link #ldifLoadFile}) for initial entries.
 *
 * @param workDir
 *          the directory to be used for storing the data
 * @throws Exception
 *           if there were some problems while initializing the system
 */
private void initDirectoryService(File workDir) throws Exception {
  // Initialize the LDAP service
  service = new DefaultDirectoryService();
  service.setWorkingDirectory(workDir);

  // first load the schema
  initSchemaPartition();

  // then the system partition
  // this is a MANDATORY partition
  Partition systemPartition = addPartition("system",
      ServerDNConstants.SYSTEM_DN);
  service.setSystemPartition(systemPartition);

  // create the partition for testing
  Partition testingPartition = addPartition("ldapTesting",
      "ou=ldapTesting,dc=pune,dc=gemstone,dc=com");

  // Disable the shutdown hook
  service.setShutdownHookEnabled(false);
  // Disable the ChangeLog system
  service.getChangeLog().setEnabled(false);
  service.setDenormalizeOpAttrsEnabled(true);

  // And start the service
  service.startup();

  // inject the entry for testing
  if (!service.getAdminSession().exists(testingPartition.getSuffixDn())) {
    DN dnTesting = new DN("ou=ldapTesting,dc=pune,dc=gemstone,dc=com");
    ServerEntry entryTesting = service.newEntry(dnTesting);
    entryTesting.add("objectClass", "top", "domain", "extensibleObject");
    entryTesting.add("dc", "pune");
    service.getAdminSession().add(entryTesting);
  }

  // load schema from LDIF
  if (ldifLoadFile != null) {
    LdifFileLoader ldifLoader = new LdifFileLoader(
        service.getAdminSession(), ldifLoadFile);
    int numLoaded = ldifLoader.execute();
    if (numLoaded <= 0) {
      throw new Exception(
          "Failed to load any entries from " + ldifLoadFile);
    } else {
      System.out.println(
          "LDAP loaded " + numLoaded + " entries from " + ldifLoadFile);
    }
  }
}
 
Example 6
Source Project: cukes   Source File: EmbeddedLDAPServer.java    License: Apache License 2.0 4 votes vote down vote up
public void loadLDIF(String fileName) {
    File ldifFile = new File(fileName);
    LdifFileLoader loader = new LdifFileLoader(service.getAdminSession(), ldifFile, null, getClass().getClassLoader());
    loader.execute();
}