use of org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager in project activemq-artemis by apache.
the class InMemoryDirectoryServiceFactory method init.
/**
* {@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();
}
use of org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager in project wildfly by wildfly.
the class InMemoryDirectoryServiceFactory method init.
/**
* {@inheritDoc}
*/
@Override
public void init(String name) throws Exception {
if ((directoryService == null) || directoryService.isStarted()) {
return;
}
int id = counter++;
directoryService.setInstanceId(name + id);
// instance layout
InstanceLayout instanceLayout = new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + directoryService.getInstanceId());
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
String cacheName = "ApacheDSTestCache-" + id;
Configuration ehCacheConfig = new Configuration();
ehCacheConfig.setName(cacheName);
CacheConfiguration defaultCache = new CacheConfiguration(cacheName, 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)));
}
DnFactory dnFactory = new DefaultDnFactory(schemaManager, cacheService.getCache("dnCache"));
// Init system partition
Partition systemPartition = partitionFactory.createPartition(directoryService.getSchemaManager(), dnFactory, "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();
}
use of org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager in project syncope by apache.
the class ApacheDSStartStopListener method initSchemaPartition.
/**
* 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 {
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.debug("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 IllegalStateException(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);
}
use of org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager in project camunda-bpm-platform by camunda.
the class LdapTestEnvironment method initSchemaPartition.
/**
* 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.log(Level.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);
}
use of org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager in project directory-ldap-api by apache.
the class LdifAnonymizerTest method testLdifAnonymizer.
@Test
public void testLdifAnonymizer() throws Exception {
String ldif = "dn: cn=test,dc=example,dc=com\n" + "ObjectClass: top\n" + "objectClass: person\n" + "cn: test\n" + "sn: Test\n" + "\n" + "dn: cn=emmanuel,dc=acme,dc=com\n" + "ObjectClass: top\n" + "objectClass: person\n" + "cn: emmanuel\n" + "sn: lecharnye\n" + "\n" + "dn: cn=emmanuel,dc=test,dc=example,dc=com\n" + "ObjectClass: top\n" + "objectClass: person\n" + "cn: emmanuel\n" + "seeAlso: cn=emmanuel,dc=acme,dc=com\n" + "sn: elecharny\n";
SchemaManager schemaManager = null;
try {
schemaManager = new DefaultSchemaManager();
} catch (Exception e) {
// Todo : we need a schemaManager
System.out.println("Missing a SchemaManager !");
System.exit(-1);
}
LdifAnonymizer anonymizer = new LdifAnonymizer(schemaManager);
anonymizer.addNamingContext("dc=example,dc=com");
anonymizer.addNamingContext("dc=acme,dc=com");
anonymizer.removeAnonAttributeType(schemaManager.getAttributeType("sn"));
String result = anonymizer.anonymize(ldif);
List<LdifEntry> entries = ldifReader.parseLdif(result);
assertEquals(3, entries.size());
// First entry
LdifEntry ldifEntry = entries.get(0);
assertTrue(ldifEntry.isEntry());
Entry entry = ldifEntry.getEntry();
assertEquals(3, entry.size());
assertEquals("cn=AAAA,dc=example,dc=com", entry.getDn().toString());
Attribute cn = entry.get("cn");
assertEquals("AAAA", cn.getString());
Attribute sn = entry.get("sn");
assertEquals("Test", sn.getString());
// Second entry
ldifEntry = entries.get(1);
assertTrue(ldifEntry.isEntry());
entry = ldifEntry.getEntry();
assertEquals(3, entry.size());
assertEquals("cn=AAAAAAAA,dc=acme,dc=com", entry.getDn().toString());
cn = entry.get("cn");
assertEquals("AAAAAAAA", cn.getString());
sn = entry.get("sn");
assertEquals("lecharnye", sn.getString());
// Third entry
ldifEntry = entries.get(2);
assertTrue(ldifEntry.isEntry());
entry = ldifEntry.getEntry();
assertEquals(4, entry.size());
assertEquals("cn=AAAAAAAA,dc=AAAA,dc=example,dc=com", entry.getDn().toString());
cn = entry.get("cn");
assertEquals("AAAAAAAA", cn.getString());
sn = entry.get("sn");
assertEquals("elecharny", sn.getString());
Attribute seeAlso = entry.get("seeAlso");
assertEquals("cn=AAAAAAAA,dc=acme,dc=com", seeAlso.getString());
}
Aggregations