Search in sources :

Example 46 with IntermediateResponse

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);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) EnumSet(java.util.EnumSet) Set(java.util.Set) LDAPException(com.unboundid.ldap.sdk.LDAPException) Control(com.unboundid.ldap.sdk.Control) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) LDAPException(com.unboundid.ldap.sdk.LDAPException) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult)

Example 47 with IntermediateResponse

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());
}
Also used : AddRequest(com.unboundid.ldap.sdk.AddRequest) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) AddRequestProtocolOp(com.unboundid.ldap.protocol.AddRequestProtocolOp) IntermediateResponseProtocolOp(com.unboundid.ldap.protocol.IntermediateResponseProtocolOp) Test(org.testng.annotations.Test)

Example 48 with IntermediateResponse

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);
}
Also used : IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) Test(org.testng.annotations.Test)

Example 49 with IntermediateResponse

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);
}
Also used : IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) Test(org.testng.annotations.Test)

Example 50 with IntermediateResponse

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());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) Test(org.testng.annotations.Test)

Aggregations

IntermediateResponse (com.unboundid.ldap.sdk.IntermediateResponse)56 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)39 Test (org.testng.annotations.Test)37 EnumSet (java.util.EnumSet)19 Set (java.util.Set)19 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)18 LDAPException (com.unboundid.ldap.sdk.LDAPException)18 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)12 Control (com.unboundid.ldap.sdk.Control)11 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)6 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)5 ASN1Element (com.unboundid.asn1.ASN1Element)2 AddRequest (com.unboundid.ldap.sdk.AddRequest)2 BindResult (com.unboundid.ldap.sdk.BindResult)2 Entry (com.unboundid.ldap.sdk.Entry)2 SearchResultReference (com.unboundid.ldap.sdk.SearchResultReference)2 AddRequestProtocolOp (com.unboundid.ldap.protocol.AddRequestProtocolOp)1 IntermediateResponseProtocolOp (com.unboundid.ldap.protocol.IntermediateResponseProtocolOp)1 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)1 DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)1