Search in sources :

Example 1 with LdifPartition

use of org.apache.directory.server.core.partition.ldif.LdifPartition in project vertx-auth by vert-x3.

the class EmbeddedADS method initSchemaPartition.

/**
 * initialize the schema manager and add the schema partition to diectory service
 *
 * @throws Exception if the schema LDIF files are not found on the classpath
 */
private void initSchemaPartition() throws Exception {
    SchemaPartition schemaPartition = service.getSchemaService().getSchemaPartition();
    // Init the LdifPartition
    LdifPartition ldifPartition = new LdifPartition();
    String workingDirectory = service.getWorkingDirectory().getPath();
    ldifPartition.setWorkingDirectory(workingDirectory + "/schema");
    // Extract the schema on disk (a brand new one) and load the registries
    File schemaRepository = new File(workingDirectory, "schema");
    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(new File(workingDirectory));
    extractor.extractOrCopy(true);
    schemaPartition.setWrappedPartition(ldifPartition);
    SchemaLoader loader = new LdifSchemaLoader(schemaRepository);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    service.setSchemaManager(schemaManager);
    // 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();
    schemaPartition.setSchemaManager(schemaManager);
    List<Throwable> errors = schemaManager.getErrors();
    if (errors.size() != 0) {
        throw new Exception("Schema load failed : " + errors);
    }
}
Also used : LdifSchemaLoader(org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader) SchemaLoader(org.apache.directory.shared.ldap.schema.registries.SchemaLoader) SchemaLdifExtractor(org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor) DefaultSchemaLdifExtractor(org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor) DefaultSchemaManager(org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.shared.ldap.schema.SchemaManager) LdifSchemaLoader(org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader) SchemaPartition(org.apache.directory.server.core.schema.SchemaPartition) LdifPartition(org.apache.directory.server.core.partition.ldif.LdifPartition) DefaultSchemaLdifExtractor(org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor) File(java.io.File) DefaultSchemaManager(org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager)

Example 2 with LdifPartition

use of org.apache.directory.server.core.partition.ldif.LdifPartition in project aws-iam-ldap-bridge by denismo.

the class Runner method initSchemaPartition.

/**
 * initialize the schema manager and add the schema partition to diectory 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()) {
        System.out.println("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.size() != 0) {
        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.schemaloader.LdifSchemaLoader) DefaultSchemaLdifExtractor(org.apache.directory.api.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor) SchemaLdifExtractor(org.apache.directory.api.ldap.schemaextractor.SchemaLdifExtractor) DefaultSchemaManager(org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) LdifSchemaLoader(org.apache.directory.api.ldap.schemaloader.LdifSchemaLoader) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) LdifPartition(org.apache.directory.server.core.partition.ldif.LdifPartition) SingleFileLdifPartition(org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition) DefaultSchemaLdifExtractor(org.apache.directory.api.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor) File(java.io.File) DefaultSchemaManager(org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager)

Example 3 with LdifPartition

use of org.apache.directory.server.core.partition.ldif.LdifPartition 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 4 with LdifPartition

use of org.apache.directory.server.core.partition.ldif.LdifPartition 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 5 with LdifPartition

use of org.apache.directory.server.core.partition.ldif.LdifPartition in project goodies by sonatype.

the class LdapServer method initPartitions.

private static void initPartitions(DefaultDirectoryService directoryService) throws Exception {
    LdifPartition ldifPartition = new LdifPartition(directoryService.getSchemaManager(), directoryService.getDnFactory());
    ldifPartition.setPartitionPath(new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "schema").toURI());
    SchemaPartition schemaPartition = new SchemaPartition(directoryService.getSchemaManager());
    schemaPartition.setWrappedPartition(ldifPartition);
    directoryService.setSchemaPartition(schemaPartition);
    PartitionFactory partitionFactory = new AvlPartitionFactory();
    Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), directoryService.getDnFactory(), "system", ServerDNConstants.SYSTEM_DN, 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "system"));
    systemPartition.setSchemaManager(directoryService.getSchemaManager());
    partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
    directoryService.setSystemPartition(systemPartition);
    Partition sonatypePartition = partitionFactory.createPartition(directoryService.getSchemaManager(), directoryService.getDnFactory(), "sonatype", "o=sonatype", 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "sonatype"));
    sonatypePartition.setSchemaManager(directoryService.getSchemaManager());
    partitionFactory.addIndex(sonatypePartition, SchemaConstants.OBJECT_CLASS_AT, 100);
    directoryService.addPartition(sonatypePartition);
    Partition groupsPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), directoryService.getDnFactory(), "groups", "ou=groups,dc=company,dc=com", 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "groups"));
    groupsPartition.setSchemaManager(directoryService.getSchemaManager());
    partitionFactory.addIndex(groupsPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
    directoryService.addPartition(groupsPartition);
    Partition usersPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), directoryService.getDnFactory(), "users", "ou=users,dc=company,dc=com", 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "users"));
    usersPartition.setSchemaManager(directoryService.getSchemaManager());
    partitionFactory.addIndex(usersPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
    directoryService.addPartition(usersPartition);
    Partition acmeBrickPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), directoryService.getDnFactory(), "acme_brick", "dc=acme brick,dc=com", 500, new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "acme_brick"));
    acmeBrickPartition.setSchemaManager(directoryService.getSchemaManager());
    partitionFactory.addIndex(acmeBrickPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
    directoryService.addPartition(acmeBrickPartition);
}
Also used : SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) Partition(org.apache.directory.server.core.api.partition.Partition) LdifPartition(org.apache.directory.server.core.partition.ldif.LdifPartition) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) LdifPartition(org.apache.directory.server.core.partition.ldif.LdifPartition) AvlPartitionFactory(org.apache.directory.server.core.factory.AvlPartitionFactory) AvlPartitionFactory(org.apache.directory.server.core.factory.AvlPartitionFactory) PartitionFactory(org.apache.directory.server.core.factory.PartitionFactory) File(java.io.File)

Aggregations

LdifPartition (org.apache.directory.server.core.partition.ldif.LdifPartition)5 File (java.io.File)4 SchemaPartition (org.apache.directory.server.core.api.schema.SchemaPartition)4 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)3 SchemaLoader (org.apache.directory.api.ldap.model.schema.registries.SchemaLoader)3 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)3 SchemaLdifExtractor (org.apache.directory.api.ldap.schema.extractor.SchemaLdifExtractor)2 DefaultSchemaLdifExtractor (org.apache.directory.api.ldap.schema.extractor.impl.DefaultSchemaLdifExtractor)2 LdifSchemaLoader (org.apache.directory.api.ldap.schema.loader.LdifSchemaLoader)2 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)2 IOException (java.io.IOException)1 InvalidNameException (javax.naming.InvalidNameException)1 NamingException (javax.naming.NamingException)1 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 SchemaLdifExtractor (org.apache.directory.api.ldap.schemaextractor.SchemaLdifExtractor)1 DefaultSchemaLdifExtractor (org.apache.directory.api.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor)1 LdifSchemaLoader (org.apache.directory.api.ldap.schemaloader.LdifSchemaLoader)1 DefaultSchemaManager (org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager)1 Partition (org.apache.directory.server.core.api.partition.Partition)1