Search in sources :

Example 6 with AddResponseProtocolOp

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

the class LDAPListenerClientConnection method run.

/**
 * Operates in a loop, waiting for a request to arrive from the client and
 * handing it off to the request handler for processing.  This method is for
 * internal use only and must not be invoked by external callers.
 */
@InternalUseOnly()
@Override()
public void run() {
    try {
        while (true) {
            final LDAPMessage requestMessage;
            try {
                requestMessage = LDAPMessage.readFrom(asn1Reader, false);
                if (requestMessage == null) {
                    // so we won't notify the exception handler.
                    try {
                        close();
                    } catch (final IOException ioe) {
                        Debug.debugException(ioe);
                    }
                    return;
                }
            } catch (final LDAPException le) {
                // This indicates that the client sent a malformed request.
                Debug.debugException(le);
                close(le);
                return;
            }
            try {
                final int messageID = requestMessage.getMessageID();
                final List<Control> controls = requestMessage.getControls();
                LDAPMessage responseMessage;
                switch(requestMessage.getProtocolOpType()) {
                    case LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST:
                        requestHandler.processAbandonRequest(messageID, requestMessage.getAbandonRequestProtocolOp(), controls);
                        responseMessage = null;
                        break;
                    case LDAPMessage.PROTOCOL_OP_TYPE_ADD_REQUEST:
                        try {
                            responseMessage = requestHandler.processAddRequest(messageID, requestMessage.getAddRequestProtocolOp(), controls);
                        } catch (final Exception e) {
                            Debug.debugException(e);
                            responseMessage = new LDAPMessage(messageID, new AddResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
                        }
                        break;
                    case LDAPMessage.PROTOCOL_OP_TYPE_BIND_REQUEST:
                        try {
                            responseMessage = requestHandler.processBindRequest(messageID, requestMessage.getBindRequestProtocolOp(), controls);
                        } catch (final Exception e) {
                            Debug.debugException(e);
                            responseMessage = new LDAPMessage(messageID, new BindResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null, null));
                        }
                        break;
                    case LDAPMessage.PROTOCOL_OP_TYPE_COMPARE_REQUEST:
                        try {
                            responseMessage = requestHandler.processCompareRequest(messageID, requestMessage.getCompareRequestProtocolOp(), controls);
                        } catch (final Exception e) {
                            Debug.debugException(e);
                            responseMessage = new LDAPMessage(messageID, new CompareResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
                        }
                        break;
                    case LDAPMessage.PROTOCOL_OP_TYPE_DELETE_REQUEST:
                        try {
                            responseMessage = requestHandler.processDeleteRequest(messageID, requestMessage.getDeleteRequestProtocolOp(), controls);
                        } catch (final Exception e) {
                            Debug.debugException(e);
                            responseMessage = new LDAPMessage(messageID, new DeleteResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
                        }
                        break;
                    case LDAPMessage.PROTOCOL_OP_TYPE_EXTENDED_REQUEST:
                        try {
                            responseMessage = requestHandler.processExtendedRequest(messageID, requestMessage.getExtendedRequestProtocolOp(), controls);
                        } catch (final Exception e) {
                            Debug.debugException(e);
                            responseMessage = new LDAPMessage(messageID, new ExtendedResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null, null, null));
                        }
                        break;
                    case LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_REQUEST:
                        try {
                            responseMessage = requestHandler.processModifyRequest(messageID, requestMessage.getModifyRequestProtocolOp(), controls);
                        } catch (final Exception e) {
                            Debug.debugException(e);
                            responseMessage = new LDAPMessage(messageID, new ModifyResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
                        }
                        break;
                    case LDAPMessage.PROTOCOL_OP_TYPE_MODIFY_DN_REQUEST:
                        try {
                            responseMessage = requestHandler.processModifyDNRequest(messageID, requestMessage.getModifyDNRequestProtocolOp(), controls);
                        } catch (final Exception e) {
                            Debug.debugException(e);
                            responseMessage = new LDAPMessage(messageID, new ModifyDNResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
                        }
                        break;
                    case LDAPMessage.PROTOCOL_OP_TYPE_SEARCH_REQUEST:
                        try {
                            responseMessage = requestHandler.processSearchRequest(messageID, requestMessage.getSearchRequestProtocolOp(), controls);
                        } catch (final Exception e) {
                            Debug.debugException(e);
                            responseMessage = new LDAPMessage(messageID, new SearchResultDoneProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_CONN_REQUEST_HANDLER_FAILURE.get(StaticUtils.getExceptionMessage(e)), null));
                        }
                        break;
                    case LDAPMessage.PROTOCOL_OP_TYPE_UNBIND_REQUEST:
                        requestHandler.processUnbindRequest(messageID, requestMessage.getUnbindRequestProtocolOp(), controls);
                        close();
                        return;
                    default:
                        close(new LDAPException(ResultCode.PROTOCOL_ERROR, ERR_CONN_INVALID_PROTOCOL_OP_TYPE.get(StaticUtils.toHex(requestMessage.getProtocolOpType()))));
                        return;
                }
                if (responseMessage != null) {
                    try {
                        sendMessage(responseMessage);
                    } catch (final LDAPException le) {
                        Debug.debugException(le);
                        close(le);
                        return;
                    }
                }
            } catch (final Throwable t) {
                close(new LDAPException(ResultCode.LOCAL_ERROR, ERR_CONN_EXCEPTION_IN_REQUEST_HANDLER.get(String.valueOf(requestMessage), StaticUtils.getExceptionMessage(t))));
                StaticUtils.throwErrorOrRuntimeException(t);
            }
        }
    } finally {
        if (listener != null) {
            listener.connectionClosed(this);
        }
    }
}
Also used : ExtendedResponseProtocolOp(com.unboundid.ldap.protocol.ExtendedResponseProtocolOp) DeleteResponseProtocolOp(com.unboundid.ldap.protocol.DeleteResponseProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp) ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) IOException(java.io.IOException) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) LDAPException(com.unboundid.ldap.sdk.LDAPException) IOException(java.io.IOException) Control(com.unboundid.ldap.sdk.Control) BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) ModifyResponseProtocolOp(com.unboundid.ldap.protocol.ModifyResponseProtocolOp) InternalUseOnly(com.unboundid.util.InternalUseOnly)

