Search in sources :

Example 1 with Partition

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

the class Runner method initDirectoryService.

/**
     * 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();
    utils = new ApacheDSUtils(service);
    //        service = new ApacheDsService();
    //        service.start(new InstanceLayout( workDir ));
    service.setInstanceLayout(new InstanceLayout(workDir));
    CacheService cacheService = new CacheService();
    cacheService.initialize(service.getInstanceLayout());
    service.setCacheService(cacheService);
    // first load the schema
    initSchemaPartition();
    // then the system partition
    // this is a MANDATORY partition
    // DO NOT add this via addPartition() method, trunk code complains about duplicate partition
    // while initializing
    JdbmPartition systemPartition = new JdbmPartition(service.getSchemaManager(), service.getDnFactory());
    systemPartition.setId("system");
    systemPartition.setPartitionPath(new File(service.getInstanceLayout().getPartitionsDirectory(), systemPartition.getId()).toURI());
    systemPartition.setSuffixDn(new Dn(ServerDNConstants.SYSTEM_DN));
    systemPartition.setSchemaManager(service.getSchemaManager());
    // mandatory to call this method to set the system partition
    // Note: this system partition might be removed from trunk
    service.setSystemPartition(systemPartition);
    service.getChangeLog().setEnabled(false);
    service.setDenormalizeOpAttrsEnabled(true);
    SingleFileLdifPartition configPartition = new SingleFileLdifPartition(service.getSchemaManager(), service.getDnFactory());
    configPartition.setId("config");
    configPartition.setPartitionPath(new File(service.getInstanceLayout().getConfDirectory(), "config.ldif").toURI());
    configPartition.setSuffixDn(new Dn(service.getSchemaManager(), "ou=config"));
    configPartition.setSchemaManager(service.getSchemaManager());
    configPartition.setCacheService(cacheService);
    configPartition.initialize();
    service.addPartition(configPartition);
    readIAMProperties();
    String rootDN = AWSIAMAuthenticator.getConfig().rootDN;
    Partition iamPartition = utils.addPartition("iam", rootDN, service.getDnFactory());
    // Index some attributes on the apache partition
    utils.addIndex(iamPartition, "objectClass", "ou", "uid", "gidNumber", "uidNumber", "cn");
    // And start the service
    service.startup();
    utils.loadLdif("iam.ldif");
    utils.loadLdif("enable_nis.ldif");
    utils.loadLdif("auth.ldif");
    if (!utils.exists("cn=config,ads-authenticatorid=awsiamauthenticator,ou=authenticators,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config")) {
        Entry entryIAM = service.newEntry(service.getDnFactory().create("cn=config,ads-authenticatorid=awsiamauthenticator,ou=authenticators,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config"));
        entryIAM.put("objectClass", "iamauthenticatorconfig", "top");
        entryIAM.put(SchemaConstants.ENTRY_CSN_AT, service.getCSN().toString());
        entryIAM.put(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
        entryIAM.put("cn", "config");
        entryIAM.put("idGenerator", "1000");
        service.getAdminSession().add(entryIAM);
    }
    Dn dnIAM = service.getDnFactory().create(rootDN);
    if (!service.getAdminSession().exists(dnIAM)) {
        Entry entryIAM = new DefaultEntry(service.getSchemaManager(), dnIAM, "objectClass: top", "objectClass: domain", "dc: iam", "entryCsn: " + service.getCSN(), SchemaConstants.ENTRY_UUID_AT + ": " + UUID.randomUUID().toString());
        iamPartition.add(new AddOperationContext(null, entryIAM));
    }
}
Also used : InstanceLayout(org.apache.directory.server.core.api.InstanceLayout) Partition(org.apache.directory.server.core.api.partition.Partition) LdifPartition(org.apache.directory.server.core.partition.ldif.LdifPartition) AbstractBTreePartition(org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition) JdbmPartition(org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition) SingleFileLdifPartition(org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) SingleFileLdifPartition(org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition) JdbmPartition(org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) AddOperationContext(org.apache.directory.server.core.api.interceptor.context.AddOperationContext) DefaultDirectoryService(org.apache.directory.server.core.DefaultDirectoryService) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) IndexEntry(org.apache.directory.server.xdbm.IndexEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) File(java.io.File) CacheService(org.apache.directory.server.core.api.CacheService)

Example 2 with Partition

use of org.apache.directory.server.core.api.partition.Partition 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)

Example 3 with Partition

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

the class Runner method createStructure.

public void createStructure() throws Exception {
    String rootDN = AWSIAMAuthenticator.getConfig().rootDN;
    Dn dnIAM = service.getDnFactory().create(rootDN);
    if (!utils.exists(dnIAM)) {
        IAM_LOG.info("Creating partition " + rootDN);
        Partition iamPartition = utils.addPartition("iam", rootDN, service.getDnFactory());
        // Index some attributes on the apache partition
        utils.addIndex(iamPartition, "objectClass", "ou", "uid", "gidNumber", "uidNumber", "cn");
        if (!utils.exists(dnIAM)) {
            IAM_LOG.info("Creating root node " + rootDN);
            Rdn rdn = dnIAM.getRdn(0);
            Entry entryIAM = new DefaultEntry(service.getSchemaManager(), dnIAM, "objectClass: top", "objectClass: domain", "entryCsn: " + service.getCSN(), SchemaConstants.ENTRY_UUID_AT + ": " + UUID.randomUUID().toString(), rdn.getType() + ": " + rdn.getValue());
            service.getAdminSession().add(entryIAM);
            checkErrors();
        }
    }
    service.sync();
}
Also used : Partition(org.apache.directory.server.core.api.partition.Partition) LdifPartition(org.apache.directory.server.core.partition.ldif.LdifPartition) AbstractBTreePartition(org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition) JdbmPartition(org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition) SingleFileLdifPartition(org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition) SchemaPartition(org.apache.directory.server.core.api.schema.SchemaPartition) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) IndexEntry(org.apache.directory.server.xdbm.IndexEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) ParentIdAndRdn(org.apache.directory.server.xdbm.ParentIdAndRdn) Rdn(org.apache.directory.api.ldap.model.name.Rdn)

Example 4 with Partition

use of org.apache.directory.server.core.api.partition.Partition in project undertow by undertow-io.

the class KerberosKDCUtil method createPartition.

private static void createPartition(final DirectoryServiceFactory dsf, final SchemaManager schemaManager, final String id, final String suffix) throws Exception {
    PartitionFactory pf = dsf.getPartitionFactory();
    Partition p = pf.createPartition(schemaManager, id, suffix, 1000, workingDir.toFile());
    pf.addIndex(p, "krb5PrincipalName", 10);
    p.initialize();
    directoryService.addPartition(p);
}
Also used : Partition(org.apache.directory.server.core.api.partition.Partition) PartitionFactory(org.apache.directory.server.core.factory.PartitionFactory)

Aggregations

Partition (org.apache.directory.server.core.api.partition.Partition)4 SchemaPartition (org.apache.directory.server.core.api.schema.SchemaPartition)3 File (java.io.File)2 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)2 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 Dn (org.apache.directory.api.ldap.model.name.Dn)2 CacheService (org.apache.directory.server.core.api.CacheService)2 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)2 AbstractBTreePartition (org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition)2 JdbmPartition (org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition)2 LdifPartition (org.apache.directory.server.core.partition.ldif.LdifPartition)2 SingleFileLdifPartition (org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition)2 IndexEntry (org.apache.directory.server.xdbm.IndexEntry)2 IOException (java.io.IOException)1 CacheManager (net.sf.ehcache.CacheManager)1 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)1 Configuration (net.sf.ehcache.config.Configuration)1 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)1 Rdn (org.apache.directory.api.ldap.model.name.Rdn)1 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)1