Search in sources :

Example 1 with Message

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

the class LdapProtocolDecoder method decode.

/**
 * {@inheritDoc}
 */
@Override
public void decode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    @SuppressWarnings("unchecked") LdapMessageContainer<MessageDecorator<? extends Message>> messageContainer = (LdapMessageContainer<MessageDecorator<? extends Message>>) session.getAttribute(LdapDecoder.MESSAGE_CONTAINER_ATTR);
    if (session.containsAttribute(LdapDecoder.MAX_PDU_SIZE_ATTR)) {
        int maxPDUSize = (Integer) session.getAttribute(LdapDecoder.MAX_PDU_SIZE_ATTR);
        messageContainer.setMaxPDUSize(maxPDUSize);
    }
    List<Message> decodedMessages = new ArrayList<>();
    ByteBuffer buf = in.buf();
    decode(buf, messageContainer, decodedMessages);
    for (Message message : decodedMessages) {
        out.write(message);
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) MessageDecorator(org.apache.directory.api.ldap.codec.api.MessageDecorator) Message(org.apache.directory.api.ldap.model.message.Message) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer)

Example 2 with Message

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

the class LdapResultTest method testDecodeAddResponseEmptyResultCodeEmptyReferrals.

/**
 * Test the decoding of a AddResponse with a valid LdapResult and an invalid
 * transition after the referral sequence
 */
@Test
public void testDecodeAddResponseEmptyResultCodeEmptyReferrals() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x10);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x0E, 0x02, 0x01, // messageID MessageID
    0x01, 0x69, // CHOICE { ..., addResponse AddResponse, ...
    0x09, 0x0A, 0x01, // resultCode success (Referral)
    0x0A, 0x04, // Empty matched Dn
    0x00, 0x04, // Empty errorMessage
    0x00, (byte) 0xA3, 0x00 });
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<MessageDecorator<? extends Message>> container = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
    // Decode the AddResponse PDU
    try {
        ldapDecoder.decode(stream, container);
    } catch (DecoderException de) {
        assertTrue(true);
        return;
    }
    fail("We should not reach this point");
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) MessageDecorator(org.apache.directory.api.ldap.codec.api.MessageDecorator) Message(org.apache.directory.api.ldap.model.message.Message) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 3 with Message

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

the class AbandonRequestTest method testDecodeAbandonRequestNoMessageId.

/**
 * Test the decoding of a AbandonRequest with a null messageId
 */
@Test
public void testDecodeAbandonRequestNoMessageId() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x0A);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x08, 0x02, 0x01, // messageID MessageID
    0x01, 0x50, // CHOICE { ..., abandonRequest AbandonRequest,...
    0x00 // AbandonRequest ::= [APPLICATION 16] MessageID
    });
    stream.flip();
    // Allocate a LdapMessageContainer Container
    LdapMessageContainer<MessageDecorator<? extends Message>> ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
    // Decode the PDU
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        assertTrue(true);
        return;
    }
    fail("We should not reach this point");
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) MessageDecorator(org.apache.directory.api.ldap.codec.api.MessageDecorator) Message(org.apache.directory.api.ldap.model.message.Message) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 4 with Message

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

the class AbandonRequestTest method testDecodeAbandonRequestBadMessageId.

/**
 * Test the decoding of a AbandonRequest with a bad Message Id
 */
@Test
public void testDecodeAbandonRequestBadMessageId() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x0B);
    stream.put(new byte[] { // LDAPMessage ::=SEQUENCE {
    0x30, // LDAPMessage ::=SEQUENCE {
    0x09, 0x02, 0x01, // messageID MessageID
    0x01, 0x50, 0x01, // CHOICE { ..., abandonRequest AbandonRequest,...
    (byte) 0xFF // AbandonRequest ::= [APPLICATION 16] MessageID
    });
    stream.flip();
    // Allocate a LdapMessageContainer Container
    LdapMessageContainer<MessageDecorator<? extends Message>> ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
    // Decode the PDU
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        assertTrue(true);
        return;
    }
    fail("We should not reach this point");
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) MessageDecorator(org.apache.directory.api.ldap.codec.api.MessageDecorator) Message(org.apache.directory.api.ldap.model.message.Message) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 5 with Message

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

the class AddRequestTest method testDecodeAddRequestbadDN.

/**
 * Test the decoding of a AddRequest
 */
@Test
public void testDecodeAddRequestbadDN() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x59);
    stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
    0x57, 0x02, 0x01, // messageID MessageID
    0x01, 0x68, // CHOICE { ..., addRequest AddRequest, ...
    0x52, // 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', // attributes AttributeList }
    0x30, // AttributeList ::= SEQUENCE OF SEQUENCE {
    0x2E, 0x30, // attribute 1
    0x0c, 0x04, 0x01, // type AttributeDescription,
    'l', 0x31, // vals SET OF AttributeValue }
    0x07, 0x04, 0x05, 'P', 'a', 'r', 'i', 's', 0x30, // attribute 2
    0x1E, // type AttributeDescription,
    0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, // vals SET
    0x15, // }
    0x04, 0x05, 't', 'e', 's', 't', '1', 0x04, 0x05, 't', 'e', 's', 't', '2', 0x04, 0x05, 't', 'e', 's', 't', '3' });
    stream.flip();
    // Allocate a LdapMessage Container
    Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
    // Decode a AddRequest message
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        assertTrue(de instanceof ResponseCarryingException);
        Message response = ((ResponseCarryingException) de).getResponse();
        assertTrue(response instanceof AddResponseImpl);
        assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((AddResponseImpl) response).getLdapResult().getResultCode());
        return;
    }
    fail("We should not reach this point");
}
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) Asn1Container(org.apache.directory.api.asn1.ber.Asn1Container) Message(org.apache.directory.api.ldap.model.message.Message) AddResponseImpl(org.apache.directory.api.ldap.model.message.AddResponseImpl) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

Message (org.apache.directory.api.ldap.model.message.Message)30 DecoderException (org.apache.directory.api.asn1.DecoderException)26 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)24 ByteBuffer (java.nio.ByteBuffer)22 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)21 Test (org.junit.Test)21 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)20 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)16 MessageDecorator (org.apache.directory.api.ldap.codec.api.MessageDecorator)11 Asn1Container (org.apache.directory.api.asn1.ber.Asn1Container)3 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)3 ModifyDnRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyDnRequestDecorator)3 AddResponseImpl (org.apache.directory.api.ldap.model.message.AddResponseImpl)3 ModifyDnResponseImpl (org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl)3 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)2 ArrayList (java.util.ArrayList)2 SchemaBinaryAttributeDetector (org.apache.directory.api.ldap.codec.api.SchemaBinaryAttributeDetector)2 CompareRequestDecorator (org.apache.directory.api.ldap.codec.decorators.CompareRequestDecorator)2