Search in sources :

Example 1 with SearchOperationContext

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();
    }
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) ConcreteNameComponentNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.ConcreteNameComponentNormalizer) FilterNormalizingVisitor(org.apache.directory.server.core.api.normalization.FilterNormalizingVisitor) Dn(org.apache.directory.api.ldap.model.name.Dn) SearchOperationContext(org.apache.directory.server.core.api.interceptor.context.SearchOperationContext) NameComponentNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NameComponentNormalizer) ConcreteNameComponentNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.ConcreteNameComponentNormalizer) EntryFilteringCursor(org.apache.directory.server.core.api.filtering.EntryFilteringCursor)

Example 2 with SearchOperationContext

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);
    }
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) ConcreteNameComponentNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.ConcreteNameComponentNormalizer) FilterNormalizingVisitor(org.apache.directory.server.core.api.normalization.FilterNormalizingVisitor) Dn(org.apache.directory.api.ldap.model.name.Dn) SearchOperationContext(org.apache.directory.server.core.api.interceptor.context.SearchOperationContext) NameComponentNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.NameComponentNormalizer) ConcreteNameComponentNormalizer(org.apache.directory.api.ldap.model.schema.normalizers.ConcreteNameComponentNormalizer) EntryFilteringCursor(org.apache.directory.server.core.api.filtering.EntryFilteringCursor)

Aggregations

ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)2 Dn (org.apache.directory.api.ldap.model.name.Dn)2 ConcreteNameComponentNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.ConcreteNameComponentNormalizer)2 NameComponentNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NameComponentNormalizer)2 EntryFilteringCursor (org.apache.directory.server.core.api.filtering.EntryFilteringCursor)2 SearchOperationContext (org.apache.directory.server.core.api.interceptor.context.SearchOperationContext)2 FilterNormalizingVisitor (org.apache.directory.server.core.api.normalization.FilterNormalizingVisitor)2