Search in sources :

Example 6 with CancelExtendedRequest

use of com.unboundid.ldap.sdk.extensions.CancelExtendedRequest in project ldapsdk by pingidentity.

the class InternalSDKHelper method cancel.

/**
 * Sends an LDAP cancel extended request to the server over the provided
 * connection without waiting for the response.  This is intended for use when
 * it is necessary to send a cancel request over a connection operating in
 * synchronous mode.
 *
 * @param  connection       The connection over which to send the cancel
 *                          request.
 * @param  targetMessageID  The message ID of the request to cancel.
 * @param  controls         The set of controls to include in the request.
 *
 * @throws  LDAPException  If a problem occurs while sending the cancel
 *                         request.
 */
@InternalUseOnly()
public static void cancel(@NotNull final LDAPConnection connection, final int targetMessageID, @Nullable final Control... controls) throws LDAPException {
    final int messageID = connection.nextMessageID();
    final CancelExtendedRequest cancelRequest = new CancelExtendedRequest(targetMessageID);
    Debug.debugLDAPRequest(Level.INFO, cancelRequest, messageID, connection);
    final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
    if (logger != null) {
        logger.logExtendedRequest(connection, messageID, cancelRequest);
    }
    connection.sendMessage(new LDAPMessage(messageID, new ExtendedRequest(cancelRequest), controls), connection.getConnectionOptions().getExtendedOperationResponseTimeoutMillis(CancelExtendedRequest.CANCEL_REQUEST_OID));
}
Also used : CancelExtendedRequest(com.unboundid.ldap.sdk.extensions.CancelExtendedRequest) CancelExtendedRequest(com.unboundid.ldap.sdk.extensions.CancelExtendedRequest) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) InternalUseOnly(com.unboundid.util.InternalUseOnly)

Example 7 with CancelExtendedRequest

use of com.unboundid.ldap.sdk.extensions.CancelExtendedRequest in project ldapsdk by pingidentity.

the class IdentifyUniqueAttributeConflicts method searchEntryReturned.

/**
 * Indicates that the provided search result entry has been returned by the
 * server and may be processed by this search result listener.
 *
 * @param  searchEntry  The search result entry that has been returned by the
 *                      server.
 */
