Пример #1
0
        /// <exception cref="System.Exception"/>
        private void InitDirectoryService()
        {
            ds = new DefaultDirectoryService();
            ds.SetInstanceLayout(new InstanceLayout(workDir));
            CacheService cacheService = new CacheService();

            ds.SetCacheService(cacheService);
            // first load the schema
            InstanceLayout instanceLayout           = ds.GetInstanceLayout();
            FilePath       schemaPartitionDirectory = new FilePath(instanceLayout.GetPartitionsDirectory
                                                                       (), "schema");
            SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(instanceLayout.GetPartitionsDirectory
                                                                               ());

            extractor.ExtractOrCopy();
            SchemaLoader  loader        = new LdifSchemaLoader(schemaPartitionDirectory);
            SchemaManager schemaManager = new DefaultSchemaManager(loader);

            schemaManager.LoadAllEnabled();
            ds.SetSchemaManager(schemaManager);
            // Init the LdifPartition with schema
            LdifPartition schemaLdifPartition = new LdifPartition(schemaManager);

            schemaLdifPartition.SetPartitionPath(schemaPartitionDirectory.ToURI());
            // The schema partition
            SchemaPartition schemaPartition = new SchemaPartition(schemaManager);

            schemaPartition.SetWrappedPartition(schemaLdifPartition);
            ds.SetSchemaPartition(schemaPartition);
            JdbmPartition systemPartition = new JdbmPartition(ds.GetSchemaManager());

            systemPartition.SetId("system");
            systemPartition.SetPartitionPath(new FilePath(ds.GetInstanceLayout().GetPartitionsDirectory
                                                              (), systemPartition.GetId()).ToURI());
            systemPartition.SetSuffixDn(new DN(ServerDNConstants.SystemDn));
            systemPartition.SetSchemaManager(ds.GetSchemaManager());
            ds.SetSystemPartition(systemPartition);
            ds.GetChangeLog().SetEnabled(false);
            ds.SetDenormalizeOpAttrsEnabled(true);
            ds.AddLast(new KeyDerivationInterceptor());
            // create one partition
            string orgName = conf.GetProperty(OrgName).ToLower(Extensions.GetEnglishCulture()
                                                               );
            string orgDomain = conf.GetProperty(OrgDomain).ToLower(Extensions.GetEnglishCulture()
                                                                   );
            JdbmPartition partition = new JdbmPartition(ds.GetSchemaManager());

            partition.SetId(orgName);
            partition.SetPartitionPath(new FilePath(ds.GetInstanceLayout().GetPartitionsDirectory
                                                        (), orgName).ToURI());
            partition.SetSuffixDn(new DN("dc=" + orgName + ",dc=" + orgDomain));
            ds.AddPartition(partition);
            // indexes
            ICollection <Index <object, object, string> > indexedAttributes = new HashSet <Index <
                                                                                               object, object, string> >();

            indexedAttributes.AddItem(new JdbmIndex <string, Org.Apache.Directory.Api.Ldap.Model.Entry.Entry
                                                     >("objectClass", false));
            indexedAttributes.AddItem(new JdbmIndex <string, Org.Apache.Directory.Api.Ldap.Model.Entry.Entry
                                                     >("dc", false));
            indexedAttributes.AddItem(new JdbmIndex <string, Org.Apache.Directory.Api.Ldap.Model.Entry.Entry
                                                     >("ou", false));
            partition.SetIndexedAttributes(indexedAttributes);
            // And start the ds
            ds.SetInstanceId(conf.GetProperty(Instance));
            ds.Startup();
            // context entry, after ds.startup()
            DN dn = new DN("dc=" + orgName + ",dc=" + orgDomain);

            Org.Apache.Directory.Api.Ldap.Model.Entry.Entry entry = ds.NewEntry(dn);
            entry.Add("objectClass", "top", "domain");
            entry.Add("dc", orgName);
            ds.GetAdminSession().Add(entry);
        }