Search in sources :

Example 6 with IntermediateResponse

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

the class ControlBasedOperationInterceptor method processDeleteRequest.

/**
 * {@inheritDoc}
 */
@Override()
public void processDeleteRequest(final InMemoryInterceptedDeleteRequest 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();
    final DeleteRequest deleteRequest = 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)) {
        deleteRequest.setDN("ou=altered,dc=example,dc=com");
    }
    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(deleteRequest);
}
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) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) DeleteRequest(com.unboundid.ldap.sdk.DeleteRequest)

Example 7 with IntermediateResponse

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

the class ControlBasedOperationInterceptor method processModifyDNRequest.

/**
 * {@inheritDoc}
 */
@Override()
public void processModifyDNRequest(final InMemoryInterceptedModifyDNRequest 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();
    final ModifyDNRequest modifyDNRequest = 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)) {
        modifyDNRequest.setDN("ou=altered,dc=example,dc=com");
    }
    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(modifyDNRequest);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) EnumSet(java.util.EnumSet) Set(java.util.Set) LDAPException(com.unboundid.ldap.sdk.LDAPException) ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) Control(com.unboundid.ldap.sdk.Control) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) LDAPException(com.unboundid.ldap.sdk.LDAPException) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult)

Example 8 with IntermediateResponse

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

the class ControlBasedOperationInterceptor method processSearchRequest.

/**
 * {@inheritDoc}
 */
@Override()
public void processSearchRequest(final InMemoryInterceptedSearchRequest 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();
    final SearchRequest searchRequest = 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)) {
        searchRequest.setBaseDN("ou=altered,dc=example,dc=com");
    }
    if (transformTypes.contains(TransformType.INJECT_ENTRY)) {
        try {
            request.sendSearchEntry(new Entry("dn: ou=Request,ou=injected,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: Request"));
        } catch (final Exception e) {
        }
    }
    if (transformTypes.contains(TransformType.INJECT_REFERENCE)) {
        try {
            final String[] referralURLs = { "ldap://" + request.getConnectedAddress() + ':' + request.getConnectedPort() + "/ou=Request,ou=injected,dc=example,dc=com" };
            request.sendSearchReference(new SearchResultReference(referralURLs, null));
        } catch (final Exception e) {
        }
    }
    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(searchRequest);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) SearchRequest(com.unboundid.ldap.sdk.SearchRequest) EnumSet(java.util.EnumSet) Set(java.util.Set) SearchResultReference(com.unboundid.ldap.sdk.SearchResultReference) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) LDAPException(com.unboundid.ldap.sdk.LDAPException) Control(com.unboundid.ldap.sdk.Control) Entry(com.unboundid.ldap.sdk.Entry) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) LDAPException(com.unboundid.ldap.sdk.LDAPException) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult)

Example 9 with IntermediateResponse

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

the class ControlBasedOperationInterceptor method processCompareRequest.

/**
 * {@inheritDoc}
 */
@Override()
public void processCompareRequest(final InMemoryInterceptedCompareRequest 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();
    final CompareRequest compareRequest = 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)) {
        compareRequest.setDN("ou=altered,dc=example,dc=com");
    }
    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(compareRequest);
}
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) CompareRequest(com.unboundid.ldap.sdk.CompareRequest) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) LDAPException(com.unboundid.ldap.sdk.LDAPException) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult)

Example 10 with IntermediateResponse

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

the class ControlBasedOperationInterceptor method processModifyRequest.

/**
 * {@inheritDoc}
 */
@Override()
public void processModifyRequest(final InMemoryInterceptedModifyRequest 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();
    final ModifyRequest modifyRequest = 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)) {
        modifyRequest.setDN("ou=altered,dc=example,dc=com");
    }
    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(modifyRequest);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) EnumSet(java.util.EnumSet) Set(java.util.Set) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) Control(com.unboundid.ldap.sdk.Control) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) LDAPException(com.unboundid.ldap.sdk.LDAPException) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult)

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