Search in sources :

Example 1 with SchemaManager

use of org.apache.directory.api.ldap.model.schema.SchemaManager 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 2 with SchemaManager

use of org.apache.directory.api.ldap.model.schema.SchemaManager in project jackrabbit-oak by apache.

the class AbstractServer method setUp.

/**
     * Get's the initial context factory for the provider's ou=system context
     * root.
     */
protected void setUp() throws Exception {
    File cwd = new File("target", "apacheds");
    doDelete(cwd);
    // setup directory service
    directoryService = new DefaultDirectoryService();
    directoryService.setShutdownHookEnabled(false);
    directoryService.setInstanceLayout(new InstanceLayout(cwd));
    cacheService = new CacheService();
    cacheService.initialize(directoryService.getInstanceLayout());
    SchemaManager schemaManager = new DefaultSchemaManager();
    directoryService.setSchemaManager(schemaManager);
    directoryService.setDnFactory(new DefaultDnFactory(directoryService.getSchemaManager(), cacheService.getCache("dnCache")));
    AvlPartition schLdifPart = new AvlPartition(directoryService.getSchemaManager(), directoryService.getDnFactory());
    schLdifPart.setId("schema");
    schLdifPart.setSuffixDn(directoryService.getDnFactory().create(ServerDNConstants.CN_SCHEMA_DN));
    SchemaPartition schPart = new SchemaPartition(directoryService.getSchemaManager());
    schPart.setWrappedPartition(schLdifPart);
    directoryService.setSchemaPartition(schPart);
    AvlPartition sysPart = new AvlPartition(directoryService.getSchemaManager(), directoryService.getDnFactory());
    sysPart.setId(SystemSchemaConstants.SCHEMA_NAME);
    sysPart.setSuffixDn(directoryService.getDnFactory().create(ServerDNConstants.SYSTEM_DN));
    directoryService.setSystemPartition(sysPart);
    AvlPartition examplePart = new AvlPartition(directoryService.getSchemaManager(), directoryService.getDnFactory());
    examplePart.setId("example");
    examplePart.setSuffixDn(directoryService.getDnFactory().create(EXAMPLE_DN));
    examplePart.setCacheService(cacheService);
    directoryService.addPartition(examplePart);
    // setup ldap server
    port = AvailablePortFinder.getNextAvailable(1024);
    ldapServer = new LdapServer();
    setupLdapServer();
    setupSaslMechanisms();
    directoryService.startup();
    setupExamplePartition();
    startLdapServer();
    setContexts(ServerDNConstants.ADMIN_SYSTEM_DN, "secret");
}
Also used : DefaultDirectoryService(org.apache.directory.server.core.DefaultDirectoryService) InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) LdapServer(org.apache.directory.server.ldap.LdapServer) DefaultDnFactory(org.apache.directory.server.core.shared.DefaultDnFactory) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) File(java.io.File) CacheService(org.apache.directory.server.core.api.CacheService) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) AvlPartition(org.apache.directory.server.core.partition.impl.avl.AvlPartition)

Example 3 with SchemaManager

use of org.apache.directory.api.ldap.model.schema.SchemaManager in project wildfly by wildfly.

the class LdapExtLDAPServerSetupTask method createLdap2.

//@formatter:off
@CreateDS(name = "JBossComDS", factory = org.jboss.as.test.integration.ldap.InMemoryDirectoryServiceFactory.class, partitions = { @CreatePartition(name = "jbossCom", suffix = "dc=jboss,dc=com", contextEntry = @ContextEntry(entryLdif = "dn: dc=jboss,dc=com\n" + "dc: jboss\n" + "objectClass: top\n" + "objectClass: domain\n\n"), indexes = { @CreateIndex(attribute = "objectClass"), @CreateIndex(attribute = "dc"), @CreateIndex(attribute = "ou") }), @CreatePartition(name = "jbossOrg", suffix = "dc=jboss,dc=org", contextEntry = @ContextEntry(entryLdif = "dn: dc=jboss,dc=org\n" + "dc: jboss\n" + "objectClass: top\n" + "objectClass: domain\n\n"), indexes = { @CreateIndex(attribute = "objectClass"), @CreateIndex(attribute = "dc"), @CreateIndex(attribute = "ou") }) }, additionalInterceptors = { KeyDerivationInterceptor.class })
@CreateLdapServer(transports = { @CreateTransport(protocol = "LDAP", port = LDAP_PORT2) })
public //@formatter:on
void createLdap2(final String hostname) throws Exception {
    directoryService2 = DSAnnotationProcessor.getDirectoryService();
    final SchemaManager schemaManager = directoryService2.getSchemaManager();
    try {
        for (LdifEntry ldifEntry : new LdifReader(LdapExtLoginModuleTestCase.class.getResourceAsStream(LdapExtLoginModuleTestCase.class.getSimpleName() + "2.ldif"))) {
            directoryService2.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    final ManagedCreateLdapServer createLdapServer = new ManagedCreateLdapServer((CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class));
    fixTransportAddress(createLdapServer, hostname);
    ldapServer2 = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService2);
    ldapServer2.start();
    LOGGER.trace("ldapServer2 = " + ldapServer2);
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) ManagedCreateLdapServer(org.jboss.as.test.integration.security.common.ManagedCreateLdapServer) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) CreateDS(org.apache.directory.server.core.annotations.CreateDS) ManagedCreateLdapServer(org.jboss.as.test.integration.security.common.ManagedCreateLdapServer) CreateLdapServer(org.apache.directory.server.annotations.CreateLdapServer)

