Search in sources :

Example 11 with ExtendedResponseProtocolOp

use of com.unboundid.ldap.protocol.ExtendedResponseProtocolOp 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)

Example 12 with ExtendedResponseProtocolOp

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

the class LDAPDebuggerRequestHandler method processExtendedRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processExtendedRequest(final int messageID, @NotNull final ExtendedRequestProtocolOp request, @NotNull final List<Control> controls) {
    final StringBuilder b = getBuffer();
    appendHeader(b, messageID);
    b.append("     Extended Request Protocol Op:").append(StaticUtils.EOL);
    b.append("          Request OID:  ").append(request.getOID()).append(StaticUtils.EOL);
    final ASN1OctetString requestValue = request.getValue();
    if (requestValue != null) {
        b.append("          Encoded Request Value:");
        b.append(StaticUtils.EOL);
        StaticUtils.toHexPlusASCII(requestValue.getValue(), 15, b);
    }
    appendControls(b, controls);
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final LDAPMessage responseMessage = requestHandler.processExtendedRequest(messageID, request, controls);
    b.setLength(0);
    appendHeader(b, responseMessage.getMessageID());
    b.append("     Extended Response Protocol Op:").append(StaticUtils.EOL);
    final ExtendedResponseProtocolOp protocolOp = responseMessage.getExtendedResponseProtocolOp();
    appendResponse(b, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs());
    final String responseOID = protocolOp.getResponseOID();
    if (responseOID != null) {
        b.append("          Response OID:  ").append(responseOID).append(StaticUtils.EOL);
    }
    final ASN1OctetString responseValue = protocolOp.getResponseValue();
    if (responseValue != null) {
        b.append("          Encoded Response Value:");
        b.append(StaticUtils.EOL);
        StaticUtils.toHexPlusASCII(responseValue.getValue(), 15, b);
    }
    appendControls(b, responseMessage.getControls());
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    return responseMessage;
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ExtendedResponseProtocolOp(com.unboundid.ldap.protocol.ExtendedResponseProtocolOp) LogRecord(java.util.logging.LogRecord) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) NotNull(com.unboundid.util.NotNull)

Example 13 with ExtendedResponseProtocolOp

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

the class StartTLSRequestHandler method processExtendedRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processExtendedRequest(final int messageID, @NotNull final ExtendedRequestProtocolOp request, @NotNull final List<Control> controls) {
    if (request.getOID().equals(StartTLSExtendedRequest.STARTTLS_REQUEST_OID)) {
        try {
            // Make sure we can decode the request as a valid StartTLS request.
            final StartTLSExtendedRequest startTLSRequest = new StartTLSExtendedRequest(new ExtendedRequest(request.getOID(), request.getValue()));
            final OutputStream clearOutputStream = connection.convertToTLS(sslSocketFactory, requestClientCertificate, requireClientCertificate);
            final LDAPMessage responseMessage = new LDAPMessage(messageID, new ExtendedResponseProtocolOp(ResultCode.SUCCESS_INT_VALUE, null, null, null, null, null));
            final ASN1Buffer buffer = new ASN1Buffer();
            responseMessage.writeTo(buffer);
            try {
                buffer.writeTo(clearOutputStream);
                clearOutputStream.flush();
            } catch (final Exception e) {
                Debug.debugException(e);
                final LDAPException le = new LDAPException(ResultCode.LOCAL_ERROR, ERR_START_TLS_REQUEST_HANDLER_WRITE_RESPONSE_FAILURE.get(StaticUtils.getExceptionMessage(e)), e);
                connection.close(le);
                throw le;
            }
            return responseMessage;
        } catch (final LDAPException le) {
            Debug.debugException(le);
            return new LDAPMessage(messageID, new ExtendedResponseProtocolOp(le.getResultCode().intValue(), le.getMatchedDN(), le.getDiagnosticMessage(), StaticUtils.toList(le.getReferralURLs()), null, null), le.getResponseControls());
        }
    } else {
        return requestHandler.processExtendedRequest(messageID, request, controls);
    }
}
Also used : ExtendedResponseProtocolOp(com.unboundid.ldap.protocol.ExtendedResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) StartTLSExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest) OutputStream(java.io.OutputStream) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) StartTLSExtendedRequest(com.unboundid.ldap.sdk.extensions.StartTLSExtendedRequest) LDAPException(com.unboundid.ldap.sdk.LDAPException) NotNull(com.unboundid.util.NotNull)

