Search in sources :

Example 1 with CompareResponseProtocolOp

use of com.unboundid.ldap.protocol.CompareResponseProtocolOp 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 2 with CompareResponseProtocolOp

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

the class LDAPDebuggerTestCase method testFailedCompare.

/**
 * Provides test coverage for a failed compare operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testFailedCompare() throws Exception {
    TestRequestHandler.setReturnOp(new CompareResponseProtocolOp(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.compare("dc=example,dc=com", "foo", "bar");
}
Also used : CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) Test(org.testng.annotations.Test)

Example 3 with CompareResponseProtocolOp

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

the class AccessLogRequestHandler method processCompareRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processCompareRequest(final int messageID, @NotNull final CompareRequestProtocolOp request, @NotNull final List<Control> controls) {
    final long opID = nextOperationID.getAndIncrement();
    final StringBuilder b = getRequestHeader("COMPARE", opID, messageID);
    b.append(" dn=\"");
    b.append(request.getDN());
    b.append("\" attr=\"");
    b.append(request.getAttributeName());
    b.append('"');
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final long startTimeNanos = System.nanoTime();
    final LDAPMessage responseMessage = requestHandler.processCompareRequest(messageID, request, controls);
    final long eTimeNanos = System.nanoTime() - startTimeNanos;
    final CompareResponseProtocolOp protocolOp = responseMessage.getCompareResponseProtocolOp();
    generateResponse(b, "COMPARE", 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) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) NotNull(com.unboundid.util.NotNull)

Example 4 with CompareResponseProtocolOp

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

the class LDAPDebuggerTestCase method testSuccessfulCompare.

/**
 * Provides test coverage for a successful compare operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSuccessfulCompare() throws Exception {
    TestRequestHandler.setReturnOp(new CompareResponseProtocolOp(6, null, null, null));
    final CompareRequest r = new CompareRequest("dc=example,dc=com", "foo", "bar");
    r.addControl(new Control("1.2.3.4"));
    conn.compare(r);
}
Also used : CompareRequest(com.unboundid.ldap.sdk.CompareRequest) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) Test(org.testng.annotations.Test)

Example 5 with CompareResponseProtocolOp

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

the class CannedResponseRequestHandlerTestCase method testDefaultConstructor.

/**
 * Tests the behavior of the request handler with the default configuration.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDefaultConstructor() throws Exception {
    final CannedResponseRequestHandler handler = new CannedResponseRequestHandler().newInstance(null);
    LDAPMessage m = handler.processAddRequest(1, new AddRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Attribute("objectClass", "top", "domain"), new Attribute("dc", "example"))), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 1);
    assertTrue(m.getProtocolOp() instanceof AddResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processBindRequest(2, new BindRequestProtocolOp("uid=admin,dc=example,dc=com", "password"), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 2);
    assertTrue(m.getProtocolOp() instanceof BindResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processCompareRequest(3, new CompareRequestProtocolOp("dc=example,dc=com", "objectClass", new ASN1OctetString("top")), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 3);
    assertTrue(m.getProtocolOp() instanceof CompareResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processDeleteRequest(4, new DeleteRequestProtocolOp("dc=example,dc=com"), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 4);
    assertTrue(m.getProtocolOp() instanceof DeleteResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processExtendedRequest(5, new ExtendedRequestProtocolOp("1.2.3.4", null), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 5);
    assertTrue(m.getProtocolOp() instanceof ExtendedResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processModifyRequest(6, new ModifyRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Modification(ModificationType.REPLACE, "description", "foo"))), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 6);
    assertTrue(m.getProtocolOp() instanceof ModifyResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processModifyDNRequest(6, new ModifyDNRequestProtocolOp("ou=People,dc=example,dc=com", "ou=Users", true, null), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 6);
    assertTrue(m.getProtocolOp() instanceof ModifyDNResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processSearchRequest(7, new SearchRequestProtocolOp("dc=example,dc=com", SearchScope.SUB, DereferencePolicy.NEVER, 0, 0, false, Filter.createEqualityFilter("uid", "test"), Arrays.<String>asList()), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 7);
    assertTrue(m.getProtocolOp() instanceof SearchResultDoneProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Modification(com.unboundid.ldap.sdk.Modification) ExtendedResponseProtocolOp(com.unboundid.ldap.protocol.ExtendedResponseProtocolOp) Attribute(com.unboundid.ldap.sdk.Attribute) SearchRequestProtocolOp(com.unboundid.ldap.protocol.SearchRequestProtocolOp) AddRequestProtocolOp(com.unboundid.ldap.protocol.AddRequestProtocolOp) CompareRequestProtocolOp(com.unboundid.ldap.protocol.CompareRequestProtocolOp) DeleteResponseProtocolOp(com.unboundid.ldap.protocol.DeleteResponseProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp) BindRequestProtocolOp(com.unboundid.ldap.protocol.BindRequestProtocolOp) ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) ExtendedRequestProtocolOp(com.unboundid.ldap.protocol.ExtendedRequestProtocolOp) DeleteRequestProtocolOp(com.unboundid.ldap.protocol.DeleteRequestProtocolOp) ModifyRequestProtocolOp(com.unboundid.ldap.protocol.ModifyRequestProtocolOp) Control(com.unboundid.ldap.sdk.Control) BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) ModifyDNRequestProtocolOp(com.unboundid.ldap.protocol.ModifyDNRequestProtocolOp) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) ModifyResponseProtocolOp(com.unboundid.ldap.protocol.ModifyResponseProtocolOp) Test(org.testng.annotations.Test)

Aggregations

CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)11 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)9 NotNull (com.unboundid.util.NotNull)7 Control (com.unboundid.ldap.sdk.Control)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 CompareRequestProtocolOp (com.unboundid.ldap.protocol.CompareRequestProtocolOp)3 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)3 LogRecord (java.util.logging.LogRecord)3 Test (org.testng.annotations.Test)3 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)2 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)2 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)2 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)2 ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)2 ModifyDNResponseProtocolOp (com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp)2 ModifyResponseProtocolOp (com.unboundid.ldap.protocol.ModifyResponseProtocolOp)2 SearchResultDoneProtocolOp (com.unboundid.ldap.protocol.SearchResultDoneProtocolOp)2 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)2 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)2 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)2