use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project activemq-artemis by apache.
the class InMemorySchemaPartition method doInit.
/**
* Partition initialization - loads schema entries from the files on classpath.
*
* @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit()
*/
@Override
protected void doInit() throws InvalidNameException, Exception {
if (initialized) {
return;
}
LOG.debug("Initializing schema partition " + getId());
suffixDn.apply(schemaManager);
super.doInit();
// load schema
final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*"));
for (String resourcePath : new TreeSet<>(resMap.keySet())) {
if (resourcePath.endsWith(".ldif")) {
URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file");
LdifEntry ldifEntry;
try (LdifReader reader = new LdifReader(resource.openStream())) {
ldifEntry = reader.next();
}
Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry());
// add mandatory attributes
if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) {
entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString());
}
if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) {
entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
}
AddOperationContext addContext = new AddOperationContext(null, entry);
super.add(addContext);
}
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project activemq-artemis by apache.
the class LdapServer method importLdif.
private void importLdif(DirectoryService directoryService, final SchemaManager schemaManager, LdifReader ldifReader) throws Exception {
try {
for (LdifEntry ldifEntry : ldifReader) {
checkPartition(ldifEntry);
directoryService.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
}
} finally {
try {
ldifReader.close();
} catch (IOException ioe) {
// ignore
}
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project wildfly by wildfly.
the class InMemorySchemaPartition method doInit.
/**
* Partition initialization - loads schema entries from the files on classpath.
*
* @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit()
*/
@Override
protected void doInit() throws Exception {
if (initialized)
return;
LOG.debug("Initializing schema partition " + getId());
suffixDn.apply(schemaManager);
super.doInit();
// load schema
final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*"));
for (String resourcePath : new TreeSet<String>(resMap.keySet())) {
if (resourcePath.endsWith(".ldif")) {
URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file");
LdifReader reader = new LdifReader(resource.openStream());
LdifEntry ldifEntry = reader.next();
reader.close();
Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry());
// add mandatory attributes
if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) {
entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString());
}
if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) {
entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
}
AddOperationContext addContext = new AddOperationContext(null, entry);
super.add(addContext);
}
}
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project midpoint by Evolveum.
the class AbstractAdLdapMultidomainTest method createUnderMeleeEntry.
protected void createUnderMeleeEntry() throws LdapException, IOException {
// This OU just gets into the way of the delete.
Entry entry = new DefaultEntry("ou=underMelee," + toOrgDn(GROUP_MELEE_ISLAND_ALT_NAME), "objectclass", "organizationalUnit", "ou", "underMelee");
displayValue("underMelee org", entry);
addLdapEntry(entry);
}
use of org.apache.directory.api.ldap.model.entry.DefaultEntry in project aws-iam-ldap-bridge by denismo.
the class Runner method initDirectoryService.
/**
* 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();
utils = new ApacheDSUtils(service);
// service = new ApacheDsService();
// service.start(new InstanceLayout( workDir ));
service.setInstanceLayout(new InstanceLayout(workDir));
CacheService cacheService = new CacheService();
cacheService.initialize(service.getInstanceLayout());
service.setCacheService(cacheService);
// first load the schema
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);
service.getChangeLog().setEnabled(false);
service.setDenormalizeOpAttrsEnabled(true);
SingleFileLdifPartition configPartition = new SingleFileLdifPartition(service.getSchemaManager(), service.getDnFactory());
configPartition.setId("config");
configPartition.setPartitionPath(new File(service.getInstanceLayout().getConfDirectory(), "config.ldif").toURI());
configPartition.setSuffixDn(new Dn(service.getSchemaManager(), "ou=config"));
configPartition.setSchemaManager(service.getSchemaManager());
configPartition.setCacheService(cacheService);
configPartition.initialize();
service.addPartition(configPartition);
readIAMProperties();
String rootDN = AWSIAMAuthenticator.getConfig().rootDN;
Partition iamPartition = utils.addPartition("iam", rootDN, service.getDnFactory());
// Index some attributes on the apache partition
utils.addIndex(iamPartition, "objectClass", "ou", "uid", "gidNumber", "uidNumber", "cn");
// And start the service
service.startup();
utils.loadLdif("iam.ldif");
utils.loadLdif("enable_nis.ldif");
utils.loadLdif("auth.ldif");
if (!utils.exists("cn=config,ads-authenticatorid=awsiamauthenticator,ou=authenticators,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config")) {
Entry entryIAM = service.newEntry(service.getDnFactory().create("cn=config,ads-authenticatorid=awsiamauthenticator,ou=authenticators,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config"));
entryIAM.put("objectClass", "iamauthenticatorconfig", "top");
entryIAM.put(SchemaConstants.ENTRY_CSN_AT, service.getCSN().toString());
entryIAM.put(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
entryIAM.put("cn", "config");
entryIAM.put("idGenerator", "1000");
service.getAdminSession().add(entryIAM);
}
Dn dnIAM = service.getDnFactory().create(rootDN);
if (!service.getAdminSession().exists(dnIAM)) {
Entry entryIAM = new DefaultEntry(service.getSchemaManager(), dnIAM, "objectClass: top", "objectClass: domain", "dc: iam", "entryCsn: " + service.getCSN(), SchemaConstants.ENTRY_UUID_AT + ": " + UUID.randomUUID().toString());
iamPartition.add(new AddOperationContext(null, entryIAM));
}
}
Aggregations