Example 14 with ExtendedResponseProtocolOp

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

the class MultiUpdateExtendedResult method encodeValue.

/**
 * Encodes the information from the provided set of results into a form
 * suitable for use as the value of a multi-update extended result.
 *
 * @param  changesApplied  The value which indicates whether any or all of the
 *                         changes from the request were successfully applied.
 * @param  results         The set of operation results to be included in the
 *                         extended result value.  It may be {@code null} or
 *                         empty if no operation results should be included.
 *
 * @return  An ASN.1 element suitable for use as the value of a multi-update
 *          extended result.
 *
 * @throws  LDAPException  If any of the results are for an inappropriate
 *                         operation type.
 */
@Nullable()
private static ASN1OctetString encodeValue(@Nullable final MultiUpdateChangesApplied changesApplied, @Nullable final List<ObjectPair<OperationType, LDAPResult>> results) throws LDAPException {
    if ((results == null) || results.isEmpty()) {
        return null;
    }
    final ArrayList<ASN1Element> opElements = new ArrayList<>(results.size());
    for (final ObjectPair<OperationType, LDAPResult> p : results) {
        final OperationType t = p.getFirst();
        final LDAPResult r = p.getSecond();
        final ASN1Element protocolOpElement;
        switch(t) {
            case ADD:
                protocolOpElement = new AddResponseProtocolOp(r).encodeProtocolOp();
                break;
            case DELETE:
                protocolOpElement = new DeleteResponseProtocolOp(r).encodeProtocolOp();
                break;
            case EXTENDED:
                protocolOpElement = new ExtendedResponseProtocolOp(r).encodeProtocolOp();
                break;
            case MODIFY:
                protocolOpElement = new ModifyResponseProtocolOp(r).encodeProtocolOp();
                break;
            case MODIFY_DN:
                protocolOpElement = new ModifyDNResponseProtocolOp(r).encodeProtocolOp();
                break;
            default:
                throw new LDAPException(ResultCode.PARAM_ERROR, ERR_MULTI_UPDATE_RESULT_INVALID_OP_TYPE.get(t.name()));
        }
        final Control[] controls = r.getResponseControls();
        if ((controls == null) || (controls.length == 0)) {
            opElements.add(new ASN1Sequence(protocolOpElement));
        } else {
            opElements.add(new ASN1Sequence(protocolOpElement, Control.encodeControls(controls)));
        }
    }
    final ASN1Sequence valueSequence = new ASN1Sequence(new ASN1Enumerated(changesApplied.intValue()), new ASN1Sequence(opElements));
    return new ASN1OctetString(valueSequence.encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ExtendedResponseProtocolOp(com.unboundid.ldap.protocol.ExtendedResponseProtocolOp) DeleteResponseProtocolOp(com.unboundid.ldap.protocol.DeleteResponseProtocolOp) ArrayList(java.util.ArrayList) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp) ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) Control(com.unboundid.ldap.sdk.Control) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) LDAPException(com.unboundid.ldap.sdk.LDAPException) ASN1Enumerated(com.unboundid.asn1.ASN1Enumerated) ASN1Element(com.unboundid.asn1.ASN1Element) ModifyResponseProtocolOp(com.unboundid.ldap.protocol.ModifyResponseProtocolOp) OperationType(com.unboundid.ldap.sdk.OperationType) Nullable(com.unboundid.util.Nullable)

Aggregations

ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)14 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)11 Control (com.unboundid.ldap.sdk.Control)8 NotNull (com.unboundid.util.NotNull)8 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)7 LDAPException (com.unboundid.ldap.sdk.LDAPException)7 ExtendedRequestProtocolOp (com.unboundid.ldap.protocol.ExtendedRequestProtocolOp)4 ExtendedRequest (com.unboundid.ldap.sdk.ExtendedRequest)4 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)4 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)3 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)3 ModifyDNResponseProtocolOp (com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp)3 ModifyResponseProtocolOp (com.unboundid.ldap.protocol.ModifyResponseProtocolOp)3 LogRecord (java.util.logging.LogRecord)3 Test (org.testng.annotations.Test)3 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)2 CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)2 SearchResultDoneProtocolOp (com.unboundid.ldap.protocol.SearchResultDoneProtocolOp)2 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)2 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)2