Search in sources :

Example 1 with CompareResponseImpl

use of org.apache.directory.api.ldap.model.message.CompareResponseImpl in project directory-ldap-api by apache.

the class CompareRequestTest method testDecodeCompareRequestEmptyAttributeDesc.

/**
 * Test the decoding of an empty attributeDesc ava
 */
@Test
public void testDecodeCompareRequestEmptyAttributeDesc() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x2D);
    stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
    0x2B, 0x02, 0x01, // messageID MessageID
    0x01, // CHOICE { ..., compareRequest CompareRequest, ...
    0x6E, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
    0x26, // entry LDAPDN,
    0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', // ava AttributeValueAssertion }
    0x30, // AttributeValueAssertion ::= SEQUENCE {
    0x02, 0x04, 0x00 });
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<CompareRequestDecorator> container = new LdapMessageContainer<CompareRequestDecorator>(codec);
    // Decode the CompareRequest PDU
    try {
        ldapDecoder.decode(stream, container);
        fail("We should never reach this point !!!");
    } catch (DecoderException de) {
        assertTrue(de instanceof ResponseCarryingException);
        Message response = ((ResponseCarryingException) de).getResponse();
        assertTrue(response instanceof CompareResponseImpl);
        assertEquals(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ((CompareResponseImpl) response).getLdapResult().getResultCode());
        return;
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) CompareResponseImpl(org.apache.directory.api.ldap.model.message.CompareResponseImpl) Message(org.apache.directory.api.ldap.model.message.Message) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) CompareRequestDecorator(org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 2 with CompareResponseImpl

use of org.apache.directory.api.ldap.model.message.CompareResponseImpl in project directory-ldap-api by apache.

the class InitCompareResponse method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<CompareResponseDecorator> container) throws DecoderException {
    // Now, we can allocate the CompareResponse Object
    CompareResponseDecorator compareResponse = new CompareResponseDecorator(container.getLdapCodecService(), new CompareResponseImpl(container.getMessageId()));
    container.setMessage(compareResponse);
    // We will check that the request is not null
    TLV tlv = container.getCurrentTLV();
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04094);
        LOG.error(msg);
        throw new DecoderException(msg);
    }
    LOG.debug("Compare response ");
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) CompareResponseImpl(org.apache.directory.api.ldap.model.message.CompareResponseImpl) CompareResponseDecorator(org.apache.directory.api.ldap.codec.decorators.CompareResponseDecorator) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 3 with CompareResponseImpl

use of org.apache.directory.api.ldap.model.message.CompareResponseImpl in project directory-ldap-api by apache.

the class StoreCompareRequestAttributeDesc method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<CompareRequestDecorator> container) throws DecoderException {
    // Get the CompareRequest Object
    CompareRequest compareRequest = container.getMessage();
    // Get the Value and store it in the CompareRequest
    TLV tlv = container.getCurrentTLV();
    // Dn
    if (tlv.getLength() == 0) {
        String msg = I18n.err(I18n.ERR_04093);
        LOG.error(msg);
        CompareResponseImpl response = new CompareResponseImpl(compareRequest.getMessageId());
        throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, compareRequest.getName(), null);
    }
    String type = Strings.utf8ToString(tlv.getValue().getData());
    compareRequest.setAttributeId(type);
    if (IS_DEBUG) {
        LOG.debug("Comparing attribute description {}", compareRequest.getAttributeId());
    }
}
Also used : CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) CompareResponseImpl(org.apache.directory.api.ldap.model.message.CompareResponseImpl) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 4 with CompareResponseImpl

use of org.apache.directory.api.ldap.model.message.CompareResponseImpl in project directory-ldap-api by apache.

the class StoreCompareRequestEntryName method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<CompareRequestDecorator> container) throws DecoderException {
    CompareRequest compareRequest = container.getMessage();
    // Get the Value and store it in the CompareRequest
    TLV tlv = container.getCurrentTLV();
    Dn entry;
    // Dn
    if (tlv.getLength() == 0) {
        // This will generate a PROTOCOL_ERROR
        throw new DecoderException(I18n.err(I18n.ERR_04089));
    } else {
        byte[] dnBytes = tlv.getValue().getData();
        String dnStr = Strings.utf8ToString(dnBytes);
        try {
            entry = new Dn(dnStr);
        } catch (LdapInvalidDnException ine) {
            String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
            LOG.error("{} : {}", msg, ine.getMessage());
            CompareResponseImpl response = new CompareResponseImpl(compareRequest.getMessageId());
            throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
        }
        compareRequest.setName(entry);
    }
    if (IS_DEBUG) {
        LOG.debug("Comparing Dn {}", entry);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) CompareResponseImpl(org.apache.directory.api.ldap.model.message.CompareResponseImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 5 with CompareResponseImpl

use of org.apache.directory.api.ldap.model.message.CompareResponseImpl in project directory-ldap-api by apache.

the class CompareRequestTest method testDecodeCompareRequestInvalidDN.

/**
 * Test the decoding of an empty ava
 */
@Test
public void testDecodeCompareRequestInvalidDN() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x2B);
    stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
    0x29, 0x02, 0x01, // messageID MessageID
    0x01, // CHOICE { ..., compareRequest CompareRequest, ...
    0x6E, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
    0x24, // entry LDAPDN,
    0x04, 0x20, 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', // ava AttributeValueAssertion }
    0x30, // AttributeValueAssertion ::= SEQUENCE {
    0x00 });
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<CompareRequestDecorator> container = new LdapMessageContainer<CompareRequestDecorator>(codec);
    // Decode the CompareRequest PDU
    try {
        ldapDecoder.decode(stream, container);
        fail("We should never reach this point !!!");
    } catch (DecoderException de) {
        assertTrue(de instanceof ResponseCarryingException);
        Message response = ((ResponseCarryingException) de).getResponse();
        assertTrue(response instanceof CompareResponseImpl);
        assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((CompareResponseImpl) response).getLdapResult().getResultCode());
        return;
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) CompareResponseImpl(org.apache.directory.api.ldap.model.message.CompareResponseImpl) Message(org.apache.directory.api.ldap.model.message.Message) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) CompareRequestDecorator(org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

CompareResponseImpl (org.apache.directory.api.ldap.model.message.CompareResponseImpl)5 DecoderException (org.apache.directory.api.asn1.DecoderException)4 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)4 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)3 ByteBuffer (java.nio.ByteBuffer)2 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)2 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)2 CompareRequestDecorator (org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator)2 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)2 CompareRequest (org.apache.directory.api.ldap.model.message.CompareRequest)2 Message (org.apache.directory.api.ldap.model.message.Message)2 Test (org.junit.Test)2 CompareResponseDecorator (org.apache.directory.api.ldap.codec.decorators.CompareResponseDecorator)1 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)1 Dn (org.apache.directory.api.ldap.model.name.Dn)1