Search in sources :

Example 41 with DecoderException

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

the class SearchRequestTest method decodeComplexFilter.

@Test
public void decodeComplexFilter() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x77);
    stream.put(new byte[] { 0x30, 0x53, 0x02, 0x01, 0x02, 0x63, 0x4E, 0x04, 0x11, 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 0x0A, 0x01, 0x02, 0x0A, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x01, 0x01, 0x00, (byte) 0xA0, 0x28, (byte) 0xA1, 0x1F, (byte) 0xA0, 0x1D, (byte) 0xA3, 0x1B, 0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x04, 0x0C, 'g', 'r', 'o', 'u', 'p', 'o', 'f', 'n', 'a', 'm', 'e', 's', (byte) 0x87, 0x05, 'o', 'w', 'n', 'e', 'r', 0x30, 0x00 });
    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());
    }
    assertEquals(TLVStateEnum.PDU_DECODED, ldapMessageContainer.getState());
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(2, searchRequest.getMessageId());
    assertEquals("dc=example,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.SUBTREE, searchRequest.getScope());
    assertEquals(AliasDerefMode.NEVER_DEREF_ALIASES, searchRequest.getDerefAliases());
    assertEquals(0, searchRequest.getSizeLimit());
    assertEquals(0, searchRequest.getTimeLimit());
    assertEquals(false, searchRequest.getTypesOnly());
    ExprNode filter = searchRequest.getFilter();
    // (&(...
    AndNode andNode = (AndNode) filter;
    assertNotNull(andNode);
    List<ExprNode> andNodes = andNode.getChildren();
    assertEquals(2, andNodes.size());
    // (&(|(...
    filter = searchRequest.getFilter();
    OrNode orNode = (OrNode) andNodes.get(0);
    assertNotNull(orNode);
    List<ExprNode> orNodes = orNode.getChildren();
    assertEquals(1, orNodes.size());
    // (&(|(&...
    AndNode andNode2 = (AndNode) orNodes.get(0);
    assertNotNull(andNode2);
    List<ExprNode> andNodes2 = andNode2.getChildren();
    assertEquals(1, andNodes2.size());
    // (&(|(&(objectClass=groupOfNames)
    EqualityNode<?> equalityNode = (EqualityNode<?>) andNodes2.get(0);
    assertNotNull(equalityNode);
    assertEquals("objectclass", equalityNode.getAttribute());
    assertEquals("groupofnames", equalityNode.getValue().getValue());
    // (&(|(&(objectClass=groupOfNames)))(owner=*))
    PresenceNode presenceNode = (PresenceNode) andNodes.get(1);
    assertNotNull(presenceNode);
    assertEquals("owner", presenceNode.getAttribute());
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) PresenceNode(org.apache.directory.api.ldap.model.filter.PresenceNode) AndNode(org.apache.directory.api.ldap.model.filter.AndNode) ByteBuffer(java.nio.ByteBuffer) ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) DecoderException(org.apache.directory.api.asn1.DecoderException) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) EqualityNode(org.apache.directory.api.ldap.model.filter.EqualityNode) SearchRequestDecorator(org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator) OrNode(org.apache.directory.api.ldap.model.filter.OrNode) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 42 with DecoderException

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

the class SearchRequestTest method testDecodeSearchRequestEmptyPresentFilter.

/**
 * Test the decoding of a SearchRequest with an empty Present filter
 */
