Search in sources :

Example 1 with SearchScope

use of org.apache.directory.api.ldap.model.message.SearchScope in project directory-ldap-api by apache.

the class SearchRequestDsml method toDsml.

/**
 * {@inheritDoc}
 */
@Override
public Element toDsml(Element root) {
    Element element = super.toDsml(root);
    SearchRequest request = getDecorated();
    // Dn
    if (request.getBase() != null) {
        element.addAttribute("dn", request.getBase().getName());
    }
    // Scope
    SearchScope scope = request.getScope();
    if (scope != null) {
        if (scope == SearchScope.OBJECT) {
            element.addAttribute("scope", "baseObject");
        } else if (scope == SearchScope.ONELEVEL) {
            element.addAttribute("scope", "singleLevel");
        } else if (scope == SearchScope.SUBTREE) {
            element.addAttribute("scope", "wholeSubtree");
        }
    }
    // DerefAliases
    AliasDerefMode derefAliases = request.getDerefAliases();
    switch(derefAliases) {
        case NEVER_DEREF_ALIASES:
            element.addAttribute(DEREF_ALIASES, "neverDerefAliases");
            break;
        case DEREF_ALWAYS:
            element.addAttribute(DEREF_ALIASES, "derefAlways");
            break;
        case DEREF_FINDING_BASE_OBJ:
            element.addAttribute(DEREF_ALIASES, "derefFindingBaseObj");
            break;
        case DEREF_IN_SEARCHING:
            element.addAttribute(DEREF_ALIASES, "derefInSearching");
            break;
        default:
            throw new IllegalStateException("Unexpected deref alias mode " + derefAliases);
    }
    // SizeLimit
    if (request.getSizeLimit() != 0L) {
        element.addAttribute("sizeLimit", Long.toString(request.getSizeLimit()));
    }
    // TimeLimit
    if (request.getTimeLimit() != 0) {
        element.addAttribute("timeLimit", Integer.toString(request.getTimeLimit()));
    }
    // TypesOnly
    if (request.getTypesOnly()) {
        element.addAttribute("typesOnly", "true");
    }
    // Filter
    Element filterElement = element.addElement("filter");
    toDsml(filterElement, request.getFilter());
    // Attributes
    List<String> attributes = request.getAttributes();
    if (!attributes.isEmpty()) {
        Element attributesElement = element.addElement("attributes");
        for (String entryAttribute : attributes) {
            attributesElement.addElement("attribute").addAttribute(NAME, entryAttribute);
        }
    }
    return element;
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) Element(org.dom4j.Element) SearchScope(org.apache.directory.api.ldap.model.message.SearchScope) AliasDerefMode(org.apache.directory.api.ldap.model.message.AliasDerefMode)

Example 2 with SearchScope

use of org.apache.directory.api.ldap.model.message.SearchScope in project directory-ldap-api by apache.

the class QuirkySchemaTest method createFakeConnection.

