org.apache.directory.api.util.exception.Exceptions Java Examples
The following examples show how to use
org.apache.directory.api.util.exception.Exceptions.
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: LdifSchemaLoaderTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
@Test public void testLoader() throws Exception { SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( tmpFolder.toFile() ); extractor.extractOrCopy(); LdifSchemaLoader loader = new LdifSchemaLoader( new File( tmpFolder.toFile(), "schema" ) ); SchemaManager sm = new DefaultSchemaManager( loader ); boolean loaded = sm.loadAllEnabled(); if ( !loaded ) { fail( "Schema load failed : " + Exceptions.printErrors( sm.getErrors() ) ); } assertTrue( sm.getRegistries().getAttributeTypeRegistry().contains( "cn" ) ); }
Example #2
Source File: QuirkySchemaTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Try to load a very minimal (and correct) schema. It has just 'person' objectclass and all * the necessary attributes, matching rules and syntaxes. Load it in strict mode. * This test is here mostly to make sure that the test itself works. */ @Test public void testLoadMinimalSchema() throws Exception { LdapConnection connection = createFakeConnection( "src/test/resources/schema-minimal.ldif" ); DefaultSchemaLoader loader = new DefaultSchemaLoader( connection ); Collection<Schema> allEnabled = loader.getAllEnabled(); assertEquals( 1, allEnabled.size() ); Schema schema = allEnabled.iterator().next(); assertNotNull( schema ); assertEquals( 26, schema.getContent().size() ); SchemaManager schemaManager = new DefaultSchemaManager( loader ); boolean loaded = schemaManager.loadAllEnabled(); if ( !loaded ) { fail( "Schema load failed : " + Exceptions.printErrors( schemaManager.getErrors() ) ); } assertTrue( schemaManager.getRegistries().getAttributeTypeRegistry().contains( "cn" ) ); ObjectClass person = schemaManager.getRegistries().getObjectClassRegistry().lookup( "person" ); assertNotNull( person ); assertEquals( 2, person.getMustAttributeTypes().size() ); assertEquals( 4, person.getMayAttributeTypes().size() ); }
Example #3
Source File: QuirkySchemaTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Try to load a quirky schema. This schema has a lot of issues that violate the * standards. Therefore load the schema in relaxed mode. We should be able to work * with this schema anyway. E.g. the loader and schema manager should not die on * null pointer or similar trivial error. */ @Test public void testLoadQuirkySchema() throws Exception { LdapConnection connection = createFakeConnection( "src/test/resources/schema-quirky.ldif" ); DefaultSchemaLoader loader = new DefaultSchemaLoader( connection, true ); Collection<Schema> allEnabled = loader.getAllEnabled(); assertEquals( 1, allEnabled.size() ); Schema schema = allEnabled.iterator().next(); assertNotNull( schema ); SchemaManager schemaManager = new DefaultSchemaManager( loader ); boolean loaded = schemaManager.loadAllEnabledRelaxed(); if ( !loaded ) { fail( "Schema load failed : " + Exceptions.printErrors( schemaManager.getErrors() ) ); } assertTrue ( schemaManager.getErrors().size() > 0, "Surprisingly no errors after load" ); assertTrue( schemaManager.getRegistries().getAttributeTypeRegistry().contains( "cn" ) ); ObjectClass person = schemaManager.getRegistries().getObjectClassRegistry().lookup( "person" ); assertNotNull( person ); assertEquals( 2, person.getMustAttributeTypes().size() ); assertEquals( 5, person.getMayAttributeTypes().size() ); }
Example #4
Source File: LdapTestEnvironment.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
/** * initialize the schema manager and add the schema partition to directory * service * * @throws Exception if the schema LDIF files are not found on the classpath */ protected 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()) { LOG.info("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.isEmpty()) { 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); }
Example #5
Source File: InMemoryDirectoryServiceFactory.java From bouncr with Eclipse Public License 1.0 | 4 votes |
/** * {@inheritDoc} */ 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("default", 1).eternal(false).timeToIdleSeconds(30) .timeToLiveSeconds(30).overflowToDisk(false); ehCacheConfig.addDefaultCache(defaultCache); CacheService cacheService = new CacheService(new CacheManager(ehCacheConfig)); 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(), directoryService.getDnFactory(), "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: 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 #7
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); if (this.dnFactory == null) { this.dnFactory = new DefaultDnFactory(schemaManager, new net.sf.ehcache.Cache(new CacheConfiguration("myvd-apacheds-dns", 10000))); } // Init the LdifPartition with schema LdifPartition schemaLdifPartition = new LdifPartition(schemaManager, this.dnFactory); schemaLdifPartition.setPartitionPath(schemaPartitionDirectory.toURI()); // The schema partition SchemaPartition schemaPartition = new SchemaPartition(schemaManager); schemaPartition.setWrappedPartition(schemaLdifPartition); directoryService.setSchemaPartition(schemaPartition); }
Example #8
Source File: InMemoryDirectoryServiceFactory.java From activemq-artemis with Apache License 2.0 | 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("default", 1).eternal(false).timeToIdleSeconds(30).timeToLiveSeconds(30).overflowToDisk(false); ehCacheConfig.addDefaultCache(defaultCache); CacheService cacheService = new CacheService(new CacheManager(ehCacheConfig)); 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(), directoryService.getDnFactory(), "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 #9
Source File: ApacheDSStartStopListener.java From syncope with Apache License 2.0 | 4 votes |
/** * Initialize the schema manager and add the schema partition to directory service. * * @throws Exception if the schema LDIF files are not found on the classpath */ private void initSchemaPartition() throws Exception { File workingDirectory = service.getInstanceLayout().getPartitionsDirectory(); // Extract the schema on disk (a brand new one) and load the registries File schemaRepository = new File(workingDirectory, "schema"); SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(workingDirectory); try { extractor.extractOrCopy(); } catch (IOException ioe) { // The schema has already been extracted, bypass } SchemaLoader loader = new LdifSchemaLoader(schemaRepository); 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(); // Tell all the normalizer comparators that they should not normalize anything ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry(); for (LdapComparator<?> comparator : comparatorRegistry) { if (comparator instanceof NormalizingComparator) { ((NormalizingComparator) comparator).setOnServer(); } } service.setSchemaManager(schemaManager); // Init the LdifPartition LdifPartition ldifPartition = new LdifPartition(schemaManager, service.getDnFactory()); ldifPartition.setPartitionPath(new File(workingDirectory, "schema").toURI()); SchemaPartition schemaPartition = new SchemaPartition(schemaManager); schemaPartition.setWrappedPartition(ldifPartition); service.setSchemaPartition(schemaPartition); List<Throwable> errors = schemaManager.getErrors(); if (!errors.isEmpty()) { throw new IllegalStateException(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors))); } }
Example #10
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 #11
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 #12
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 #13
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 #14
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 ); }