Example 7 with AddResponseProtocolOp

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

the class InMemoryOperationInterceptorRequestHandler method processAddRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processAddRequest(final int messageID, @NotNull final AddRequestProtocolOp request, @NotNull final List<Control> controls) {
    final InterceptedAddOperation op = new InterceptedAddOperation(connection, messageID, request, toArray(controls));
    activeOperations.put(messageID, op);
    try {
        for (final InMemoryOperationInterceptor i : interceptors) {
            try {
                i.processAddRequest(op);
            } catch (final LDAPException le) {
                Debug.debugException(le);
                return new LDAPMessage(messageID, new AddResponseProtocolOp(le.toLDAPResult()), le.getResponseControls());
            } catch (final Exception e) {
                Debug.debugException(e);
                return new LDAPMessage(messageID, new AddResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_REQUEST_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null));
            }
        }
        final LDAPMessage resultMessage = wrappedHandler.processAddRequest(messageID, new AddRequestProtocolOp((AddRequest) op.getRequest()), op.getRequest().getControlList());
        op.setResult(resultMessage.getAddResponseProtocolOp().toLDAPResult(toArray(resultMessage.getControls())));
        for (final InMemoryOperationInterceptor i : interceptors) {
            try {
                i.processAddResult(op);
            } catch (final Exception e) {
                Debug.debugException(e);
                return new LDAPMessage(messageID, new AddResponseProtocolOp(ResultCode.OTHER_INT_VALUE, null, ERR_DS_INTERCEPTOR_RESULT_ERROR.get(String.valueOf(op), i.getClass().getName(), StaticUtils.getExceptionMessage(e)), null));
            }
        }
        return new LDAPMessage(messageID, new AddResponseProtocolOp(op.getResult()), op.getResult().getResponseControls());
    } finally {
        activeOperations.remove(messageID);
    }
}
Also used : AddRequest(com.unboundid.ldap.sdk.AddRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) AddRequestProtocolOp(com.unboundid.ldap.protocol.AddRequestProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) NotNull(com.unboundid.util.NotNull)

Example 8 with AddResponseProtocolOp

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

the class AccessLogRequestHandler method processAddRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processAddRequest(final int messageID, @NotNull final AddRequestProtocolOp request, @NotNull final List<Control> controls) {
    final long opID = nextOperationID.getAndIncrement();
    final StringBuilder b = getRequestHeader("ADD", opID, messageID);
    b.append(" dn=\"");
    b.append(request.getDN());
    b.append('"');
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final long startTimeNanos = System.nanoTime();
    final LDAPMessage responseMessage = requestHandler.processAddRequest(messageID, request, controls);
    final long eTimeNanos = System.nanoTime() - startTimeNanos;
    final AddResponseProtocolOp protocolOp = responseMessage.getAddResponseProtocolOp();
    generateResponse(b, "ADD", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    return responseMessage;
}
Also used : LogRecord(java.util.logging.LogRecord) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 9 with AddResponseProtocolOp

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

the class LDAPDebuggerTestCase method testFailedAdd.

/**
 * Provides test coverage for a failed add operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testFailedAdd() throws Exception {
    TestRequestHandler.setReturnOp(new AddResponseProtocolOp(32, "dc=example,dc=com", "msg", Arrays.asList("ldap://server1.example.com/dc=example,dc=com", "ldap://server2.example.com/dc=example,dc=com")));
    conn.add("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
}
Also used : AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp) Test(org.testng.annotations.Test)

Example 10 with AddResponseProtocolOp

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

the class LDAPDebuggerTestCase method testSuccessfulAdd.

/**
 * Provides test coverage for a successful add operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSuccessfulAdd() throws Exception {
    TestRequestHandler.setReturnOp(new AddResponseProtocolOp(0, null, null, null));
    final AddRequest r = new AddRequest("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
    r.addControl(new Control("1.2.3.4"));
    conn.add(r);
}
Also used : AddRequest(com.unboundid.ldap.sdk.AddRequest) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp) Test(org.testng.annotations.Test)

Aggregations

AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)14 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)11 LDAPException (com.unboundid.ldap.sdk.LDAPException)8 NotNull (com.unboundid.util.NotNull)8 Control (com.unboundid.ldap.sdk.Control)7 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 AddRequestProtocolOp (com.unboundid.ldap.protocol.AddRequestProtocolOp)4 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)4 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)4 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)4 ArrayList (java.util.ArrayList)4 ModifyDNResponseProtocolOp (com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp)3 ModifyResponseProtocolOp (com.unboundid.ldap.protocol.ModifyResponseProtocolOp)3 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)3 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)3 DontUseCopyRequestControl (com.unboundid.ldap.sdk.controls.DontUseCopyRequestControl)3 DraftLDUPSubentriesRequestControl (com.unboundid.ldap.sdk.controls.DraftLDUPSubentriesRequestControl)3 PermissiveModifyRequestControl (com.unboundid.ldap.sdk.controls.PermissiveModifyRequestControl)3 PostReadRequestControl (com.unboundid.ldap.sdk.controls.PostReadRequestControl)3 PostReadResponseControl (com.unboundid.ldap.sdk.controls.PostReadResponseControl)3