private LdapConnection createFakeConnection(final String schemaFileName) {
    return new LdapConnection() {

        @Override
        public void unBind() throws LdapException {
        }

        @Override
        public void setTimeOut(long timeOut) {
        }

        @Override
        public void setSchemaManager(SchemaManager schemaManager) {
        }

        @Override
        public void setBinaryAttributeDetector(BinaryAttributeDetector binaryAttributeDetecter) {
        }

        @Override
        public SearchCursor search(SearchRequest searchRequest) throws LdapException {
            return null;
        }

        @Override
        public EntryCursor search(String baseDn, String filter, SearchScope scope, String... attributes) throws LdapException {
            return null;
        }

        @Override
        public EntryCursor search(Dn baseDn, String filter, SearchScope scope, String... attributes) throws LdapException {
            return null;
        }

        @Override
        public void rename(Dn entryDn, Rdn newRdn, boolean deleteOldRdn) throws LdapException {
        }

        @Override
        public void rename(String entryDn, String newRdn, boolean deleteOldRdn) throws LdapException {
        }

        @Override
        public void rename(Dn entryDn, Rdn newRdn) throws LdapException {
        }

        @Override
        public void rename(String entryDn, String newRdn) throws LdapException {
        }

        @Override
        public void moveAndRename(String entryDn, String newDn, boolean deleteOldRdn) throws LdapException {
        }

        @Override
        public void moveAndRename(Dn entryDn, Dn newDn, boolean deleteOldRdn) throws LdapException {
        }

        @Override
        public void moveAndRename(String entryDn, String newDn) throws LdapException {
        }

        @Override
        public void moveAndRename(Dn entryDn, Dn newDn) throws LdapException {
        }

        @Override
        public void move(Dn entryDn, Dn newSuperiorDn) throws LdapException {
        }

        @Override
        public void move(String entryDn, String newSuperiorDn) throws LdapException {
        }

        @Override
        public ModifyDnResponse modifyDn(ModifyDnRequest modDnRequest) throws LdapException {
            return null;
        }

        @Override
        public ModifyResponse modify(ModifyRequest modRequest) throws LdapException {
            return null;
        }

        @Override
        public void modify(Entry entry, ModificationOperation modOp) throws LdapException {
        }

        @Override
        public void modify(String dn, Modification... modifications) throws LdapException {
        }

        @Override
        public void modify(Dn dn, Modification... modifications) throws LdapException {
        }

        @Override
        public Entry lookup(String dn, Control[] controls, String... attributes) throws LdapException {
            return lookup(new Dn(dn));
        }

        @Override
        public Entry lookup(String dn, String... attributes) throws LdapException {
            return lookup(new Dn(dn));
        }

        @Override
        public Entry lookup(Dn dn, Control[] controls, String... attributes) throws LdapException {
            return lookup(dn);
        }

        @Override
        public Entry lookup(Dn dn, String... attributes) throws LdapException {
            return lookup(dn);
        }

        @Override
        public Entry lookup(String dn) throws LdapException {
            return lookup(new Dn(dn));
        }

        @Override
        public Entry lookup(Dn dn) throws LdapException {
            if (dn.isRootDse()) {
                Entry entry = new DefaultEntry(dn);
                entry.add(SchemaConstants.SUBSCHEMA_SUBENTRY_AT, SCHEMA_DN);
                return entry;
            } else if (dn.toString().equals(SCHEMA_DN)) {
                Entry entry = loadSchemaEntry(schemaFileName);
                return entry;
            } else {
                throw new UnsupportedOperationException("Unexpected DN " + dn);
            }
        }

        @Override
        public void loadSchemaRelaxed() throws LdapException {
        }

        @Override
        public void loadSchema() throws LdapException {
        }

        @Override
        public boolean isRequestCompleted(int messageId) {
            return true;
        }

        @Override
        public boolean isControlSupported(String controlOID) throws LdapException {
            return true;
        }

        @Override
        public boolean isConnected() {
            return true;
        }

        @Override
        public boolean isAuthenticated() {
            return false;
        }

        @Override
        public List<String> getSupportedControls() throws LdapException {
            return null;
        }

        @Override
        public SchemaManager getSchemaManager() {
            return null;
        }

        @Override
        public Entry getRootDse(String... attributes) throws LdapException {
            return lookup(Dn.ROOT_DSE);
        }

        @Override
        public Entry getRootDse() throws LdapException {
            return lookup(Dn.ROOT_DSE);
        }

        @Override
        public LdapApiService getCodecService() {
            return null;
        }

        @Override
        public BinaryAttributeDetector getBinaryAttributeDetector() {
            return null;
        }

        @Override
        public ExtendedResponse extended(ExtendedRequest extendedRequest) throws LdapException {
            return null;
        }

        @Override
        public ExtendedResponse extended(Oid oid, byte[] value) throws LdapException {
            return null;
        }

        @Override
        public ExtendedResponse extended(Oid oid) throws LdapException {
            return null;
        }

        @Override
        public ExtendedResponse extended(String oid, byte[] value) throws LdapException {
            return null;
        }

        @Override
        public ExtendedResponse extended(String oid) throws LdapException {
            return null;
        }

        @Override
        public boolean exists(Dn dn) throws LdapException {
            return false;
        }

        @Override
        public boolean exists(String dn) throws LdapException {
            return false;
        }

        @Override
        public boolean doesFutureExistFor(int messageId) {
            return false;
        }

        @Override
        public DeleteResponse delete(DeleteRequest deleteRequest) throws LdapException {
            return null;
        }

        @Override
        public void delete(Dn dn) throws LdapException {
        }

        @Override
        public void delete(String dn) throws LdapException {
        }

        @Override
        public boolean connect() throws LdapException {
            return true;
        }

        @Override
        public CompareResponse compare(CompareRequest compareRequest) throws LdapException {
            return null;
        }

        @Override
        public boolean compare(Dn dn, String attributeName, byte[] value) throws LdapException {
            return false;
        }

        @Override
        public boolean compare(Dn dn, String attributeName, String value) throws LdapException {
            return false;
        }

        @Override
        public boolean compare(String dn, String attributeName, byte[] value) throws LdapException {
            return false;
        }

        @Override
        public boolean compare(String dn, String attributeName, String value) throws LdapException {
            return false;
        }

        @Override
        public void close() throws IOException {
        }

        @Override
        public BindResponse bind(BindRequest bindRequest) throws LdapException {
            return null;
        }

        @Override
        public void bind(Dn name, String credentials) throws LdapException {
        }

        @Override
        public void bind(Dn name) throws LdapException {
        }

        @Override
        public void bind(String name, String credentials) throws LdapException {
        }

        @Override
        public void bind(String name) throws LdapException {
        }

        @Override
        public void bind() throws LdapException {
        }

        @Override
        public void anonymousBind() throws LdapException {
        }

        @Override
        public AddResponse add(AddRequest addRequest) throws LdapException {
            return null;
        }

        @Override
        public void add(Entry entry) throws LdapException {
        }

        @Override
        public void abandon(AbandonRequest abandonRequest) {
        }

        @Override
        public void abandon(int messageId) {
        }

        @Override
        public boolean compare(String dn, String attributeName, Value value) throws LdapException {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean compare(Dn dn, String attributeName, Value value) throws LdapException {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public BindResponse bind(SaslRequest saslRequest) throws LdapException {
            // TODO Auto-generated method stub
            return null;
        }
    };
}
Also used : SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) Modification(org.apache.directory.api.ldap.model.entry.Modification) BindRequest(org.apache.directory.api.ldap.model.message.BindRequest) AbandonRequest(org.apache.directory.api.ldap.model.message.AbandonRequest) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Dn(org.apache.directory.api.ldap.model.name.Dn) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) Oid(org.apache.directory.api.asn1.util.Oid) BinaryAttributeDetector(org.apache.directory.api.ldap.codec.api.BinaryAttributeDetector) AddRequest(org.apache.directory.api.ldap.model.message.AddRequest) 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) CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) ModificationOperation(org.apache.directory.api.ldap.model.entry.ModificationOperation) ExtendedRequest(org.apache.directory.api.ldap.model.message.ExtendedRequest) SearchScope(org.apache.directory.api.ldap.model.message.SearchScope) Value(org.apache.directory.api.ldap.model.entry.Value) Rdn(org.apache.directory.api.ldap.model.name.Rdn) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest)

