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;
}
}
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());
}
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);
}
}
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());
}
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();
}
}
Aggregations