use of org.apache.directory.server.core.api.interceptor.context.SearchOperationContext in project aws-iam-ldap-bridge by denismo.
the class LDAPIAMPoller method getAllEntries.
private Collection<Entry> getAllEntries(String rootDN, String className) {
try {
Dn dn = directory.getDnFactory().create(rootDN);
dn.apply(directory.getSchemaManager());
ExprNode filter = FilterParser.parse(directory.getSchemaManager(), String.format("(ObjectClass=%s)", className));
NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer(directory.getSchemaManager());
FilterNormalizingVisitor visitor = new FilterNormalizingVisitor(ncn, directory.getSchemaManager());
filter.accept(visitor);
SearchOperationContext context = new SearchOperationContext(directory.getAdminSession(), dn, SearchScope.SUBTREE, filter, SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES);
EntryFilteringCursor cursor = directory.getPartitionNexus().search(context);
cursor.beforeFirst();
Collection<Entry> entries = new ArrayList<Entry>();
while (cursor.next()) {
Entry ent = cursor.get();
if (ent.getDn().equals(dn))
continue;
entries.add(ent);
}
cursor.close();
return entries;
} catch (Throwable e) {
return Collections.emptyList();
}
}
use of org.apache.directory.server.core.api.interceptor.context.SearchOperationContext in project aws-iam-ldap-bridge by denismo.
the class LDAPIAMPoller method clearDN.
private void clearDN(String dnStr) throws LdapException, ParseException, IOException, CursorException {
Dn dn = directory.getDnFactory().create(dnStr);
dn.apply(directory.getSchemaManager());
ExprNode filter = FilterParser.parse(directory.getSchemaManager(), "(ObjectClass=*)");
NameComponentNormalizer ncn = new ConcreteNameComponentNormalizer(directory.getSchemaManager());
FilterNormalizingVisitor visitor = new FilterNormalizingVisitor(ncn, directory.getSchemaManager());
filter.accept(visitor);
SearchOperationContext context = new SearchOperationContext(directory.getAdminSession(), dn, SearchScope.SUBTREE, filter, SchemaConstants.ALL_USER_ATTRIBUTES, SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES);
EntryFilteringCursor cursor = directory.getPartitionNexus().search(context);
cursor.beforeFirst();
Collection<Dn> dns = new ArrayList<Dn>();
while (cursor.next()) {
Entry ent = cursor.get();
if (ent.getDn().equals(dn))
continue;
dns.add(ent.getDn());
}
cursor.close();
LOG.debug("Deleting " + dns.size() + " items from under " + dnStr);
for (Dn deleteDn : dns) {
directory.getAdminSession().delete(deleteDn);
}
}
Aggregations