Search in sources :

Example 21 with Asn1Decoder

use of org.apache.directory.api.asn1.ber.Asn1Decoder in project directory-ldap-api by apache.

the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringFilterFinalInitial.

/**
 * Test the decoding of a SearchRequest with a Substring filter Final before
 * initial
 */
@Test
public void testDecodeSearchRequestSubstringFilterFinalInitial() {
    byte[] asn1BER = new byte[] { 0x30, 0x49, 0x02, 0x01, // messageID
    0x04, 0x63, 0x44, 0x04, // baseObject LDAPDN,
    0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x01, 0x01, (byte) 0xFF, (byte) 0xA4, 0x0E, 0x04, 0x04, 't', 'e', 's', 't', 0x30, 0x06, (byte) 0x82, 0x01, 'a', (byte) 0x80, 0x01, 'b', 0x30, // AttributeDescriptionList
    0x02, // AttributeDescription
    0x04, 0x00 };
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(asn1BER.length);
    stream.put(asn1BER);
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    // Decode a SearchRequest message
    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) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 22 with Asn1Decoder

use of org.apache.directory.api.asn1.ber.Asn1Decoder in project directory-ldap-api by apache.

the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringFilterTwoFinals.

/**
 * Test the decoding of a SearchRequest with a Substring filter Two finals
 */
@Test
public void testDecodeSearchRequestSubstringFilterTwoFinals() {
    byte[] asn1BER = new byte[] { 0x30, 0x49, 0x02, 0x01, // messageID
    0x04, 0x63, 0x44, 0x04, // baseObject LDAPDN,
    0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x01, 0x01, (byte) 0xFF, (byte) 0xA4, 0x0E, 0x04, 0x04, 't', 'e', 's', 't', 0x30, 0x06, (byte) 0x82, 0x01, 'a', (byte) 0x82, 0x01, 'b', 0x30, // AttributeDescriptionList
    0x02, // AttributeDescription
    0x04, 0x00 };
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(asn1BER.length);
    stream.put(asn1BER);
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    // Decode a SearchRequest message
    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) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 23 with Asn1Decoder

use of org.apache.directory.api.asn1.ber.Asn1Decoder in project directory-ldap-api by apache.

the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringFinal.

/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=*t*t*t*)
 */
@Test
public void testDecodeSearchRequestSubstringFinal() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x67);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x65, 0x02, 0x01, // messageID MessageID
    0x01, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
    0x60, // SearchRequest ::= APPLICATION[3] SEQUENCE {
    0x04, // baseObject LDAPDN,
    0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, // scope
    0x01, // wholeSubtree (2) },
    0x0A, 0x01, // derefAliases ENUMERATED {
    0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, 0x01, 0x01, // typesOnly
    (byte) 0xFF, // filter Filter,
    (byte) 0xA4, // Filter ::= CHOICE {
    0x15, // SubstringFilter ::= SEQUENCE {
    0x04, // type AttributeDescription,
    0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x30, 0x06, (byte) 0x82, 0x04, 'A', 'm', 'o', // 
    's', 0x30, // AttributeDescriptionList ::= SEQUENCE OF
    0x15, // AttributeDescription
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '0', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '1', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::=
    '2' // LDAPString
    });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(1, searchRequest.getMessageId());
    assertEquals("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(1000, searchRequest.getSizeLimit());
    assertEquals(1000, searchRequest.getTimeLimit());
    assertEquals(true, searchRequest.getTypesOnly());
    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = (SubstringNode) node;
    assertNotNull(substringNode);
    assertEquals("objectclass", substringNode.getAttribute());
    assertEquals(null, substringNode.getInitial());
    assertEquals(0, substringNode.getAny().size());
    assertEquals("Amos", substringNode.getFinal());
    // The attributes
    List<String> attributes = searchRequest.getAttributes();
    for (String attribute : attributes) {
        assertNotNull(attribute);
    }
    // attributes may have been reordered
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x67, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu.substring(0, 0x5B), decodedPdu.substring(0, 0x5B));
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 24 with Asn1Decoder

use of org.apache.directory.api.asn1.ber.Asn1Decoder in project directory-ldap-api by apache.

the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringFilterNoSubstrings.

/**
 * Test the decoding of a SearchRequest with a Substring filter and an empty
 * Substring
 */
