Search in sources :

Example 26 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class LDAPListenerClientConnection method sendIntermediateResponse.

/**
 * Sends an intermediate response message to the client with the provided
 * information.
 *
 * @param  messageID   The message ID for the LDAP message to send to the
 *                     client.  It must match the message ID of the associated
 *                     search request.
 * @param  protocolOp  The intermediate response protocol op to include in the
 *                     LDAP message to send to the client.
 * @param  controls    The set of controls to include in the response message.
 *                     It may be empty or {@code null} if no controls should
 *                     be included.
 *
 * @throws  LDAPException  If a problem occurs while attempting to send the
 *                         provided response message.  If an exception is
 *                         thrown, then the client connection will have been
 *                         terminated.
 */
public void sendIntermediateResponse(final int messageID, @NotNull final IntermediateResponseProtocolOp protocolOp, @Nullable final Control... controls) throws LDAPException {
    if (intermediateResponseTransformers.isEmpty()) {
        sendMessage(new LDAPMessage(messageID, protocolOp, controls));
    } else {
        Control[] c;
        IntermediateResponseProtocolOp op = protocolOp;
        if (controls == null) {
            c = EMPTY_CONTROL_ARRAY;
        } else {
            c = controls;
        }
        for (final IntermediateResponseTransformer t : intermediateResponseTransformers) {
            try {
                final ObjectPair<IntermediateResponseProtocolOp, Control[]> p = t.transformIntermediateResponse(messageID, op, c);
                if (p == null) {
                    return;
                }
                op = p.getFirst();
                c = p.getSecond();
            } catch (final Exception e) {
                Debug.debugException(e);
                sendMessage(new LDAPMessage(messageID, protocolOp, c));
                throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_CONN_INTERMEDIATE_RESPONSE_TRANSFORMER_EXCEPTION.get(t.getClass().getName(), String.valueOf(op), StaticUtils.getExceptionMessage(e)), e);
            }
        }
        sendMessage(new LDAPMessage(messageID, op, c));
    }
}
Also used : Control(com.unboundid.ldap.sdk.Control) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) IntermediateResponseProtocolOp(com.unboundid.ldap.protocol.IntermediateResponseProtocolOp) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) LDAPException(com.unboundid.ldap.sdk.LDAPException) IOException(java.io.IOException)

Example 27 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class ProxyRequestHandler method processExtendedRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processExtendedRequest(final int messageID, @NotNull final ExtendedRequestProtocolOp request, @NotNull final List<Control> controls) {
    final ExtendedRequest extendedRequest;
    if (controls.isEmpty()) {
        extendedRequest = new ExtendedRequest(request.getOID(), request.getValue());
    } else {
        final Control[] controlArray = new Control[controls.size()];
        controls.toArray(controlArray);
        extendedRequest = new ExtendedRequest(request.getOID(), request.getValue(), controlArray);
    }
    extendedRequest.setIntermediateResponseListener(this);
    try {
        final ExtendedResult extendedResult = ldapConnection.processExtendedOperation(extendedRequest);
        final ExtendedResponseProtocolOp extendedResponseProtocolOp = new ExtendedResponseProtocolOp(extendedResult.getResultCode().intValue(), extendedResult.getMatchedDN(), extendedResult.getDiagnosticMessage(), Arrays.asList(extendedResult.getReferralURLs()), extendedResult.getOID(), extendedResult.getValue());
        return new LDAPMessage(messageID, extendedResponseProtocolOp, Arrays.asList(extendedResult.getResponseControls()));
    } catch (final LDAPException le) {
        Debug.debugException(le);
        final ExtendedResponseProtocolOp extendedResponseProtocolOp = new ExtendedResponseProtocolOp(le.getResultCode().intValue(), le.getMatchedDN(), le.getMessage(), Arrays.asList(le.getReferralURLs()), null, null);
        return new LDAPMessage(messageID, extendedResponseProtocolOp, Arrays.asList(le.getResponseControls()));
    }
}
Also used : Control(com.unboundid.ldap.sdk.Control) ExtendedResponseProtocolOp(com.unboundid.ldap.protocol.ExtendedResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) NotNull(com.unboundid.util.NotNull)

