org.apache.directory.server.core.partition.Partition Java Examples

The following examples show how to use org.apache.directory.server.core.partition.Partition. 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 File: ApacheDirectoryPartitionManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
@Override
public void removeAllPartitions() throws DirectoryServerException {
    Set<? extends Partition> partitions = this.directoryService.getPartitions();

    for (Partition partition : partitions) {
        if (!"schema".equalsIgnoreCase(partition.getId())) {

            try {

                if (logger.isDebugEnabled()) {
                    logger.debug("Removing partition with id - " + partition.getId() + " suffix - " +
                            partition.getSuffix());
                }

                this.directoryService.removePartition(partition);
            } catch (Exception e) {
                String msg = "Unable to remove partition with id " + partition.getId() +
                        " with suffix " + partition.getSuffix();
                logger.error(msg, e);
                throw new DirectoryServerException(msg, e);
            }
        }
    }
}
 
Example #2
Source File: CarbonDirectoryServiceFactory.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Inits the system partition.
 *
 * @throws Exception the exception
 */
private void initSystemPartition()
        throws Exception {
    // change the working apacheds to something that is unique
    // on the system and somewhere either under target apacheds
    // or somewhere in a temp area of the machine.

    // Inject the System Partition
    Partition systemPartition = partitionFactory.createPartition(
            "system", ServerDNConstants.SYSTEM_DN, PARTITION_CACHE_SIZE,
            new File(directoryService.getWorkingDirectory(), "system"));
    systemPartition.setSchemaManager(directoryService.getSchemaManager());

    partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT,
            INDEX_CACHE_SIZE);

    directoryService.setSystemPartition(systemPartition);
}
 
Example #3
Source File: LdapTestServer.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new partition to the server
 *
 * @param partitionId
 *          The partition Id
 * @param partitionDn
 *          The partition DN
 * @return The newly added partition
 *
 * @throws Exception
 *           If the partition can't be added
 */
private Partition addPartition(String partitionId, String partitionDn)
    throws Exception {
  // Create a new partition named 'foo'.
  JdbmPartition partition = new JdbmPartition();
  partition.setId(partitionId);
  partition.setPartitionDir(
      new File(service.getWorkingDirectory(), partitionId));
  partition.setSuffix(partitionDn);
  service.addPartition(partition);

  return partition;
}
 
Example #4
Source File: EmbeddedADS.java    From easybuggy with Apache License 2.0 5 votes vote down vote up
private static void addRootEntry(Partition t246osslabPartition) throws Exception {
    try {
        service.getAdminSession().lookup(t246osslabPartition.getSuffixDn());
    } catch (Exception e) {
        log.debug("Exception occurs: ", e);
        LdapDN dnBar = new LdapDN(ROOT_DN);
        ServerEntry entryBar = service.newEntry(dnBar);
        entryBar.add("objectClass", "dcObject", "organization");
        entryBar.add("o", ROOT_PARTITION_NAME);
        entryBar.add("dc", ROOT_PARTITION_NAME);
        service.getAdminSession().add(entryBar);
    }
}
 
Example #5
Source File: EmbeddedADS.java    From easybuggy with Apache License 2.0 5 votes vote down vote up
private static Partition addPartition(String partitionId, String partitionDn) throws Exception {
    // Create a new partition named
    Partition partition = new JdbmPartition();
    partition.setId(partitionId);
    partition.setSuffix(partitionDn);
    service.addPartition(partition);
    return partition;
}
 
Example #6
Source File: EmbeddedLdapServer.java    From codenvy with Eclipse Public License 1.0 5 votes vote down vote up
private static Partition addPartition(
    DirectoryService service, String partitionId, String partitionDn) throws Exception {
  final JdbmPartition partition = new JdbmPartition();
  partition.setId(partitionId);
  partition.setPartitionDir(new File(service.getWorkingDirectory(), partitionId));
  partition.setSuffix(partitionDn);
  service.addPartition(partition);
  return partition;
}
 
Example #7
Source File: LdapTestServer.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new partition to the server
 *
 * @param partitionId
 *          The partition Id
 * @param partitionDn
 *          The partition DN
 * @return The newly added partition
 *
 * @throws Exception
 *           If the partition can't be added
 */
private Partition addPartition(String partitionId, String partitionDn)
    throws Exception {
  // Create a new partition named 'foo'.
  JdbmPartition partition = new JdbmPartition();
  partition.setId(partitionId);
  partition.setPartitionDir(
      new File(service.getWorkingDirectory(), partitionId));
  partition.setSuffix(partitionDn);
  service.addPartition(partition);

  return partition;
}
 
