Search in sources :

Example 1 with LdifSchemaLoader

use of org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader in project syncope by apache.

the class ApacheDSStartStopListener method initSchemaPartition.

/**
 * Initialize the schema manager and add the schema partition to directory service.
 *
 * @throws Exception if the schema LDIF files are not found on the classpath
 */
private void initSchemaPartition() throws Exception {
    InstanceLayout instanceLayout = service.getInstanceLayout();
    File schemaPartitionDirectory = new File(instanceLayout.getPartitionsDirectory(), "schema");
    // Extract the schema on disk (a brand new one) and load the registries
    if (schemaPartitionDirectory.exists()) {
        LOG.debug("schema partition already exists, skipping schema extraction");
    } else {
        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(instanceLayout.getPartitionsDirectory());
        extractor.extractOrCopy();
    }
    SchemaLoader loader = new LdifSchemaLoader(schemaPartitionDirectory);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    // We have to load the schema now, otherwise we won't be able
    // to initialize the Partitions, as we won't be able to parse
    // and normalize their suffix Dn
    schemaManager.loadAllEnabled();
    List<Throwable> errors = schemaManager.getErrors();
    if (!errors.isEmpty()) {
        throw new IllegalStateException(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
    }
    service.setSchemaManager(schemaManager);
    // Init the LdifPartition with schema
    LdifPartition schemaLdifPartition = new LdifPartition(schemaManager, service.getDnFactory());
    schemaLdifPartition.setPartitionPath(schemaPartitionDirectory.toURI());
    // The schema partition
    SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
    schemaPartition.setWrappedPartition(schemaLdifPartition);
    service.setSchemaPartition(schemaPartition);
}
Also used : InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) SchemaLoader(org.apache.directory.api.ldap.model.schema.registries.SchemaLoader) LdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader) SchemaLdifExtractor(org.apache.directory.api.ldap.schema.extractor.SchemaLdifExtractor) DefaultSchemaLdifExtractor(org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) LdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) LdifPartition(org.apache.directory.server.core.partition.ldif.LdifPartition) DefaultSchemaLdifExtractor(org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor) File(java.io.File) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)

Example 2 with LdifSchemaLoader

use of org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader in project camunda-bpm-platform by camunda.

the class LdapTestEnvironment method initSchemaPartition.

/**
 * initialize the schema manager and add the schema partition to directory
 * service
 *
 * @throws Exception if the schema LDIF files are not found on the classpath
 */
protected void initSchemaPartition() throws Exception {
    InstanceLayout instanceLayout = service.getInstanceLayout();
    File schemaPartitionDirectory = new File(instanceLayout.getPartitionsDirectory(), "schema");
    // Extract the schema on disk (a brand new one) and load the registries
    if (schemaPartitionDirectory.exists()) {
        LOG.log(Level.INFO, "schema partition already exists, skipping schema extraction");
    } else {
        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(instanceLayout.getPartitionsDirectory());
        extractor.extractOrCopy();
    }
    SchemaLoader loader = new LdifSchemaLoader(schemaPartitionDirectory);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    // We have to load the schema now, otherwise we won't be able
    // to initialize the Partitions, as we won't be able to parse
    // and normalize their suffix Dn
    schemaManager.loadAllEnabled();
    List<Throwable> errors = schemaManager.getErrors();
    if (!errors.isEmpty()) {
        throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
    }
    service.setSchemaManager(schemaManager);
    // Init the LdifPartition with schema
    LdifPartition schemaLdifPartition = new LdifPartition(schemaManager, service.getDnFactory());
    schemaLdifPartition.setPartitionPath(schemaPartitionDirectory.toURI());
    // The schema partition
    SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
    schemaPartition.setWrappedPartition(schemaLdifPartition);
    service.setSchemaPartition(schemaPartition);
}
Also used : InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) SchemaLoader(org.apache.directory.api.ldap.model.schema.registries.SchemaLoader) LdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader) SchemaLdifExtractor(org.apache.directory.api.ldap.schema.extractor.SchemaLdifExtractor) DefaultSchemaLdifExtractor(org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) LdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader) NamingException(javax.naming.NamingException) InvalidNameException(javax.naming.InvalidNameException) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) LdifPartition(org.apache.directory.server.core.partition.ldif.LdifPartition) DefaultSchemaLdifExtractor(org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)

Example 3 with LdifSchemaLoader

use of org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader in project cloudstack by apache.

the class EmbeddedLdapServer method addSchemaFromPath.

/**
 * Add additional schemas to the directory server. This takes a path to
 * the schema directory and uses the LdifSchemaLoader.
 *
 * @param schemaLocation The path to the directory containing the
 *                       "ou=schema" directory for an additional schema
 * @param schemaName     The name of the schema
 * @return true if the schemas have been loaded and the registries is
 * consistent
 */
public boolean addSchemaFromPath(File schemaLocation, String schemaName) throws LdapException, IOException {
    LdifSchemaLoader schemaLoader = new LdifSchemaLoader(schemaLocation);
    DefaultSchema schema = new DefaultSchema(schemaLoader, schemaName);
    return getDirectoryService().getSchemaManager().load(schema);
}
Also used : DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) JarLdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader) LdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader)

Aggregations

LdifSchemaLoader (org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader)3 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)2 SchemaLoader (org.apache.directory.api.ldap.model.schema.registries.SchemaLoader)2 SchemaLdifExtractor (org.apache.directory.api.ldap.schema.extractor.SchemaLdifExtractor)2 DefaultSchemaLdifExtractor (org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor)2 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)2 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)2 SchemaPartition (org.apache.directory.server.core.api.schema.SchemaPartition)2 LdifPartition (org.apache.directory.server.core.partition.ldif.LdifPartition)2 File (java.io.File)1 InvalidNameException (javax.naming.InvalidNameException)1 NamingException (javax.naming.NamingException)1 DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)1 JarLdifSchemaLoader (org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader)1