org.apache.directory.server.constants.ServerDNConstants Java Examples
The following examples show how to use
org.apache.directory.server.constants.ServerDNConstants.
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: CarbonDirectoryServiceFactory.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Inits the system partition. * * @throws Exception the exception */ private void initSystemPartition() throws Exception { // change the working apacheds to something that is unique // on the system and somewhere either under target apacheds // or somewhere in a temp area of the machine. // Inject the System Partition Partition systemPartition = partitionFactory.createPartition( "system", ServerDNConstants.SYSTEM_DN, PARTITION_CACHE_SIZE, new File(directoryService.getWorkingDirectory(), "system")); systemPartition.setSchemaManager(directoryService.getSchemaManager()); partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, INDEX_CACHE_SIZE); directoryService.setSystemPartition(systemPartition); }
Example #2
Source File: ApacheDSStartStopListener.java From syncope with Apache License 2.0 | 6 votes |
private void initSystemPartition() throws Exception { JdbmPartitionFactory partitionFactory = new JdbmPartitionFactory(); Partition systemPartition = partitionFactory.createPartition( service.getSchemaManager(), service.getDnFactory(), "system", ServerDNConstants.SYSTEM_DN, 500, new File(service.getInstanceLayout().getPartitionsDirectory(), "system")); systemPartition.setSchemaManager(service.getSchemaManager()); partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100); service.setSystemPartition(systemPartition); }
Example #3
Source File: LdapIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
private LdapContext getWiredContext(int port) throws Exception { Hashtable<String, String> env = new Hashtable<String, String>(); env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" ); env.put( Context.PROVIDER_URL, Network.ldapLoopbackUrl( port ) ); env.put( Context.SECURITY_PRINCIPAL, ServerDNConstants.ADMIN_SYSTEM_DN ); env.put( Context.SECURITY_CREDENTIALS, "secret" ); env.put( Context.SECURITY_AUTHENTICATION, "simple" ); LdapApiService ldapApiService = new StandaloneLdapApiService(); return new InitialLdapContext( env, JndiUtils.toJndiControls(ldapApiService, null ) ); }
Example #4
Source File: DefaultCoreSession.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * TODO - perhaps we should just use a flag that is calculated on creation * of this session * * @see org.apache.directory.server.core.api.CoreSession#isAdministrator() */ public boolean isAdministrator() { String normName = getEffectivePrincipal().getName(); return normName.equals( ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED ); }
Example #5
Source File: DefaultPartitionNexus.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Creates the root nexus singleton of the entire system. The root DSE has * several attributes that are injected into it besides those that may * already exist. As partitions are added to the system more namingContexts * attributes are added to the rootDSE. * * @see <a href="http://www.faqs.org/rfcs/rfc3045.html">Vendor Information</a> * @param rootDse the root entry for the DSA * @throws javax.naming.Exception on failure to initialize */ public DefaultPartitionNexus( Entry rootDse ) throws Exception { id = ID; suffixDn = null; // setup that root DSE this.rootDse = rootDse; // Add the basic informations rootDse.put( SchemaConstants.SUBSCHEMA_SUBENTRY_AT, ServerDNConstants.CN_SCHEMA_DN ); rootDse.put( SchemaConstants.SUPPORTED_LDAP_VERSION_AT, "3" ); rootDse.put( SchemaConstants.SUPPORTED_FEATURES_AT, SchemaConstants.FEATURE_ALL_OPERATIONAL_ATTRIBUTES ); rootDse.put( SchemaConstants.SUPPORTED_EXTENSION_AT, NoticeOfDisconnect.EXTENSION_OID ); // Add the objectClasses rootDse.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.EXTENSIBLE_OBJECT_OC ); // Add the 'vendor' name and version infos rootDse.put( SchemaConstants.VENDOR_NAME_AT, ASF ); Properties props = new Properties(); try { props.load( getClass().getResourceAsStream( "version.properties" ) ); } catch ( IOException e ) { LOG.error( I18n.err( I18n.ERR_33 ) ); } rootDse.put( SchemaConstants.VENDOR_VERSION_AT, props.getProperty( "apacheds.version", "UNKNOWN" ) ); // The rootDSE uuid has been randomly created rootDse.put( SchemaConstants.ENTRY_UUID_AT, "f290425c-8272-4e62-8a67-92b06f38dbf5" ); }
Example #6
Source File: DefaultCoreSession.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * TODO - perhaps we should just use a flag that is calculated on creation * of this session * * @see org.apache.directory.server.core.api.CoreSession#isAdministrator() */ public boolean isAdministrator() { String normName = getEffectivePrincipal().getName(); return normName.equals( ServerDNConstants.ADMIN_SYSTEM_DN_NORMALIZED ); }
Example #7
Source File: DefaultPartitionNexus.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Creates the root nexus singleton of the entire system. The root DSE has * several attributes that are injected into it besides those that may * already exist. As partitions are added to the system more namingContexts * attributes are added to the rootDSE. * * @see <a href="http://www.faqs.org/rfcs/rfc3045.html">Vendor Information</a> * @param rootDse the root entry for the DSA * @throws javax.naming.Exception on failure to initialize */ public DefaultPartitionNexus( Entry rootDse ) throws Exception { id = ID; suffixDn = null; // setup that root DSE this.rootDse = rootDse; // Add the basic informations rootDse.put( SchemaConstants.SUBSCHEMA_SUBENTRY_AT, ServerDNConstants.CN_SCHEMA_DN ); rootDse.put( SchemaConstants.SUPPORTED_LDAP_VERSION_AT, "3" ); rootDse.put( SchemaConstants.SUPPORTED_FEATURES_AT, SchemaConstants.FEATURE_ALL_OPERATIONAL_ATTRIBUTES ); rootDse.put( SchemaConstants.SUPPORTED_EXTENSION_AT, NoticeOfDisconnect.EXTENSION_OID ); // Add the objectClasses rootDse.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.EXTENSIBLE_OBJECT_OC ); // Add the 'vendor' name and version infos rootDse.put( SchemaConstants.VENDOR_NAME_AT, ASF ); Properties props = new Properties(); try { props.load( getClass().getResourceAsStream( "version.properties" ) ); } catch ( IOException e ) { LOG.error( I18n.err( I18n.ERR_33 ) ); } rootDse.put( SchemaConstants.VENDOR_VERSION_AT, props.getProperty( "apacheds.version", "UNKNOWN" ) ); // The rootDSE uuid has been randomly created rootDse.put( SchemaConstants.ENTRY_UUID_AT, "f290425c-8272-4e62-8a67-92b06f38dbf5" ); }
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: LdapTestEnvironment.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
/** * Initialize the server. It creates the partition, adds the index, and * injects the context entries for the created partitions. * * @throws Exception if there were some problems while initializing the system */ protected void initializeDirectory() throws Exception { workingDirectory.mkdirs(); service = new DefaultDirectoryService(); InstanceLayout il = new InstanceLayout(workingDirectory); service.setInstanceLayout(il); CacheService cacheService = new CacheService(); cacheService.initialize(service.getInstanceLayout()); service.setCacheService(cacheService); 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); // Disable the ChangeLog system service.getChangeLog().setEnabled(false); service.setDenormalizeOpAttrsEnabled(true); Partition camundaPartition = addPartition("camunda", BASE_DN, service.getDnFactory()); addIndex(camundaPartition, "objectClass", "ou", "uid"); service.startup(); // Create the root entry if (!service.getAdminSession().exists(camundaPartition.getSuffixDn())) { Dn dn = new Dn(BASE_DN); Entry entry = service.newEntry(dn); entry.add("objectClass", "top", "domain", "extensibleObject"); entry.add("dc", "camunda"); service.getAdminSession().add(entry); } }
Example #10
Source File: EmbeddedADS.java From vertx-auth with Apache License 2.0 | 4 votes |
/** * 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(); service.setWorkingDirectory(workDir); // first load the schema initSchemaPartition(); // then the system partition // this is a MANDATORY partition Partition systemPartition = addPartition("system", ServerDNConstants.SYSTEM_DN); service.setSystemPartition(systemPartition); // Disable the ChangeLog system service.getChangeLog().setEnabled(false); service.setDenormalizeOpAttrsEnabled(true); // Now we can create as many partitions as we need // Create some new partitions named 'foo', 'bar' and 'apache'. Partition fooPartition = addPartition("foo", "dc=foo,dc=com"); // Index some attributes on the apache partition addIndex(fooPartition, "objectClass", "ou", "uid"); // And start the service service.startup(); DN dnFoo = new DN("dc=foo,dc=com"); ServerEntry entryFoo = service.newEntry(dnFoo); entryFoo.add("objectClass", "top", "domain", "extensibleObject"); entryFoo.add("dc", "foo"); service.getAdminSession().add(entryFoo); DN usersDN=new DN("ou=users,dc=foo,dc=com"); ServerEntry usersEntry=service.newEntry(usersDN); usersEntry.add("objectClass","organizationalUnit","top"); usersEntry.add("ou","users"); service.getAdminSession().add(usersEntry); }
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: 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 #15
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 #16
Source File: LdapTestServer.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Initialize the server. It creates the partition, injects the context * entries for the created partitions, and loads an LDIF file ( * {@link #ldifLoadFile}) for initial entries. * * @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(); service.setWorkingDirectory(workDir); // first load the schema initSchemaPartition(); // then the system partition // this is a MANDATORY partition Partition systemPartition = addPartition("system", ServerDNConstants.SYSTEM_DN); service.setSystemPartition(systemPartition); // create the partition for testing Partition testingPartition = addPartition("ldapTesting", "ou=ldapTesting,dc=pune,dc=gemstone,dc=com"); // Disable the shutdown hook service.setShutdownHookEnabled(false); // Disable the ChangeLog system service.getChangeLog().setEnabled(false); service.setDenormalizeOpAttrsEnabled(true); // And start the service service.startup(); // inject the entry for testing if (!service.getAdminSession().exists(testingPartition.getSuffixDn())) { DN dnTesting = new DN("ou=ldapTesting,dc=pune,dc=gemstone,dc=com"); ServerEntry entryTesting = service.newEntry(dnTesting); entryTesting.add("objectClass", "top", "domain", "extensibleObject"); entryTesting.add("dc", "pune"); service.getAdminSession().add(entryTesting); } // load schema from LDIF if (ldifLoadFile != null) { LdifFileLoader ldifLoader = new LdifFileLoader( service.getAdminSession(), ldifLoadFile); int numLoaded = ldifLoader.execute(); if (numLoaded <= 0) { throw new Exception( "Failed to load any entries from " + ldifLoadFile); } else { System.out.println( "LDAP loaded " + numLoaded + " entries from " + ldifLoadFile); } } }
Example #17
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 #18
Source File: LdapTestServer.java From gemfirexd-oss with Apache License 2.0 | 4 votes |
/** * Initialize the server. It creates the partition, injects the context * entries for the created partitions, and loads an LDIF file ( * {@link #ldifLoadFile}) for initial entries. * * @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(); service.setWorkingDirectory(workDir); // first load the schema initSchemaPartition(); // then the system partition // this is a MANDATORY partition Partition systemPartition = addPartition("system", ServerDNConstants.SYSTEM_DN); service.setSystemPartition(systemPartition); // create the partition for testing Partition testingPartition = addPartition("ldapTesting", "ou=ldapTesting,dc=pune,dc=gemstone,dc=com"); // Disable the shutdown hook service.setShutdownHookEnabled(false); // Disable the ChangeLog system service.getChangeLog().setEnabled(false); service.setDenormalizeOpAttrsEnabled(true); // And start the service service.startup(); // inject the entry for testing if (!service.getAdminSession().exists(testingPartition.getSuffixDn())) { DN dnTesting = new DN("ou=ldapTesting,dc=pune,dc=gemstone,dc=com"); ServerEntry entryTesting = service.newEntry(dnTesting); entryTesting.add("objectClass", "top", "domain", "extensibleObject"); entryTesting.add("dc", "pune"); service.getAdminSession().add(entryTesting); } // load schema from LDIF if (ldifLoadFile != null) { LdifFileLoader ldifLoader = new LdifFileLoader( service.getAdminSession(), ldifLoadFile); int numLoaded = ldifLoader.execute(); if (numLoaded <= 0) { throw new Exception( "Failed to load any entries from " + ldifLoadFile); } else { System.out.println( "LDAP loaded " + numLoaded + " entries from " + ldifLoadFile); } } }
Example #19
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(); }