org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager Java Examples
The following examples show how to use
org.apache.directory.api.ldap.schemamanager.impl.DefaultSchemaManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MiniKdc.java From hadoop with Apache License 2.0 | 4 votes |
private void initDirectoryService() throws Exception { ds = new DefaultDirectoryService(); ds.setInstanceLayout(new InstanceLayout(workDir)); CacheService cacheService = new CacheService(); ds.setCacheService(cacheService); // first load the schema InstanceLayout instanceLayout = ds.getInstanceLayout(); File schemaPartitionDirectory = new File( 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 File( ds.getInstanceLayout().getPartitionsDirectory(), systemPartition.getId()).toURI()); systemPartition.setSuffixDn(new Dn(ServerDNConstants.SYSTEM_DN)); 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(ORG_NAME).toLowerCase(Locale.ENGLISH); String orgDomain = conf.getProperty(ORG_DOMAIN).toLowerCase(Locale.ENGLISH); JdbmPartition partition = new JdbmPartition(ds.getSchemaManager()); partition.setId(orgName); partition.setPartitionPath(new File( ds.getInstanceLayout().getPartitionsDirectory(), orgName).toURI()); partition.setSuffixDn(new Dn("dc=" + orgName + ",dc=" + orgDomain)); ds.addPartition(partition); // indexes Set<Index<?, ?, String>> indexedAttributes = new HashSet<Index<?, ?, String>>(); indexedAttributes.add(new JdbmIndex<String, Entry>("objectClass", false)); indexedAttributes.add(new JdbmIndex<String, Entry>("dc", false)); indexedAttributes.add(new JdbmIndex<String, 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); Entry entry = ds.newEntry(dn); entry.add("objectClass", "top", "domain"); entry.add("dc", orgName); ds.getAdminSession().add(entry); }
Example #2
Source File: MiniKdc.java From big-c with Apache License 2.0 | 4 votes |
private void initDirectoryService() throws Exception { ds = new DefaultDirectoryService(); ds.setInstanceLayout(new InstanceLayout(workDir)); CacheService cacheService = new CacheService(); ds.setCacheService(cacheService); // first load the schema InstanceLayout instanceLayout = ds.getInstanceLayout(); File schemaPartitionDirectory = new File( 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 File( ds.getInstanceLayout().getPartitionsDirectory(), systemPartition.getId()).toURI()); systemPartition.setSuffixDn(new Dn(ServerDNConstants.SYSTEM_DN)); 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(ORG_NAME).toLowerCase(Locale.ENGLISH); String orgDomain = conf.getProperty(ORG_DOMAIN).toLowerCase(Locale.ENGLISH); JdbmPartition partition = new JdbmPartition(ds.getSchemaManager()); partition.setId(orgName); partition.setPartitionPath(new File( ds.getInstanceLayout().getPartitionsDirectory(), orgName).toURI()); partition.setSuffixDn(new Dn("dc=" + orgName + ",dc=" + orgDomain)); ds.addPartition(partition); // indexes Set<Index<?, ?, String>> indexedAttributes = new HashSet<Index<?, ?, String>>(); indexedAttributes.add(new JdbmIndex<String, Entry>("objectClass", false)); indexedAttributes.add(new JdbmIndex<String, Entry>("dc", false)); indexedAttributes.add(new JdbmIndex<String, 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); Entry entry = ds.newEntry(dn); entry.add("objectClass", "top", "domain"); entry.add("dc", orgName); ds.getAdminSession().add(entry); }
Example #3
Source File: Server.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * 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 = directoryService.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 ) ) ); } directoryService.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 ); directoryService.setSchemaPartition( schemaPartition ); }
Example #4
Source File: InMemoryDirectoryServiceFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * {@inheritDoc} */ @Override public void init(String name) throws Exception { if ((directoryService != null) && directoryService.isStarted()) { return; } directoryService.setInstanceId(name); // instance layout InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + name); 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 Configuration ehCacheConfig = new Configuration(); CacheConfiguration defaultCache = new CacheConfiguration("ApacheDSTestCache", 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))); } // Init system partition Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), "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(); }
Example #5
Source File: InMemoryDirectoryServiceFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * {@inheritDoc} */ @Override public void init(String name) throws Exception { if ((directoryService != null) && directoryService.isStarted()) { return; } directoryService.setInstanceId(name); // instance layout InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + name); 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 Configuration ehCacheConfig = new Configuration(); CacheConfiguration defaultCache = new CacheConfiguration("ApacheDSTestCache", 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))); } // Init system partition Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), "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(); }
Example #6
Source File: InMemoryDirectoryServiceFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * {@inheritDoc} */ @Override public void init(String name) throws Exception { if ((directoryService != null) && directoryService.isStarted()) { return; } directoryService.setInstanceId(name); // instance layout InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + name); 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 Configuration ehCacheConfig = new Configuration(); CacheConfiguration defaultCache = new CacheConfiguration("ApacheDSTestCache", 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))); } // Init system partition Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), "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(); }
Example #7
Source File: InMemoryDirectoryServiceFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * {@inheritDoc} */ @Override public void init(String name) throws Exception { if ((directoryService != null) && directoryService.isStarted()) { return; } directoryService.setInstanceId(name); // instance layout InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + name); 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 Configuration ehCacheConfig = new Configuration(); CacheConfiguration defaultCache = new CacheConfiguration("ApacheDSTestCache", 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))); } // Init system partition Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), "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(); }
Example #8
Source File: Runner.java From aws-iam-ldap-bridge with Apache License 2.0 | 4 votes |
/** * 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 ); }