@Test
public void testDecodeSearchRequestEmptyPresentFilter() {
    byte[] asn1BER = new byte[] { 0x30, 0x37, 0x02, 0x01, // messageID
    0x04, 0x63, 0x32, 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, 0x00, 0x0A, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x01, 0x01, (byte) 0xFF, (byte) 0x87, 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 43 with DecoderException

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

the class SearchRequestTest method testDecodeSearchRequestNoAttributes.

/**
 * Test the decoding of a SearchRequest with no attributes. The search
 * filter is : (objectclass=*)
 */
@Test
public void testDecodeSearchRequestNoAttributes() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x40);
    stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
    0x37, 0x02, 0x01, // messageID MessageID
    0x03, 0x63, // CHOICE { ..., searchRequest SearchRequest, ...
    0x32, // SearchRequest ::= APPLICATION[3] SEQUENCE {
    0x04, // baseObject LDAPDN,
    0x12, 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', 0x0A, 0x01, // scope ENUMERATED {
    0x00, // wholeSubtree (2) },
    0x0A, 0x01, // derefAliases ENUMERATED {
    0x03, // sizeLimit INTEGER (0 .. maxInt), (infinite)
    0x02, 0x01, 0x00, // timeLimit INTEGER (0 .. maxInt), (infinite)
    0x02, 0x01, 0x00, 0x01, 0x01, // typesOnly
    (byte) 0x00, // Filter ::= CHOICE {
    (byte) 0x87, // present [7] AttributeDescription,
    0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'C', 'l', 'a', 's', 's', // attributes AttributeDescriptionList }
    0x30, // AttributeDescriptionList ::= SEQUENCE OF
    0x00, // AttributeDescription
    0x00, // Some trailing 00, useless.
    0x00, 0x00, 0x00, 0x00, 0x00 });
    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());
    }
    assertEquals(TLVStateEnum.PDU_DECODED, ldapMessageContainer.getState());
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(3, searchRequest.getMessageId());
    assertEquals("ou=users,ou=system", searchRequest.getBase().toString());
    assertEquals(SearchScope.OBJECT, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(0, searchRequest.getSizeLimit());
    assertEquals(0, searchRequest.getTimeLimit());
    assertEquals(false, searchRequest.getTypesOnly());
    // (objectClass = *)
    ExprNode filter = searchRequest.getFilter();
    PresenceNode presenceNode = (PresenceNode) filter;
    assertNotNull(presenceNode);
    assertEquals("objectClass", presenceNode.getAttribute());
    // The attributes
    List<String> attributes = searchRequest.getAttributes();
    assertEquals(0, attributes.size());
    // Check the encoding
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x39, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu.substring(0, decodedPdu.length() - 35));
    } 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) EncoderException(org.apache.directory.api.asn1.EncoderException) PresenceNode(org.apache.directory.api.ldap.model.filter.PresenceNode) 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 44 with DecoderException

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

the class SearchRequestTest method testDecodeSearchRequestEmptyFilter.

/**
 * Test the decoding of a SearchRequest with an empty filter
 */
@Test
public void testDecodeSearchRequestEmptyFilter() {
    byte[] asn1BER = new byte[] { 0x30, 0x37, 0x02, 0x01, // messageID
    0x04, 0x63, 0x32, 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, 0x00, 0x0A, 0x01, 0x00, 0x02, 0x01, 0x00, 0x02, 0x01, 0x00, 0x01, 0x01, (byte) 0xFF, (byte) 0xA0, 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 45 with DecoderException

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

the class SearchRequestTest method testDecodeSearchRequestEmptyNotFilter.

/**
 * Test the decoding of a SearchRequest with an empty Not filter
 */
@Test
public void testDecodeSearchRequestEmptyNotFilter() {
    byte[] asn1BER = new byte[] { 0x30, 0x3B, 0x02, 0x01, // messageID
    0x04, 0x63, 0x36, 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) 0xA2, 0x00, 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)

Aggregations

DecoderException (org.apache.directory.api.asn1.DecoderException)404 ByteBuffer (java.nio.ByteBuffer)346 Test (org.junit.Test)346 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)334 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)269 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)269 EncoderException (org.apache.directory.api.asn1.EncoderException)145 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)102 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)73 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)50 Control (org.apache.directory.api.ldap.model.message.Control)40 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)38 Asn1Container (org.apache.directory.api.asn1.ber.Asn1Container)36 CodecControl (org.apache.directory.api.ldap.codec.api.CodecControl)34 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)28 Message (org.apache.directory.api.ldap.model.message.Message)25 BindRequestDecorator (org.apache.directory.api.ldap.codec.decorators.BindRequestDecorator)22 ModifyRequestDecorator (org.apache.directory.api.ldap.codec.decorators.ModifyRequestDecorator)22 BindRequest (org.apache.directory.api.ldap.model.message.BindRequest)22 AndNode (org.apache.directory.api.ldap.model.filter.AndNode)20