use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class ControlBasedOperationInterceptor method processSimpleBindRequest.
/**
* {@inheritDoc}
*/
@Override()
public void processSimpleBindRequest(final InMemoryInterceptedSimpleBindRequest request) throws LDAPException {
final ObjectPair<Set<TransformType>, Control[]> transformationData = getTransformTypes(request.getRequest());
// If there are no transformation types to apply, then return without doing
// anything.
final Set<TransformType> transformTypes = transformationData.getFirst();
if (transformTypes.isEmpty()) {
return;
}
// Store the set of transformation types in the operation state for any
// necessary result processing.
request.setProperty(STATE_KEY_TRANSFORM_TYPES, transformTypes);
// Update the request to remove the transformation controls.
final Control[] remainingControls = transformationData.getSecond();
SimpleBindRequest bindRequest = request.getRequest().duplicate(remainingControls);
// Apply any necessary transformations to the request.
if (transformTypes.contains(TransformType.REJECT_REQUEST)) {
throw new LDAPException(ResultCode.UNWILLING_TO_PERFORM, "Rejected by transformation control");
}
if (transformTypes.contains(TransformType.REQUEST_RUNTIME_EXCEPTION)) {
throw new RuntimeException();
}
if (transformTypes.contains(TransformType.ALTER_DN)) {
final long responseTimeout = bindRequest.getResponseTimeoutMillis(null);
bindRequest = new SimpleBindRequest("ou=altered,dc=example,dc=com", bindRequest.getPassword().getValue(), bindRequest.getControls());
bindRequest.setResponseTimeoutMillis(responseTimeout);
}
if (transformTypes.contains(TransformType.INJECT_INTERMEDIATE_RESPONSE)) {
try {
request.sendIntermediateResponse(new IntermediateResponse(INTERMEDIATE_RESPONSE_OID, new ASN1OctetString("Injected in Request")));
} catch (final Exception e) {
}
}
if (transformTypes.contains(TransformType.INJECT_UNSOLICITED_NOTIFICATION)) {
try {
request.sendUnsolicitedNotification(new ExtendedResult(0, ResultCode.SUCCESS, "Injected by Request", null, null, UNSOLICITED_NOTIFICATION_OID, null, null));
} catch (final Exception e) {
}
}
// Update the add request to be processed.
request.setRequest(bindRequest);
}
use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class InterceptedIntermediateResponseTestCase method testBasics.
/**
* Provides basic test coverage for an intercepted intermediate response.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testBasics() throws Exception {
// Create an intercepted intermediate response. We'll use a null
// connection, which shouldn't happen naturally but will be sufficient for
// this test.
final AddRequestProtocolOp requestOp = new AddRequestProtocolOp(new AddRequest("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example"));
final InterceptedAddOperation o = new InterceptedAddOperation(null, 1, requestOp);
assertNotNull(o.toString());
final IntermediateResponseProtocolOp responseOp = new IntermediateResponseProtocolOp(new IntermediateResponse("1.2.3.4", null));
final InterceptedIntermediateResponse r = new InterceptedIntermediateResponse(o, responseOp);
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.getIntermediateResponse());
assertEquals(r.getIntermediateResponse().getOID(), "1.2.3.4");
assertNotNull(r.toString());
r.setIntermediateResponse(new IntermediateResponse("5.6.7.8", null));
assertEquals(r.getIntermediateResponse().getOID(), "5.6.7.8");
assertNotNull(r.toString());
r.setIntermediateResponse(null);
assertNull(r.getIntermediateResponse());
assertNotNull(r.toString());
}
use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class DebugTestCase method testDebugLDAPResult7DisabledAll.
/**
* Tests the seventh {@code debugLDAPResult} method with the debugger disabled
* and a debug type set of all types.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDebugLDAPResult7DisabledAll() throws Exception {
Debug.setEnabled(false);
testLogHandler.resetMessageCount();
assertFalse(Debug.debugEnabled(DebugType.LDAP));
Debug.debugLDAPResult(new IntermediateResponse("1.2.3.4", null));
assertTrue(testLogHandler.getMessageCount() >= 0);
}
use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class GetChangelogBatchIntermediateResponseListenerTestCase method testHandleOtherIntermediateResponseWithoutOIDOrValue.
/**
* Provides test coverage for the {@code intermediateResponseReturned} method
* with an intermediate response message without an OID or value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testHandleOtherIntermediateResponseWithoutOIDOrValue() throws Exception {
final GetChangelogBatchExtendedRequest r = new GetChangelogBatchExtendedRequest(new EndOfChangelogStartingPoint(), 100, 300000L);
final TestChangelogEntryListener entryListener = new TestChangelogEntryListener();
assertEquals(entryListener.getEntryCount(), 0);
assertEquals(entryListener.getMissingChangesCount(), 0);
assertEquals(entryListener.getOtherCount(), 0);
final GetChangelogBatchIntermediateResponseListener l = new GetChangelogBatchIntermediateResponseListener(entryListener);
assertEquals(l.getEntryCount(), 0);
l.intermediateResponseReturned(new IntermediateResponse(null, null));
assertEquals(l.getEntryCount(), 0);
assertEquals(entryListener.getEntryCount(), 0);
assertEquals(entryListener.getMissingChangesCount(), 0);
assertEquals(entryListener.getOtherCount(), 1);
}
use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class MissingChangelogEntriesIntermediateResponseTestCase method testDecodeValueEmptySequence.
/**
* Provides test coverage for an attempt to decode a generic intermediate
* response with a value that is an empty sequence.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testDecodeValueEmptySequence() throws Exception {
final ASN1Sequence valueSequence = new ASN1Sequence();
final IntermediateResponse genericIR = new IntermediateResponse(MissingChangelogEntriesIntermediateResponse.MISSING_CHANGELOG_ENTRIES_INTERMEDIATE_RESPONSE_OID, new ASN1OctetString(valueSequence.encode()));
final MissingChangelogEntriesIntermediateResponse mceIR = new MissingChangelogEntriesIntermediateResponse(genericIR);
assertNotNull(mceIR);
assertNull(mceIR.getMessage());
assertNotNull(mceIR.getIntermediateResponseName());
assertNull(mceIR.valueToString());
assertNotNull(mceIR.toString());
}
Aggregations