Search in sources :

Example 21 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class InMemoryRequestHandler method indexSearch.

/**
 * Attempts to use indexes to obtain a candidate list for the provided filter.
 *
 * @param  filter  The filter to be processed.
 *
 * @return  The DNs of entries which may match the given filter, or
 *          {@code null} if the filter is not indexed.
 */
@Nullable()
private Set<DN> indexSearch(@NotNull final Filter filter) {
    switch(filter.getFilterType()) {
        case Filter.FILTER_TYPE_AND:
            Filter[] comps = filter.getComponents();
            if (comps.length == 0) {
                return null;
            } else if (comps.length == 1) {
                return indexSearch(comps[0]);
            } else {
                Set<DN> candidateSet = null;
                for (final Filter f : comps) {
                    final Set<DN> dnSet = indexSearch(f);
                    if (dnSet != null) {
                        if (candidateSet == null) {
                            candidateSet = new TreeSet<>(dnSet);
                        } else {
                            candidateSet.retainAll(dnSet);
                        }
                    }
                }
                return candidateSet;
            }
        case Filter.FILTER_TYPE_OR:
            comps = filter.getComponents();
            if (comps.length == 0) {
                return Collections.emptySet();
            } else if (comps.length == 1) {
                return indexSearch(comps[0]);
            } else {
                Set<DN> candidateSet = null;
                for (final Filter f : comps) {
                    final Set<DN> dnSet = indexSearch(f);
                    if (dnSet == null) {
                        return null;
                    }
                    if (candidateSet == null) {
                        candidateSet = new TreeSet<>(dnSet);
                    } else {
                        candidateSet.addAll(dnSet);
                    }
                }
                return candidateSet;
            }
        case Filter.FILTER_TYPE_EQUALITY:
            final Schema schema = schemaRef.get();
            if (schema == null) {
                return null;
            }
            final AttributeTypeDefinition at = schema.getAttributeType(filter.getAttributeName());
            if (at == null) {
                return null;
            }
            final InMemoryDirectoryServerEqualityAttributeIndex i = equalityIndexes.get(at);
            if (i == null) {
                return null;
            }
            try {
                return i.getMatchingEntries(filter.getRawAssertionValue());
            } catch (final Exception e) {
                Debug.debugException(e);
                return null;
            }
        default:
            return null;
    }
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) Set(java.util.Set) TreeSet(java.util.TreeSet) LinkedHashSet(java.util.LinkedHashSet) SortedSet(java.util.SortedSet) Filter(com.unboundid.ldap.sdk.Filter) TreeSet(java.util.TreeSet) Schema(com.unboundid.ldap.sdk.schema.Schema) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDIFException(com.unboundid.ldif.LDIFException) Nullable(com.unboundid.util.Nullable)

Example 22 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class InMemoryRequestHandler method getMissingAttributeNames.

/**
 * Retrieves a list containing all of the named attributes which do not exist
 * in the target entry.
 *
 * @param  dn              The DN of the entry to examine.
 * @param  attributeNames  The names of the attributes expected to be present
 *                         in the target entry.
 *
 * @return  A list containing the names of the attributes which were not
 *          present in the target entry, an empty list if all specified
 *          attributes were found in the entry, or {@code null} if the target
 *          entry does not exist.
 *
 * @throws  LDAPException  If a problem is encountered while trying to
 *                         communicate with the directory server.
 */
@Nullable()
public List<String> getMissingAttributeNames(@NotNull final String dn, @NotNull final Collection<String> attributeNames) throws LDAPException {
    synchronized (entryMap) {
        final Entry e = getEntry(dn);
        if (e == null) {
            return null;
        }
        final Schema schema = schemaRef.get();
        final List<String> missingAttrs = new ArrayList<>(attributeNames.size());
        for (final String attr : attributeNames) {
            final Filter f = Filter.createPresenceFilter(attr);
            if (!f.matchesEntry(e, schema)) {
                missingAttrs.add(attr);
            }
        }
        return missingAttrs;
    }
}
Also used : ChangeLogEntry(com.unboundid.ldap.sdk.ChangeLogEntry) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) Entry(com.unboundid.ldap.sdk.Entry) ReadOnlyEntry(com.unboundid.ldap.sdk.ReadOnlyEntry) Filter(com.unboundid.ldap.sdk.Filter) Schema(com.unboundid.ldap.sdk.schema.Schema) ArrayList(java.util.ArrayList) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Nullable(com.unboundid.util.Nullable)

Example 23 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class InMemoryDirectoryServer method getListenAddress.