Example 4 with SchemaManager

use of org.apache.directory.api.ldap.model.schema.SchemaManager in project wildfly by wildfly.

the class LdapServerSetupTask method startLdapServer.

@CreateDS(name = "JBossDS-LdapServerSetupTask", factory = org.jboss.as.test.integration.ldap.InMemoryDirectoryServiceFactory.class, partitions = { @CreatePartition(name = "jboss", suffix = "dc=jboss,dc=org", contextEntry = @ContextEntry(entryLdif = "dn: dc=jboss,dc=org\n" + "dc: jboss\n" + "objectClass: top\n" + "objectClass: domain\n\n"), indexes = { @CreateIndex(attribute = "objectClass"), @CreateIndex(attribute = "dc"), @CreateIndex(attribute = "ou") }) }, additionalInterceptors = { KeyDerivationInterceptor.class })
@CreateLdapServer(transports = { @CreateTransport(protocol = "LDAP", port = LDAP_PORT), @CreateTransport(protocol = "LDAPS", port = LDAPS_PORT) }, certificatePassword = "secret")
public //@formatter:on
void startLdapServer(final String hostname) throws Exception, IOException, ClassNotFoundException, FileNotFoundException {
    final Map<String, String> map = new HashMap<String, String>();
    map.put("hostname", NetworkUtils.formatPossibleIpv6Address(hostname));
    directoryService = DSAnnotationProcessor.getDirectoryService();
    final String ldifContent = StrSubstitutor.replace(IOUtils.toString(LdapServerSetupTask.class.getResourceAsStream("picketlink-idm-tests.ldif"), "UTF-8"), map);
    final SchemaManager schemaManager = directoryService.getSchemaManager();
    try {
        for (LdifEntry ldifEntry : new LdifReader(IOUtils.toInputStream(ldifContent))) {
            directoryService.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    final ManagedCreateLdapServer createLdapServer = new ManagedCreateLdapServer((CreateLdapServer) AnnotationUtils.getInstance(CreateLdapServer.class));
    FileOutputStream fos = new FileOutputStream(KEYSTORE_FILE);
    IOUtils.copy(getClass().getResourceAsStream(KEYSTORE_FILENAME), fos);
    fos.close();
    createLdapServer.setKeyStore(KEYSTORE_FILE.getAbsolutePath());
    fixTransportAddress(createLdapServer, hostname);
    ldapServer = ServerAnnotationProcessor.instantiateLdapServer(createLdapServer, directoryService);
    ldapServer.start();
}
Also used : LdifReader(org.apache.directory.api.ldap.model.ldif.LdifReader) ManagedCreateLdapServer(org.jboss.as.test.integration.security.common.ManagedCreateLdapServer) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) CreateDS(org.apache.directory.server.core.annotations.CreateDS) ManagedCreateLdapServer(org.jboss.as.test.integration.security.common.ManagedCreateLdapServer) CreateLdapServer(org.apache.directory.server.annotations.CreateLdapServer)

Example 5 with SchemaManager

use of org.apache.directory.api.ldap.model.schema.SchemaManager in project wildfly by wildfly.

the class InMemoryDirectoryServiceFactory method init.

/**
     * {@inheritDoc}
     */
@Override
public void init(String name) throws Exception {
    if ((directoryService == null) || directoryService.isStarted()) {
        return;
    }
    int id = counter++;
    directoryService.setInstanceId(name + id);
    // instance layout
    InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + directoryService.getInstanceId());
    if (instanceLayout.getInstanceDirectory().exists()) {
        try {
            FileUtils.deleteDirectory(instanceLayout.getInstanceDirectory());
        } catch (IOException e) {
            LOG.warn("couldn't delete the instance directory before initializing the DirectoryService", e);
        }
    }
    directoryService.setInstanceLayout(instanceLayout);
    // EhCache in disabled-like-mode
    String cacheName = "ApacheDSTestCache-" + id;
    Configuration ehCacheConfig = new Configuration();
    ehCacheConfig.setName(cacheName);
    CacheConfiguration defaultCache = new CacheConfiguration(cacheName, 1).eternal(false).timeToIdleSeconds(30).timeToLiveSeconds(30).overflowToDisk(false);
    ehCacheConfig.addDefaultCache(defaultCache);
    cacheManager = new CacheManager(ehCacheConfig);
    CacheService cacheService = new CacheService(cacheManager);
    directoryService.setCacheService(cacheService);
    // Init the schema
    // SchemaLoader loader = new SingleLdifSchemaLoader();
    SchemaLoader loader = new JarLdifSchemaLoader();
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    schemaManager.loadAllEnabled();
    ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry();
    for (LdapComparator<?> comparator : comparatorRegistry) {
        if (comparator instanceof NormalizingComparator) {
            ((NormalizingComparator) comparator).setOnServer();
        }
    }
    directoryService.setSchemaManager(schemaManager);
    InMemorySchemaPartition inMemorySchemaPartition = new InMemorySchemaPartition(schemaManager);
    SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
    schemaPartition.setWrappedPartition(inMemorySchemaPartition);
    directoryService.setSchemaPartition(schemaPartition);
    List<Throwable> errors = schemaManager.getErrors();
    if (errors.size() != 0) {
        throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
    }
    DnFactory dnFactory = new DefaultDnFactory(schemaManager, cacheService.getCache("dnCache"));
    // Init system partition
    Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), dnFactory, "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);
    directoryService.startup();
}
Also used : InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) Partition(org.apache.directory.server.core.api.partition.Partition) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) SchemaLoader(org.apache.directory.api.ldap.model.schema.registries.SchemaLoader) JarLdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader) Configuration(net.sf.ehcache.config.Configuration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) DefaultDnFactory(org.apache.directory.server.core.shared.DefaultDnFactory) NormalizingComparator(org.apache.directory.api.ldap.model.schema.comparators.NormalizingComparator) IOException(java.io.IOException) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) SubschemaAdministrativePoint(org.apache.directory.server.core.api.administrative.SubschemaAdministrativePoint) TriggerExecutionAdministrativePoint(org.apache.directory.server.core.api.administrative.TriggerExecutionAdministrativePoint) AccessControlAdministrativePoint(org.apache.directory.server.core.api.administrative.AccessControlAdministrativePoint) CollectiveAttributeAdministrativePoint(org.apache.directory.server.core.api.administrative.CollectiveAttributeAdministrativePoint) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) DnFactory(org.apache.directory.server.core.api.DnFactory) DefaultDnFactory(org.apache.directory.server.core.shared.DefaultDnFactory) JarLdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader) CacheManager(net.sf.ehcache.CacheManager) ComparatorRegistry(org.apache.directory.api.ldap.model.schema.registries.ComparatorRegistry) File(java.io.File) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) CacheService(org.apache.directory.server.core.api.CacheService) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)

Aggregations

SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)8 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)4 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)4 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)4 CreateLdapServer (org.apache.directory.server.annotations.CreateLdapServer)4 CreateDS (org.apache.directory.server.core.annotations.CreateDS)4 ManagedCreateLdapServer (org.jboss.as.test.integration.security.common.ManagedCreateLdapServer)4 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)3 SchemaPartition (org.apache.directory.server.core.api.schema.SchemaPartition)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 SchemaLoader (org.apache.directory.api.ldap.model.schema.registries.SchemaLoader)2 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)2 CacheService (org.apache.directory.server.core.api.CacheService)2 DefaultDnFactory (org.apache.directory.server.core.shared.DefaultDnFactory)2 LdapServer (org.apache.directory.server.ldap.LdapServer)2 FileNotFoundException (java.io.FileNotFoundException)1