Example 28 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class ProxyRequestHandler method processSearchRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processSearchRequest(final int messageID, @NotNull final SearchRequestProtocolOp request, @NotNull final List<Control> controls) {
    final String[] attrs;
    final List<String> attrList = request.getAttributes();
    if (attrList.isEmpty()) {
        attrs = StaticUtils.NO_STRINGS;
    } else {
        attrs = new String[attrList.size()];
        attrList.toArray(attrs);
    }
    final ProxySearchResultListener searchListener = new ProxySearchResultListener(listenerConnection, messageID);
    final SearchRequest searchRequest = new SearchRequest(searchListener, request.getBaseDN(), request.getScope(), request.getDerefPolicy(), request.getSizeLimit(), request.getTimeLimit(), request.typesOnly(), request.getFilter(), attrs);
    if (!controls.isEmpty()) {
        searchRequest.setControls(controls);
    }
    searchRequest.setIntermediateResponseListener(this);
    LDAPResult searchResult;
    try {
        searchResult = ldapConnection.search(searchRequest);
    } catch (final LDAPException le) {
        Debug.debugException(le);
        searchResult = le.toLDAPResult();
    }
    final SearchResultDoneProtocolOp searchResultDoneProtocolOp = new SearchResultDoneProtocolOp(searchResult.getResultCode().intValue(), searchResult.getMatchedDN(), searchResult.getDiagnosticMessage(), Arrays.asList(searchResult.getReferralURLs()));
    return new LDAPMessage(messageID, searchResultDoneProtocolOp, Arrays.asList(searchResult.getResponseControls()));
}
Also used : SearchRequest(com.unboundid.ldap.sdk.SearchRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) NotNull(com.unboundid.util.NotNull)

Example 29 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class ProxyRequestHandler method processModifyRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processModifyRequest(final int messageID, @NotNull final ModifyRequestProtocolOp request, @NotNull final List<Control> controls) {
    final ModifyRequest modifyRequest = new ModifyRequest(request.getDN(), request.getModifications());
    if (!controls.isEmpty()) {
        modifyRequest.setControls(controls);
    }
    modifyRequest.setIntermediateResponseListener(this);
    LDAPResult modifyResult;
    try {
        modifyResult = ldapConnection.modify(modifyRequest);
    } catch (final LDAPException le) {
        Debug.debugException(le);
        modifyResult = le.toLDAPResult();
    }
    final ModifyResponseProtocolOp modifyResponseProtocolOp = new ModifyResponseProtocolOp(modifyResult.getResultCode().intValue(), modifyResult.getMatchedDN(), modifyResult.getDiagnosticMessage(), Arrays.asList(modifyResult.getReferralURLs()));
    return new LDAPMessage(messageID, modifyResponseProtocolOp, Arrays.asList(modifyResult.getResponseControls()));
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ModifyResponseProtocolOp(com.unboundid.ldap.protocol.ModifyResponseProtocolOp) ModifyRequest(com.unboundid.ldap.sdk.ModifyRequest) NotNull(com.unboundid.util.NotNull)

Example 30 with LDAPMessage

use of com.unboundid.ldap.protocol.LDAPMessage in project ldapsdk by pingidentity.

the class ProxyRequestHandler method processModifyDNRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processModifyDNRequest(final int messageID, @NotNull final ModifyDNRequestProtocolOp request, @NotNull final List<Control> controls) {
    final ModifyDNRequest modifyDNRequest = new ModifyDNRequest(request.getDN(), request.getNewRDN(), request.deleteOldRDN(), request.getNewSuperiorDN());
    if (!controls.isEmpty()) {
        modifyDNRequest.setControls(controls);
    }
    modifyDNRequest.setIntermediateResponseListener(this);
    LDAPResult modifyDNResult;
    try {
        modifyDNResult = ldapConnection.modifyDN(modifyDNRequest);
    } catch (final LDAPException le) {
        Debug.debugException(le);
        modifyDNResult = le.toLDAPResult();
    }
    final ModifyDNResponseProtocolOp modifyDNResponseProtocolOp = new ModifyDNResponseProtocolOp(modifyDNResult.getResultCode().intValue(), modifyDNResult.getMatchedDN(), modifyDNResult.getDiagnosticMessage(), Arrays.asList(modifyDNResult.getReferralURLs()));
    return new LDAPMessage(messageID, modifyDNResponseProtocolOp, Arrays.asList(modifyDNResult.getResponseControls()));
}
Also used : ModifyDNRequest(com.unboundid.ldap.sdk.ModifyDNRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Aggregations

LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)92 NotNull (com.unboundid.util.NotNull)72 LDAPException (com.unboundid.ldap.sdk.LDAPException)42 Control (com.unboundid.ldap.sdk.Control)25 LogRecord (java.util.logging.LogRecord)24 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)23 ArrayList (java.util.ArrayList)19 TransactionSpecificationRequestControl (com.unboundid.ldap.sdk.controls.TransactionSpecificationRequestControl)14 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)13 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)13 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)13 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)13 DontUseCopyRequestControl (com.unboundid.ldap.sdk.controls.DontUseCopyRequestControl)13 DraftLDUPSubentriesRequestControl (com.unboundid.ldap.sdk.controls.DraftLDUPSubentriesRequestControl)13 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)13 PermissiveModifyRequestControl (com.unboundid.ldap.sdk.controls.PermissiveModifyRequestControl)13 PostReadRequestControl (com.unboundid.ldap.sdk.controls.PostReadRequestControl)13 PostReadResponseControl (com.unboundid.ldap.sdk.controls.PostReadResponseControl)13 PreReadRequestControl (com.unboundid.ldap.sdk.controls.PreReadRequestControl)13 PreReadResponseControl (com.unboundid.ldap.sdk.controls.PreReadResponseControl)13