Search in sources :

Example 1 with SearchResultReferenceProtocolOp

use of com.unboundid.ldap.protocol.SearchResultReferenceProtocolOp in project ldapsdk by pingidentity.

the class InMemoryRequestHandler method processSearchRequest.

/**
 * Attempts to process the provided search request.  The attempt will fail
 * if any of the following conditions is true:
 * <UL>
 *   <LI>There is a problem with any of the request controls.</LI>
 *   <LI>The modify DN request contains a malformed target DN, new RDN, or
 *       new superior DN.</LI>
 *   <LI>The new DN of the entry would conflict with the DN of an existing
 *       entry.</LI>
 *   <LI>The new DN of the entry would exist outside the set of defined
 *       base DNs.</LI>
 *   <LI>The new DN of the entry is not a defined base DN and does not exist
 *       immediately below an existing entry.</LI>
 * </UL>
 *
 * @param  messageID  The message ID of the LDAP message containing the search
 *                    request.
 * @param  request    The search request that was included in the LDAP message
 *                    that was received.
 * @param  controls   The set of controls included in the LDAP message.  It
 *                    may be empty if there were no controls, but will not be
 *                    {@code null}.
 *
 * @return  The {@link LDAPMessage} containing the response to send to the
 *          client.  The protocol op in the {@code LDAPMessage} must be an
 *          {@code SearchResultDoneProtocolOp}.
 */
@Override()
@NotNull()
public LDAPMessage processSearchRequest(final int messageID, @NotNull final SearchRequestProtocolOp request, @NotNull final List<Control> controls) {
    synchronized (entryMap) {
        final List<SearchResultEntry> entryList = new ArrayList<>(entryMap.size());
        final List<SearchResultReference> referenceList = new ArrayList<>(entryMap.size());
        final LDAPMessage returnMessage = processSearchRequest(messageID, request, controls, entryList, referenceList);
        for (final SearchResultEntry e : entryList) {
            try {
                connection.sendSearchResultEntry(messageID, e, e.getControls());
            } catch (final LDAPException le) {
                Debug.debugException(le);
                return new LDAPMessage(messageID, new SearchResultDoneProtocolOp(le.getResultCode().intValue(), le.getMatchedDN(), le.getDiagnosticMessage(), StaticUtils.toList(le.getReferralURLs())), le.getResponseControls());
            }
        }
        for (final SearchResultReference r : referenceList) {
            try {
                connection.sendSearchResultReference(messageID, new SearchResultReferenceProtocolOp(StaticUtils.toList(r.getReferralURLs())), r.getControls());
            } catch (final LDAPException le) {
                Debug.debugException(le);
                return new LDAPMessage(messageID, new SearchResultDoneProtocolOp(le.getResultCode().intValue(), le.getMatchedDN(), le.getDiagnosticMessage(), StaticUtils.toList(le.getReferralURLs())), le.getResponseControls());
            }
        }
        return returnMessage;
    }
}
Also used : SearchResultReferenceProtocolOp(com.unboundid.ldap.protocol.SearchResultReferenceProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) ArrayList(java.util.ArrayList) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) SearchResultReference(com.unboundid.ldap.sdk.SearchResultReference) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry) NotNull(com.unboundid.util.NotNull)

Example 2 with SearchResultReferenceProtocolOp

use of com.unboundid.ldap.protocol.SearchResultReferenceProtocolOp 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)

Example 3 with SearchResultReferenceProtocolOp

use of com.unboundid.ldap.protocol.SearchResultReferenceProtocolOp in project ldapsdk by pingidentity.

the class ProxySearchResultListener method searchReferenceReturned.

/**
 * {@inheritDoc}
 */
@Override()
public void searchReferenceReturned(@NotNull final SearchResultReference searchReference) {
    try {
        final SearchResultReferenceProtocolOp searchResultReferenceProtocolOp = new SearchResultReferenceProtocolOp(Arrays.asList(searchReference.getReferralURLs()));
        clientConnection.sendSearchResultReference(messageID, searchResultReferenceProtocolOp, searchReference.getControls());
    } catch (final Exception e) {
        Debug.debugException(e);
    }
}
Also used : SearchResultReferenceProtocolOp(com.unboundid.ldap.protocol.SearchResultReferenceProtocolOp)

Example 4 with SearchResultReferenceProtocolOp

use of com.unboundid.ldap.protocol.SearchResultReferenceProtocolOp in project ldapsdk by pingidentity.

the class InterceptedSearchReferenceTestCase method testBasics.

