Search in sources :

Example 31 with SubstringNode

use of org.apache.directory.api.ldap.model.filter.SubstringNode in project directory-ldap-api by apache.

the class SearchRequestTest method testDecodeSearchRequestComplexFilterWithControl.

/**
 * Test the decoding of a SearchRequest with a complex filter :
 * (&(objectClass=person)(|(cn=Tori*)(sn=Jagger)))
 */
@Test
public void testDecodeSearchRequestComplexFilterWithControl() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x77);
    stream.put(new byte[] { // LdapMessage
    0x30, // LdapMessage
    0x75, 0x02, 0x01, // message Id = 6
    0x06, 0x63, // SearchRequest
    0x53, 0x04, // BaseDN 'ou=system'
    0x09, 0x6F, 0x75, 0x3D, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x0A, 0x01, // scope = SUBTREE
    0x02, 0x0A, 0x01, // derefAlias = 3
    0x03, 0x02, 0x01, // sizeLimit = none
    0x00, 0x02, 0x01, // timeLimit = none
    0x00, 0x01, 0x01, // types only = false
    0x00, (byte) 0xA0, // AND
    0x35, (byte) 0xA3, // equals
    0x15, 0x04, // 'objectclass'
    0x0B, 0x6F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x04, // 'person'
    0x06, 0x70, 0x65, 0x72, 0x73, 0x6F, 0x6E, (byte) 0xA1, // OR
    0x1C, (byte) 0xA4, // substrings : 'cn=Tori*'
    0x0C, 0x04, // 'cn'
    0x02, 0x63, 0x6E, 0x30, // initial = 'Tori'
    0x06, (byte) 0x80, 0x04, 0x54, 0x6F, 0x72, 0x69, (byte) 0xA3, // equals
    0x0C, 0x04, // 'sn'
    0x02, 0x73, 0x6E, 0x04, // 'Jagger'
    0x06, 0x4A, 0x61, 0x67, 0x67, 0x65, 0x72, 0x30, // Control
    0x00, (byte) 0xA0, 0x1B, 0x30, 0x19, 0x04, 0x17, '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2' });
    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(6, searchRequest.getMessageId());
    assertEquals("ou=system", searchRequest.getBase().toString());
    assertEquals(SearchScope.SUBTREE, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, 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());
    // (&(objectClass=person)..
    EqualityNode<?> equalityNode = (EqualityNode<?>) andNodes.get(0);
    assertNotNull(equalityNode);
    assertEquals("objectClass", equalityNode.getAttribute());
    assertEquals("person", equalityNode.getValue().getValue());
    // (&(a=b)(|
    OrNode orNode = (OrNode) andNodes.get(1);
    assertNotNull(orNode);
    List<ExprNode> orNodes = orNode.getChildren();
    assertEquals(2, orNodes.size());
    // (&(a=b)(|(cn=Tori*
    SubstringNode substringNode = (SubstringNode) orNodes.get(0);
    assertNotNull(substringNode);
    assertEquals("cn", substringNode.getAttribute());
    assertEquals("Tori", substringNode.getInitial());
    assertEquals(0, substringNode.getAny().size());
    assertEquals(null, substringNode.getFinal());
    // (&(a=b)(|(cn=Tori*)(sn=Jagger)))
    equalityNode = (EqualityNode<?>) orNodes.get(1);
    assertNotNull(equalityNode);
    assertEquals("sn", equalityNode.getAttribute());
    assertEquals("Jagger", equalityNode.getValue().getValue());
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) 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 32 with SubstringNode

use of org.apache.directory.api.ldap.model.filter.SubstringNode in project directory-ldap-api by apache.

the class SearchRequestTest method testDecodeSearchRequestDIRSERVER_651.

/**
 * Test the decoding of a SearchRequest with a greaterOrEqual filter and an
 * empty attributeValue, and an '*' attribute List
 */
@Test
public void testDecodeSearchRequestDIRSERVER_651() {
    byte[] asn1BER = new byte[] { 0x30, 0x60, 0x02, 0x01, 0x02, 0x63, 0x5b, 0x04, 0x0a, 'd', 'c', '=', 'p', 'g', 'p', 'k', 'e', 'y', 's', 0x0a, 01, 02, 0x0a, 01, 00, 0x02, 01, 00, 0x02, 01, 00, 0x01, 01, 00, (byte) 0xa0, 0x3c, (byte) 0xa4, 0x28, 0x04, 0x09, 'p', 'g', 'p', 'u', 's', 'e', 'r', 'i', 'd', 0x30, 0x1b, (byte) 0x80, 0x19, 'v', 'g', 'j', 'o', 'k', 'j', 'e', 'v', '@', 'n', 'e', 't', 'c', 'e', 't', 'e', 'r', 'a', '.', 'c', 'o', 'm', '.', 'm', 'k', (byte) 0xa3, 0x10, 0x04, 0x0b, 'p', 'g', 'p', 'd', 'i', 's', 'a', 'b', 'l', 'e', 'd', 0x04, 0x01, '0', 0x30, 0x00 };
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(asn1BER.length);
    stream.put(asn1BER);
    String decodedPdu = Strings.dumpBytes(stream.array());
    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) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    assertEquals(TLVStateEnum.PDU_DECODED, ldapMessageContainer.getState());
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(2, searchRequest.getMessageId());
    assertEquals("dc=pgpkeys", 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());
    // And
    ExprNode filter = searchRequest.getFilter();
    AndNode andNode = (AndNode) filter;
    assertNotNull(andNode);
    List<ExprNode> andNodes = andNode.getChildren();
    assertEquals(2, andNodes.size());
    SubstringNode substringNode = (SubstringNode) andNodes.get(0);
    assertNotNull(substringNode);
    assertEquals("pgpuserid", substringNode.getAttribute());
    assertEquals("vgjokjev@netcetera.com.mk", substringNode.getInitial());
    assertEquals(0, substringNode.getAny().size());
    assertEquals(null, substringNode.getFinal());
    EqualityNode<?> equalityNode = (EqualityNode<?>) andNodes.get(1);
    assertNotNull(equalityNode);
    assertEquals("pgpdisabled", equalityNode.getAttribute());
    assertEquals("0", equalityNode.getValue().getValue());
    // attributes may have been reordered
    try {
        ByteBuffer bb = encoder.encodeMessage(searchRequest);
        // Check the length
        assertEquals(0x62, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu, decodedPdu);
    } catch (EncoderException ee) {
        ee.printStackTrace();
        fail(ee.getMessage());
    }
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) 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) EncoderException(org.apache.directory.api.asn1.EncoderException) 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) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Aggregations

SubstringNode (org.apache.directory.api.ldap.model.filter.SubstringNode)32 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)29 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)26 Test (org.junit.Test)26 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)14 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)14 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)14 DecoderException (org.apache.directory.api.asn1.DecoderException)13 ByteBuffer (java.nio.ByteBuffer)12 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)12 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)12 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)12 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)12 EncoderException (org.apache.directory.api.asn1.EncoderException)11 AndNode (org.apache.directory.api.ldap.model.filter.AndNode)7 EqualityNode (org.apache.directory.api.ldap.model.filter.EqualityNode)6 OrNode (org.apache.directory.api.ldap.model.filter.OrNode)6 PresenceNode (org.apache.directory.api.ldap.model.filter.PresenceNode)5 Value (org.apache.directory.api.ldap.model.entry.Value)4 ApproximateNode (org.apache.directory.api.ldap.model.filter.ApproximateNode)4