Example #8
Source File: LDAPServer.java    From Benchmark with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a new set of index on the given attributes
 *
 * @param partition
 *            The partition on which we want to add index
 * @param attrs
 *            The list of attributes to index
 */
private void addIndex(Partition partition, String... attrs) {
	// Index some attributes on the apache partition
	HashSet<Index<?, ServerEntry, Long>> indexedAttributes = new HashSet<Index<?, ServerEntry, Long>>();

	for (String attribute : attrs) {
		indexedAttributes.add(new JdbmIndex<String, ServerEntry>(attribute));
	}

	((JdbmPartition) partition).setIndexedAttributes(indexedAttributes);
}
 
Example #9
Source File: ApacheDirectoryPartitionManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public boolean partitionInitialized(String partitionId) {
    Set<? extends Partition> partitions = this.directoryService.getPartitions();

    for (Partition partition : partitions) {
        if (partition.getId().equals(partitionId)) {
            return true;
        }
    }

    return false;
}
 
Example #10
Source File: ApacheDirectoryPartitionManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
@Override
public int getNumberOfPartitions() {
    int numOfPartitions = 0; //if no partition is created

    Set<? extends Partition> partitions = this.directoryService.getPartitions();

    numOfPartitions = partitions.size();

    return numOfPartitions;
}
 
Example #11
Source File: EmbeddedADS.java    From vertx-auth with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new partition to the server
 *
 * @param partitionId The partition Id
 * @param partitionDn The partition DN
 * @return The newly added partition
 * @throws Exception If the partition can't be added
 */
private Partition addPartition(String partitionId, String partitionDn) throws Exception {
  // Create a new partition named 'foo'.
  JdbmPartition partition = new JdbmPartition();
  partition.setId(partitionId);
  partition.setPartitionDir(new File(service.getWorkingDirectory(), partitionId));
  partition.setSuffix(partitionDn);
  service.addPartition(partition);

  return partition;
}
 
Example #12
Source File: EmbeddedADS.java    From vertx-auth with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new set of index on the given attributes
 *
 * @param partition The partition on which we want to add index
 * @param attrs     The list of attributes to index
 */
private void addIndex(Partition partition, String... attrs) {
  // Index some attributes on the apache partition
  HashSet<Index<?, ServerEntry, Long>> indexedAttributes = new HashSet<>();

  for (String attribute : attrs) {
    indexedAttributes.add(new JdbmIndex<String, ServerEntry>(attribute));
  }

  ((JdbmPartition) partition).setIndexedAttributes(indexedAttributes);
}
 
Example #13
Source File: LdapTestServer.java    From gemfirexd-oss with 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 #14
Source File: LdapTestServer.java    From gemfirexd-oss with 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 #15
Source File: EmbeddedADS.java    From vertx-auth with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the server. It creates the partition, adds the index, and
 * injects the context entries for the created partitions.
 *
 * @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);

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

  // Now we can create as many partitions as we need
  // Create some new partitions named 'foo', 'bar' and 'apache'.
  Partition fooPartition = addPartition("foo", "dc=foo,dc=com");

  // Index some attributes on the apache partition
  addIndex(fooPartition, "objectClass", "ou", "uid");

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

  DN dnFoo = new DN("dc=foo,dc=com");
  ServerEntry entryFoo = service.newEntry(dnFoo);
  entryFoo.add("objectClass", "top", "domain", "extensibleObject");
  entryFoo.add("dc", "foo");
  service.getAdminSession().add(entryFoo);

  DN usersDN=new DN("ou=users,dc=foo,dc=com");
  ServerEntry usersEntry=service.newEntry(usersDN);
  usersEntry.add("objectClass","organizationalUnit","top");
  usersEntry.add("ou","users");
  service.getAdminSession().add(usersEntry);

}
 
Example #16
Source File: LDAPServer.java    From Benchmark with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Add a new partition to the server
 *
 * @param partitionId
 *            The partition Id
 * @param partitionDn
 *            The partition DN
 * @return The newly added partition
 * @throws Exception
 *             If the partition can't be added
 */
private Partition addPartition(String partitionId, String partitionDn) throws Exception {
	// Create a new partition named 'foo'.
	JdbmPartition partition = new JdbmPartition();
	partition.setId(partitionId);
	partition.setPartitionDir(new File(service.getWorkingDirectory(), partitionId));
	partition.setSuffix(partitionDn);
	service.addPartition(partition);

	return partition;
}