/**
 * Provides basic test coverage for an intercepted search reference.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBasics() throws Exception {
    // Create an intercepted search reference.  We'll use a null connection,
    // which shouldn't happen naturally but will be sufficient for this test.
    final SearchRequestProtocolOp requestOp = new SearchRequestProtocolOp(new SearchRequest("dc=example,dc=com", SearchScope.BASE, "(objectClass=*)"));
    String[] referralURLs = { "ldap://ds1.example.com/" };
    final InterceptedSearchReference r = new InterceptedSearchReference(new InterceptedSearchOperation(null, 1, requestOp), new SearchResultReferenceProtocolOp(new SearchResultReference(1, referralURLs, null)));
    assertNotNull(r.toString());
    // Test methods for a generic intercepted operation.
    assertNull(r.getClientConnection());
    assertEquals(r.getConnectionID(), -1L);
    assertNull(r.getConnectedAddress());
    assertEquals(r.getConnectedPort(), -1);
    assertEquals(r.getMessageID(), 1);
    assertNull(r.getProperty("propX"));
    r.setProperty("propX", "valX");
    assertNotNull(r.getProperty("propX"));
    assertEquals(r.getProperty("propX"), "valX");
    assertNotNull(r.toString());
    r.setProperty("propX", null);
    assertNull(r.getProperty("propX"));
    // Test methods specific to an intercepted compare operation.
    assertNotNull(r.getRequest());
    assertNotNull(r.getSearchReference());
    assertEquals(r.getSearchReference().getReferralURLs().length, 1);
    assertNotNull(r.toString());
    referralURLs = new String[] { "ldap://ds1.example.com/", "ldap://ds2.example.com/" };
    r.setSearchReference(new SearchResultReference(1, referralURLs, null));
    assertNotNull(r.getSearchReference());
    assertEquals(r.getSearchReference().getReferralURLs().length, 2);
    assertNotNull(r.toString());
    r.setSearchReference(null);
    assertNull(r.getSearchReference());
    assertNotNull(r.toString());
}
Also used : SearchResultReferenceProtocolOp(com.unboundid.ldap.protocol.SearchResultReferenceProtocolOp) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) SearchRequestProtocolOp(com.unboundid.ldap.protocol.SearchRequestProtocolOp) SearchResultReference(com.unboundid.ldap.sdk.SearchResultReference) Test(org.testng.annotations.Test)

Example 5 with SearchResultReferenceProtocolOp

use of com.unboundid.ldap.protocol.SearchResultReferenceProtocolOp in project ldapsdk by pingidentity.

the class LDAPDebuggerTestCase method testSuccessfulSearch.

/**
 * Provides test coverage for a successful search operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSuccessfulSearch() throws Exception {
    TestRequestHandler.setReturnOp(new SearchResultDoneProtocolOp(0, null, null, null));
    TestRequestHandler.setReturnEntries(new SearchResultEntryProtocolOp("dc=example,dc=com", Arrays.asList(new Attribute("objectClass", "top", "domain"), new Attribute("dc", "example"))));
    TestRequestHandler.setReturnReferences(new SearchResultReferenceProtocolOp(Arrays.asList("ldap://server1.example.com/dc=example,dc=com", "ldap://server2.example.com/dc=example,dc=com")));
    try {
        final SearchRequest r = new SearchRequest("dc=example,dc=com", SearchScope.BASE, "(objectClass=*)");
        r.addControl(new Control("1.2.3.4"));
        conn.search(r);
    } finally {
        TestRequestHandler.setReturnEntries();
        TestRequestHandler.setReturnReferences();
    }
}
Also used : SearchResultReferenceProtocolOp(com.unboundid.ldap.protocol.SearchResultReferenceProtocolOp) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) Attribute(com.unboundid.ldap.sdk.Attribute) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) SearchResultEntryProtocolOp(com.unboundid.ldap.protocol.SearchResultEntryProtocolOp) Test(org.testng.annotations.Test)

Aggregations

SearchResultReferenceProtocolOp (com.unboundid.ldap.protocol.SearchResultReferenceProtocolOp)6 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)2 SearchResultDoneProtocolOp (com.unboundid.ldap.protocol.SearchResultDoneProtocolOp)2 Control (com.unboundid.ldap.sdk.Control)2 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)2 SearchResultReference (com.unboundid.ldap.sdk.SearchResultReference)2 Test (org.testng.annotations.Test)2 SearchRequestProtocolOp (com.unboundid.ldap.protocol.SearchRequestProtocolOp)1 SearchResultEntryProtocolOp (com.unboundid.ldap.protocol.SearchResultEntryProtocolOp)1 Attribute (com.unboundid.ldap.sdk.Attribute)1 LDAPRuntimeException (com.unboundid.ldap.sdk.LDAPRuntimeException)1 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)1 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)1 NotNull (com.unboundid.util.NotNull)1 Nullable (com.unboundid.util.Nullable)1 ObjectPair (com.unboundid.util.ObjectPair)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1