/**
 * Retrieves the configured listen address for the specified listener, if
 * defined.
 *
 * @param  listenerName  The name of the listener for which to retrieve the
 *                       listen address.  It may be {@code null} in order to
 *                       obtain the listen address for the first active
 *                       listener.
 *
 * @return  The configured listen address for the specified listener, or
 *          {@code null} if there is no such listener or the listener does not
 *          have an explicitly-configured listen address.
 */
@Nullable()
public synchronized InetAddress getListenAddress(@Nullable final String listenerName) {
    final String name;
    if (listenerName == null) {
        name = getFirstListenerName();
    } else {
        name = StaticUtils.toLowerCase(listenerName);
    }
    final LDAPListenerConfig listenerCfg = ldapListenerConfigs.get(name);
    if (listenerCfg == null) {
        return null;
    } else {
        return listenerCfg.getListenAddress();
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Nullable(com.unboundid.util.Nullable)

Example 24 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class InMemoryOperationInterceptorRequestHandler method transformEntry.

/**
 * {@inheritDoc}
 */
@Override()
@Nullable()
public ObjectPair<SearchResultEntryProtocolOp, Control[]> transformEntry(final int messageID, @NotNull final SearchResultEntryProtocolOp entry, @NotNull final Control[] controls) {
    final InterceptedSearchOperation op = (InterceptedSearchOperation) activeOperations.get(messageID);
    if (op == null) {
        return new ObjectPair<>(entry, controls);
    }
    final InterceptedSearchEntry e = new InterceptedSearchEntry(op, entry, controls);
    for (final InMemoryOperationInterceptor i : interceptors) {
        try {
            i.processSearchEntry(e);
            if (e.getSearchEntry() == null) {
                return null;
            }
        } catch (final Exception ex) {
            Debug.debugException(ex);
            return null;
        }
    }
    return new ObjectPair<>(new SearchResultEntryProtocolOp(e.getSearchEntry()), e.getSearchEntry().getControls());
}
Also used : SearchResultEntryProtocolOp(com.unboundid.ldap.protocol.SearchResultEntryProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) ObjectPair(com.unboundid.util.ObjectPair) Nullable(com.unboundid.util.Nullable)

Example 25 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class InMemoryOperationInterceptorRequestHandler method transformReference.

/**
 * {@inheritDoc}
 */
@Override()
@Nullable()
public ObjectPair<SearchResultReferenceProtocolOp, Control[]> transformReference(final int messageID, @NotNull final SearchResultReferenceProtocolOp reference, @NotNull final Control[] controls) {
    final InterceptedSearchOperation op = (InterceptedSearchOperation) activeOperations.get(messageID);
    if (op == null) {
        return new ObjectPair<>(reference, controls);
    }
    final InterceptedSearchReference r = new InterceptedSearchReference(op, reference, controls);
    for (final InMemoryOperationInterceptor i : interceptors) {
        try {
            i.processSearchReference(r);
            if (r.getSearchReference() == null) {
                return null;
            }
        } catch (final Exception ex) {
            Debug.debugException(ex);
            return null;
        }
    }
    return new ObjectPair<>(new SearchResultReferenceProtocolOp(r.getSearchReference()), r.getSearchReference().getControls());
}
Also used : SearchResultReferenceProtocolOp(com.unboundid.ldap.protocol.SearchResultReferenceProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) ObjectPair(com.unboundid.util.ObjectPair) Nullable(com.unboundid.util.Nullable)

Aggregations

Nullable (com.unboundid.util.Nullable)149 ArrayList (java.util.ArrayList)47 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)42 Entry (com.unboundid.ldap.sdk.Entry)30 LDAPException (com.unboundid.ldap.sdk.LDAPException)30 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)21 Attribute (com.unboundid.ldap.sdk.Attribute)21 ASN1Element (com.unboundid.asn1.ASN1Element)20 Filter (com.unboundid.ldap.sdk.Filter)20 SearchResult (com.unboundid.ldap.sdk.SearchResult)18 IOException (java.io.IOException)16 ReadOnlyEntry (com.unboundid.ldap.sdk.ReadOnlyEntry)14 File (java.io.File)14 DN (com.unboundid.ldap.sdk.DN)12 ArgumentException (com.unboundid.util.args.ArgumentException)10 RDN (com.unboundid.ldap.sdk.RDN)9 LDIFException (com.unboundid.ldif.LDIFException)8 ChangeLogEntry (com.unboundid.ldap.sdk.ChangeLogEntry)7 Modification (com.unboundid.ldap.sdk.Modification)7 LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)7