Search in sources :

Example 1 with EntryFilteringCursor

use of org.apache.directory.server.core.api.filtering.EntryFilteringCursor 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)

Example 2 with EntryFilteringCursor

use of org.apache.directory.server.core.api.filtering.EntryFilteringCursor 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 3 with EntryFilteringCursor

use of org.apache.directory.server.core.api.filtering.EntryFilteringCursor in project activemq-artemis by apache.

the class SaslKrb5LDAPSecurityTest method dumpLdapContents.

private void dumpLdapContents() throws Exception {
    EntryFilteringCursor cursor = getService().getAdminSession().search(new Dn("ou=system"), SearchScope.SUBTREE, new PresenceNode("ObjectClass"), AliasDerefMode.DEREF_ALWAYS);
    String st = "";
    while (cursor.next()) {
        Entry entry = cursor.get();
        String ss = LdifUtils.convertToLdif(entry);
        st += ss + "\n";
    }
    System.out.println(st);
    cursor = getService().getAdminSession().search(new Dn("dc=example,dc=com"), SearchScope.SUBTREE, new PresenceNode("ObjectClass"), AliasDerefMode.DEREF_ALWAYS);
    st = "";
    while (cursor.next()) {
        Entry entry = cursor.get();
        String ss = LdifUtils.convertToLdif(entry);
        st += ss + "\n";
    }
    System.out.println(st);
}
Also used : ContextEntry(org.apache.directory.server.core.annotations.ContextEntry) KeytabEntry(org.apache.directory.server.kerberos.shared.keytab.KeytabEntry) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdifEntry(org.apache.directory.api.ldap.model.ldif.LdifEntry) PresenceNode(org.apache.directory.api.ldap.model.filter.PresenceNode) Dn(org.apache.directory.api.ldap.model.name.Dn) EntryFilteringCursor(org.apache.directory.server.core.api.filtering.EntryFilteringCursor)

Aggregations

Dn (org.apache.directory.api.ldap.model.name.Dn)3 EntryFilteringCursor (org.apache.directory.server.core.api.filtering.EntryFilteringCursor)3 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)2 ConcreteNameComponentNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.ConcreteNameComponentNormalizer)2 NameComponentNormalizer (org.apache.directory.api.ldap.model.schema.normalizers.NameComponentNormalizer)2 SearchOperationContext (org.apache.directory.server.core.api.interceptor.context.SearchOperationContext)2 FilterNormalizingVisitor (org.apache.directory.server.core.api.normalization.FilterNormalizingVisitor)2 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)1 Entry (org.apache.directory.api.ldap.model.entry.Entry)1 PresenceNode (org.apache.directory.api.ldap.model.filter.PresenceNode)1 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)1 ContextEntry (org.apache.directory.server.core.annotations.ContextEntry)1 KeytabEntry (org.apache.directory.server.kerberos.shared.keytab.KeytabEntry)1