Search in sources :

Example 1 with DefaultDirectoryService

use of org.apache.directory.server.core.DefaultDirectoryService 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 DefaultDirectoryService

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

Aggregations

File (java.io.File)2 DefaultDirectoryService (org.apache.directory.server.core.DefaultDirectoryService)2 CacheService (org.apache.directory.server.core.api.CacheService)2 InstanceLayout (org.apache.directory.server.core.api.InstanceLayout)2 SchemaPartition (org.apache.directory.server.core.api.schema.SchemaPartition)2 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)1 Entry (org.apache.directory.api.ldap.model.entry.Entry)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)1 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)1 AddOperationContext (org.apache.directory.server.core.api.interceptor.context.AddOperationContext)1 Partition (org.apache.directory.server.core.api.partition.Partition)1 AvlPartition (org.apache.directory.server.core.partition.impl.avl.AvlPartition)1 AbstractBTreePartition (org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition)1 JdbmPartition (org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition)1 LdifPartition (org.apache.directory.server.core.partition.ldif.LdifPartition)1 SingleFileLdifPartition (org.apache.directory.server.core.partition.ldif.SingleFileLdifPartition)1 DefaultDnFactory (org.apache.directory.server.core.shared.DefaultDnFactory)1 LdapServer (org.apache.directory.server.ldap.LdapServer)1 IndexEntry (org.apache.directory.server.xdbm.IndexEntry)1