use of org.apache.directory.server.core.normalization.NormalizationInterceptor in project keycloak by keycloak.
the class LDAPEmbeddedServer method createDirectoryService.
protected DirectoryService createDirectoryService() throws Exception {
// Parse "keycloak" from "dc=keycloak,dc=org"
String dcName = baseDN.split(",")[0];
dcName = dcName.substring(dcName.indexOf("=") + 1);
if (this.directoryServiceFactory.equals(DSF_INMEMORY)) {
System.setProperty("apacheds.partition.factory", AvlPartitionFactory.class.getName());
} else if (this.directoryServiceFactory.equals(DSF_FILE)) {
System.setProperty("apacheds.partition.factory", JdbmPartitionFactory.class.getName());
} else {
throw new IllegalStateException("Unknown value of directoryServiceFactory: " + this.directoryServiceFactory);
}
DefaultDirectoryServiceFactory dsf = new DefaultDirectoryServiceFactory();
DirectoryService service = dsf.getDirectoryService();
service.setAccessControlEnabled(enableAccessControl);
service.setAllowAnonymousAccess(enableAnonymousAccess);
service.getChangeLog().setEnabled(false);
dsf.init(dcName + "DS");
Partition partition = dsf.getPartitionFactory().createPartition(service.getSchemaManager(), service.getDnFactory(), dcName, this.baseDN, 1000, new File(service.getInstanceLayout().getPartitionsDirectory(), dcName));
partition.initialize();
partition.setSchemaManager(service.getSchemaManager());
// Inject the partition into the DirectoryService
service.addPartition(partition);
// Last, process the context entry
String entryLdif = "dn: " + baseDN + "\n" + "dc: " + dcName + "\n" + "objectClass: top\n" + "objectClass: domain\n\n";
importLdifContent(service, entryLdif);
if (this.directoryServiceFactory.equals(DSF_INMEMORY)) {
// Find Normalization interceptor in chain and add our range emulated interceptor
List<Interceptor> interceptors = service.getInterceptors();
int insertionPosition = -1;
for (int pos = 0; pos < interceptors.size(); ++pos) {
Interceptor interceptor = interceptors.get(pos);
if (interceptor instanceof NormalizationInterceptor) {
insertionPosition = pos;
}
}
RangedAttributeInterceptor interceptor = new RangedAttributeInterceptor("member", PAGE_SIZE);
interceptor.init(service);
interceptors.add(insertionPosition + 1, interceptor);
service.setInterceptors(interceptors);
}
return service;
}
Aggregations