Ejemplo n.º 1
0
        /// <summary>
        /// initialize the schema manager and add the schema partition to directory
        /// service
        /// </summary>
        /// <exception cref="Exception"> if the schema LDIF files are not found on the classpath </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void initSchemaPartition() throws Exception
        protected internal virtual void initSchemaPartition()
        {
            InstanceLayout instanceLayout = service.InstanceLayout;

            File schemaPartitionDirectory = new File(instanceLayout.PartitionsDirectory, "schema");

            // Extract the schema on disk (a brand new one) and load the registries
            if (schemaPartitionDirectory.exists())
            {
                LOG.info("schema partition already exists, skipping schema extraction");
            }
            else
            {
                SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(instanceLayout.PartitionsDirectory);
                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();

            IList <Exception> errors = schemaManager.Errors;

            if (errors.Count > 0)
            {
                throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
            }

            service.SchemaManager = schemaManager;

            // Init the LdifPartition with schema
            LdifPartition schemaLdifPartition = new LdifPartition(schemaManager, service.DnFactory);

            schemaLdifPartition.PartitionPath = schemaPartitionDirectory.toURI();

            // The schema partition
            SchemaPartition schemaPartition = new SchemaPartition(schemaManager);

            schemaPartition.WrappedPartition = schemaLdifPartition;
            service.SchemaPartition          = schemaPartition;
        }
Ejemplo n.º 2
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);
        }