Example 3 with SearchScope

use of org.apache.directory.api.ldap.model.message.SearchScope in project structr by structr.

the class StructrPartition method search.

@Override
public EntryFilteringCursor search(SearchOperationContext searchContext) throws LdapException {
    logger.info("{}", searchContext);
    final LdapPrincipal principal = searchContext.getEffectivePrincipal();
    final Dn dn = searchContext.getDn();
    final ExprNode filter = searchContext.getFilter();
    final SearchScope scope = searchContext.getScope();
    final List<Entry> list = getWrapper(principal).filter(dn, filter, scope);
    final Cursor<Entry> cursor = new ListCursor<>(list);
    final SchemaManager manager = getSchemaManager();
    return new EntryFilteringCursorImpl(cursor, searchContext, manager);
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) ListCursor(org.apache.directory.api.ldap.model.cursor.ListCursor) EntryFilteringCursorImpl(org.apache.directory.server.core.api.filtering.EntryFilteringCursorImpl) Entry(org.apache.directory.api.ldap.model.entry.Entry) LdapPrincipal(org.apache.directory.server.core.api.LdapPrincipal) SearchScope(org.apache.directory.api.ldap.model.message.SearchScope) Dn(org.apache.directory.api.ldap.model.name.Dn) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager)

Aggregations

SearchScope (org.apache.directory.api.ldap.model.message.SearchScope)3 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)2 Dn (org.apache.directory.api.ldap.model.name.Dn)2 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)2 Oid (org.apache.directory.api.asn1.util.Oid)1 BinaryAttributeDetector (org.apache.directory.api.ldap.codec.api.BinaryAttributeDetector)1 ListCursor (org.apache.directory.api.ldap.model.cursor.ListCursor)1 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)1 Modification (org.apache.directory.api.ldap.model.entry.Modification)1 ModificationOperation (org.apache.directory.api.ldap.model.entry.ModificationOperation)1 Value (org.apache.directory.api.ldap.model.entry.Value)1 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)1 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)1 AbandonRequest (org.apache.directory.api.ldap.model.message.AbandonRequest)1 AddRequest (org.apache.directory.api.ldap.model.message.AddRequest)1 AliasDerefMode (org.apache.directory.api.ldap.model.message.AliasDerefMode)1 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)1 CompareRequest (org.apache.directory.api.ldap.model.message.CompareRequest)1 DeleteRequest (org.apache.directory.api.ldap.model.message.DeleteRequest)1