@Test
public void testDecodeSearchRequestSubstringFilterNoSubstrings() {
    byte[] asn1BER = new byte[] { 0x30, 0x41, 0x02, 0x01, // messageID
    0x04, 0x63, 0x3D, 0x04, // baseObject LDAPDN,
    0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x01, 0x0A, 0x01, 0x03, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x01, 0x01, (byte) 0xFF, (byte) 0xA4, 0x06, 0x04, 0x04, 't', 'e', 's', 't', 0x30, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
    0x02, 0x04, 0x00 };
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(asn1BER.length);
    stream.put(asn1BER);
    stream.flip();
    // Allocate a LdapMessage Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    // Decode a SearchRequest message
    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) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 25 with Asn1Decoder

use of org.apache.directory.api.asn1.ber.Asn1Decoder in project directory-ldap-api by apache.

the class SearchRequestSubstringTest method testDecodeSearchRequestSubstringInitialAnyAny.

/**
 * Test the decoding of a SearchRequest with a substring filter. Test the
 * initial filter : (objectclass=t*)
 */
@Test
public void testDecodeSearchRequestSubstringInitialAnyAny() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x67);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x65, 0x02, 0x01, // messageID MessageID
    0x01, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
    0x60, // SearchRequest ::= APPLICATION[3] SEQUENCE {
    0x04, // baseObject LDAPDN,
    0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, // scope
    0x01, // wholeSubtree (2) },
    0x0A, 0x01, // derefAliases ENUMERATED {
    0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000)
    0x02, 0x02, 0x03, (byte) 0xE8, 0x01, 0x01, // typesOnly
    (byte) 0xFF, // filter Filter,
    (byte) 0xA4, // Filter ::= CHOICE {
    0x15, // SubstringFilter ::= SEQUENCE {
    0x04, // type AttributeDescription,
    0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x30, 0x06, (byte) 0x80, 0x01, // 
    't', (byte) 0x81, 0x01, // 
    '*', 0x30, // AttributeDescriptionList ::= SEQUENCE OF
    0x15, // AttributeDescription
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '0', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription
    '1', // ::= LDAPString
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::=
    '2' // LDAPString
    });
    String decodedPdu = Strings.dumpBytes(stream.array());
    stream.flip();
    // Allocate a BindRequest Container
    LdapMessageContainer<SearchRequestDecorator> ldapMessageContainer = new LdapMessageContainer<SearchRequestDecorator>(codec);
    try {
        ldapDecoder.decode(stream, ldapMessageContainer);
    } catch (DecoderException de) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(1, searchRequest.getMessageId());
    assertEquals("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(1000, searchRequest.getSizeLimit());
    assertEquals(1000, searchRequest.getTimeLimit());
    assertEquals(true, searchRequest.getTypesOnly());
    // (objectclass=t*)
    ExprNode node = searchRequest.getFilter();
    SubstringNode substringNode = (SubstringNode) node;
    assertNotNull(substringNode);
    assertEquals("objectclass", substringNode.getAttribute());
    assertEquals("t", substringNode.getInitial());
    assertEquals("*", substringNode.getAny().get(0));
    // The attributes
    List<String> attributes = searchRequest.getAttributes();
    for (String attribute : attributes) {
        assertNotNull(attribute);
    }
    // attributes may have been reordered
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x67, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu.substring(0, 0x58), decodedPdu.substring(0, 0x58));
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) DecoderException(org.apache.directory.api.asn1.DecoderException) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) EncoderException(org.apache.directory.api.asn1.EncoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ByteBuffer(java.nio.ByteBuffer) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)335 ByteBuffer (java.nio.ByteBuffer)334 Test (org.junit.Test)332 DecoderException (org.apache.directory.api.asn1.DecoderException)331 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)268 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)268 EncoderException (org.apache.directory.api.asn1.EncoderException)145 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)85 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)43 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)37 Control (org.apache.directory.api.ldap.model.message.Control)37 Asn1Container (org.apache.directory.api.asn1.ber.Asn1Container)36 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)34 BindRequestDecorator (org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator)21 Message (org.apache.directory.api.ldap.model.message.Message)20 ModifyRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator)19 AndNode (org.apache.directory.api.ldap.model.filter.AndNode)19 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)18 EqualityNode (org.apache.directory.api.ldap.model.filter.EqualityNode)18 SearchResultEntryDecorator (org.apache.directory.api.ldap.codec.decorators.SearchResultEntryDecorator)16