@Override()
public void searchEntryReturned(@NotNull final SearchResultEntry searchEntry) {
    // bother processing any more entries.
    if (timeLimitExceeded.get()) {
        return;
    }
    if (uniqueInCombination) {
        checkForConflictsInCombination(searchEntry);
        return;
    }
    try {
        // first.
        if (!allowConflictsInSameEntry) {
            boolean conflictFound = false;
            for (int i = 0; i < attributes.length; i++) {
                final List<Attribute> l1 = searchEntry.getAttributesWithOptions(attributes[i], null);
                if (l1 != null) {
                    for (int j = i + 1; j < attributes.length; j++) {
                        final List<Attribute> l2 = searchEntry.getAttributesWithOptions(attributes[j], null);
                        if (l2 != null) {
                            for (final Attribute a1 : l1) {
                                for (final String value : a1.getValues()) {
                                    for (final Attribute a2 : l2) {
                                        if (a2.hasValue(value)) {
                                            err("Value '", value, "' in attribute ", a1.getName(), " of entry '", searchEntry.getDN(), " is also present in attribute ", a2.getName(), " of the same entry.");
                                            conflictFound = true;
                                            conflictCounts.get(attributes[i]).incrementAndGet();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (conflictFound) {
                return;
            }
        }
        // efficient in the common case.
        for (final String attrName : attributes) {
            final List<Attribute> attrList = searchEntry.getAttributesWithOptions(attrName, null);
            for (final Attribute a : attrList) {
                for (final String value : a.getValues()) {
                    Filter filter;
                    if (uniqueAcrossAttributes) {
                        final Filter[] orComps = new Filter[attributes.length];
                        for (int i = 0; i < attributes.length; i++) {
                            orComps[i] = Filter.createEqualityFilter(attributes[i], value);
                        }
                        filter = Filter.createORFilter(orComps);
                    } else {
                        filter = Filter.createEqualityFilter(attrName, value);
                    }
                    if (filterArgument.isPresent()) {
                        filter = Filter.createANDFilter(filterArgument.getValue(), filter);
                    }
                    baseDNLoop: for (final String baseDN : baseDNs) {
                        SearchResult searchResult;
                        final SearchRequest searchRequest = new SearchRequest(baseDN, SearchScope.SUB, DereferencePolicy.NEVER, 2, timeLimitArgument.getValue(), false, filter, "1.1");
                        try {
                            searchResult = findConflictsPool.search(searchRequest);
                        } catch (final LDAPSearchException lse) {
                            Debug.debugException(lse);
                            if (lse.getResultCode() == ResultCode.TIME_LIMIT_EXCEEDED) {
                                // The server spent more time than the configured time limit
                                // to process the search.  This almost certainly means that
                                // the search is unindexed, and we don't want to continue.
                                // Indicate that the time limit has been exceeded, cancel the
                                // outer search, and display an error message to the user.
                                timeLimitExceeded.set(true);
                                try {
                                    findConflictsPool.processExtendedOperation(new CancelExtendedRequest(searchEntry.getMessageID()));
                                } catch (final Exception e) {
                                    Debug.debugException(e);
                                }
                                err("A server-side time limit was exceeded when searching " + "below base DN '" + baseDN + "' with filter '" + filter + "', which likely means that the search " + "request is not indexed in the server.  Check the " + "server configuration to ensure that any appropriate " + "indexes are in place.  To indicate that searches " + "should not request any time limit, use the " + timeLimitArgument.getIdentifierString() + " to indicate a time limit of zero seconds.");
                                return;
                            } else if (lse.getResultCode().isConnectionUsable()) {
                                searchResult = lse.getSearchResult();
                            } else {
                                try {
                                    searchResult = findConflictsPool.search(searchRequest);
                                } catch (final LDAPSearchException lse2) {
                                    Debug.debugException(lse2);
                                    searchResult = lse2.getSearchResult();
                                }
                            }
                        }
                        for (final SearchResultEntry e : searchResult.getSearchEntries()) {
                            try {
                                if (DN.equals(searchEntry.getDN(), e.getDN())) {
                                    continue;
                                }
                            } catch (final Exception ex) {
                                Debug.debugException(ex);
                            }
                            err("Value '", value, "' in attribute ", a.getName(), " of entry '" + searchEntry.getDN(), "' is also present in entry '", e.getDN(), "'.");
                            conflictCounts.get(attrName).incrementAndGet();
                            break baseDNLoop;
                        }
                        if (searchResult.getResultCode() != ResultCode.SUCCESS) {
                            err("An error occurred while attempting to search for " + "conflicts with " + a.getName() + " value '" + value + "' (as found in entry '" + searchEntry.getDN() + "') below '" + baseDN + "':  " + searchResult.getDiagnosticMessage());
                            conflictCounts.get(attrName).incrementAndGet();
                            break baseDNLoop;
                        }
                    }
                }
            }
        }
    } finally {
        final long count = entriesExamined.incrementAndGet();
        if ((count % 1000L) == 0L) {
            out(count, " entries examined");
        }
    }
}
Also used : SearchRequest(com.unboundid.ldap.sdk.SearchRequest) Attribute(com.unboundid.ldap.sdk.Attribute) SearchResult(com.unboundid.ldap.sdk.SearchResult) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LDAPSearchException(com.unboundid.ldap.sdk.LDAPSearchException) ArgumentException(com.unboundid.util.args.ArgumentException) LDAPException(com.unboundid.ldap.sdk.LDAPException) Filter(com.unboundid.ldap.sdk.Filter) CancelExtendedRequest(com.unboundid.ldap.sdk.extensions.CancelExtendedRequest) LDAPSearchException(com.unboundid.ldap.sdk.LDAPSearchException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Aggregations

CancelExtendedRequest (com.unboundid.ldap.sdk.extensions.CancelExtendedRequest)7 Test (org.testng.annotations.Test)4 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)3 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)2 Attribute (com.unboundid.ldap.sdk.Attribute)2 Filter (com.unboundid.ldap.sdk.Filter)2 LDAPException (com.unboundid.ldap.sdk.LDAPException)2 LDAPSearchException (com.unboundid.ldap.sdk.LDAPSearchException)2 SearchResult (com.unboundid.ldap.sdk.SearchResult)2 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)2 ArgumentException (com.unboundid.util.args.ArgumentException)2 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)1 AsyncRequestID (com.unboundid.ldap.sdk.AsyncRequestID)1 DN (com.unboundid.ldap.sdk.DN)1 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 WhoAmIExtendedRequest (com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest)1 WhoAmIExtendedResult (com.unboundid.ldap.sdk.extensions.WhoAmIExtendedResult)1 InternalUseOnly (com.unboundid.util.InternalUseOnly)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1