Search in sources :

Example 41 with IntermediateResponse

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

the class ControlBasedOperationInterceptor method processCompareResult.

/**
 * {@inheritDoc}
 */
@Override()
public void processCompareResult(final InMemoryInterceptedCompareResult result) {
    // See if there are any transformations that should be applied.
    final Object transformTypesObj = result.getProperty(STATE_KEY_TRANSFORM_TYPES);
    if (transformTypesObj == null) {
        return;
    }
    @SuppressWarnings("unchecked") final Set<TransformType> transformTypes = (Set<TransformType>) transformTypesObj;
    if (transformTypes.contains(TransformType.INJECT_INTERMEDIATE_RESPONSE)) {
        try {
            result.sendIntermediateResponse(new IntermediateResponse(INTERMEDIATE_RESPONSE_OID, new ASN1OctetString("Injected in Response")));
        } catch (final Exception e) {
        }
    }
    if (transformTypes.contains(TransformType.INJECT_UNSOLICITED_NOTIFICATION)) {
        try {
            result.sendUnsolicitedNotification(new ExtendedResult(0, ResultCode.SUCCESS, "Injected by Result", null, null, UNSOLICITED_NOTIFICATION_OID, null, null));
        } catch (final Exception e) {
        }
    }
    if (transformTypes.contains(TransformType.ERROR_RESULT)) {
        result.setResult(new LDAPResult(result.getMessageID(), ResultCode.UNWILLING_TO_PERFORM, "Error result by transformation", null, StaticUtils.NO_STRINGS, StaticUtils.NO_CONTROLS));
    }
    if (transformTypes.contains(TransformType.RESULT_RUNTIME_EXCEPTION)) {
        throw new RuntimeException();
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) EnumSet(java.util.EnumSet) Set(java.util.Set) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 42 with IntermediateResponse

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

the class ControlBasedOperationInterceptor method processExtendedResult.

/**
 * {@inheritDoc}
 */
@Override()
public void processExtendedResult(final InMemoryInterceptedExtendedResult result) {
    // See if there are any transformations that should be applied.
    final Object transformTypesObj = result.getProperty(STATE_KEY_TRANSFORM_TYPES);
    if (transformTypesObj == null) {
        return;
    }
    @SuppressWarnings("unchecked") final Set<TransformType> transformTypes = (Set<TransformType>) transformTypesObj;
    if (transformTypes.contains(TransformType.INJECT_INTERMEDIATE_RESPONSE)) {
        try {
            result.sendIntermediateResponse(new IntermediateResponse(INTERMEDIATE_RESPONSE_OID, new ASN1OctetString("Injected in Response")));
        } catch (final Exception e) {
        }
    }
    if (transformTypes.contains(TransformType.INJECT_UNSOLICITED_NOTIFICATION)) {
        try {
            result.sendUnsolicitedNotification(new ExtendedResult(0, ResultCode.SUCCESS, "Injected by Result", null, null, UNSOLICITED_NOTIFICATION_OID, null, null));
        } catch (final Exception e) {
        }
    }
    if (transformTypes.contains(TransformType.ERROR_RESULT)) {
        result.setResult(new ExtendedResult(result.getMessageID(), ResultCode.UNWILLING_TO_PERFORM, "Error result by transformation", null, StaticUtils.NO_STRINGS, null, null, StaticUtils.NO_CONTROLS));
    }
    if (transformTypes.contains(TransformType.RESULT_RUNTIME_EXCEPTION)) {
        throw new RuntimeException();
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) EnumSet(java.util.EnumSet) Set(java.util.Set) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 43 with IntermediateResponse

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

the class ControlBasedOperationInterceptor method processModifyDNResult.

/**
 * {@inheritDoc}
 */
@Override()
public void processModifyDNResult(final InMemoryInterceptedModifyDNResult result) {
    // See if there are any transformations that should be applied.
    final Object transformTypesObj = result.getProperty(STATE_KEY_TRANSFORM_TYPES);
    if (transformTypesObj == null) {
        return;
    }
    @SuppressWarnings("unchecked") final Set<TransformType> transformTypes = (Set<TransformType>) transformTypesObj;
    if (transformTypes.contains(TransformType.INJECT_INTERMEDIATE_RESPONSE)) {
        try {
            result.sendIntermediateResponse(new IntermediateResponse(INTERMEDIATE_RESPONSE_OID, new ASN1OctetString("Injected in Response")));
        } catch (final Exception e) {
        }
    }
    if (transformTypes.contains(TransformType.INJECT_UNSOLICITED_NOTIFICATION)) {
        try {
            result.sendUnsolicitedNotification(new ExtendedResult(0, ResultCode.SUCCESS, "Injected by Result", null, null, UNSOLICITED_NOTIFICATION_OID, null, null));
        } catch (final Exception e) {
        }
    }
    if (transformTypes.contains(TransformType.ERROR_RESULT)) {
        result.setResult(new LDAPResult(result.getMessageID(), ResultCode.UNWILLING_TO_PERFORM, "Error result by transformation", null, StaticUtils.NO_STRINGS, StaticUtils.NO_CONTROLS));
    }
    if (transformTypes.contains(TransformType.RESULT_RUNTIME_EXCEPTION)) {
        throw new RuntimeException();
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) EnumSet(java.util.EnumSet) Set(java.util.Set) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 44 with IntermediateResponse

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

the class ControlBasedOperationInterceptor method processSASLBindRequest.

/**
 * {@inheritDoc}
 */
@Override()
public void processSASLBindRequest(final InMemoryInterceptedSASLBindRequest 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();
    GenericSASLBindRequest 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 GenericSASLBindRequest("ou=altered,dc=example,dc=com", bindRequest.getSASLMechanismName(), bindRequest.getCredentials(), 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) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) LDAPException(com.unboundid.ldap.sdk.LDAPException) GenericSASLBindRequest(com.unboundid.ldap.sdk.GenericSASLBindRequest) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult)

Example 45 with IntermediateResponse

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

the class ControlBasedOperationInterceptor method processIntermediateResponse.

/**
 * {@inheritDoc}
 */
@Override()
public void processIntermediateResponse(final InMemoryInterceptedIntermediateResponse response) {
    // See if there are any transformations that should be applied.
    final Object transformTypesObj = response.getProperty(STATE_KEY_TRANSFORM_TYPES);
    if (transformTypesObj == null) {
        return;
    }
    @SuppressWarnings("unchecked") final Set<TransformType> transformTypes = (Set<TransformType>) transformTypesObj;
    if (transformTypes.contains(TransformType.SUPPRESS_INTERMEDIATE_RESPONSE)) {
        response.setIntermediateResponse(null);
        return;
    }
    if (transformTypes.contains(TransformType.INTERMEDIATE_RESPONSE_RUNTIME_EXCEPTION)) {
        throw new RuntimeException();
    }
    if (transformTypes.contains(TransformType.ALTER_INTERMEDIATE_RESPONSE)) {
        response.setIntermediateResponse(new IntermediateResponse(INTERMEDIATE_RESPONSE_OID, new ASN1OctetString("Altered Value"), response.getIntermediateResponse().getControls()));
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) EnumSet(java.util.EnumSet) Set(java.util.Set)

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