Search in sources :

Example 1 with OrNode

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

the class SearchRequestTest method testDecodeSearchRequestGlobalNoControls.

/**
 * Test the decoding of a SearchRequest with no controls. The search filter
 * is : (&(|(objectclass=top)(ou=contacts))(!(objectclass=ttt)))
 */
@Test
public void testDecodeSearchRequestGlobalNoControls() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0x90);
    stream.put(new byte[] { 0x30, (byte) 0x81, // LDAPMessage ::=SEQUENCE {
    (byte) 0x8D, 0x02, 0x01, // messageID MessageID
    0x01, 0x63, (byte) 0x81, // CHOICE { ...,
    (byte) 0x87, // 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 ENUMERATED {
    0x01, // wholeSubtree (2) },
    0x0A, 0x01, // derefAliases ENUMERATED {
    0x03, // derefAlways (3) },
    0x02, 0x02, 0x03, // sizeLimit INTEGER (0 .. maxInt), (1000)
    (byte) 0xE8, 0x02, 0x02, 0x03, // timeLimit INTEGER (0 .. maxInt), (1000)
    (byte) 0xE8, 0x01, 0x01, // typesOnly  BOOLEAN, (TRUE)
    (byte) 0xFF, // filter Filter,
    (byte) 0xA0, // Filter ::= CHOICE {
    0x3C, // and [0] SET OF Filter,
    (byte) 0xA1, // or [1] SET of Filter,
    0x24, (byte) 0xA3, // equalityMatch [3]
    0x12, // attributeDesc AttributeDescription (LDAPString),
    0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // assertionValue AssertionValue (OCTET STRING) }
    0x04, 0x03, 't', 'o', 'p', (byte) 0xA3, // equalityMatch [3] Assertion,
    0x0E, // Assertion ::= SEQUENCE {
    0x04, 0x02, 'o', // attributeDesc AttributeDescription (LDAPString),
    'u', // assertionValue AssertionValue (OCTET STRING) }
    0x04, 0x08, 'c', 'o', 'n', 't', 'a', 'c', 't', 's', (byte) 0xA2, // not [2] Filter,
    0x14, (byte) 0xA3, // equalityMatch [3] Assertion,
    0x12, // attributeDesc AttributeDescription (LDAPString),
    0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // assertionValue AssertionValue (OCTET STRING) }
    0x04, 0x03, 't', 't', 't', // attributes AttributeDescriptionList }
    0x30, // AttributeDescriptionList ::= SEQUENCE OF
    0x15, // AttributeDescription
    0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::= LDAPString
    '0', 0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::= LDAPString
    '1', 0x04, 0x05, 'a', 't', 't', 'r', // AttributeDescription ::= LDAPString
    '2' });
    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(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());
    // (& (...
    ExprNode node = searchRequest.getFilter();
    AndNode andNode = (AndNode) node;
    assertNotNull(andNode);
    List<ExprNode> andNodes = andNode.getChildren();
    // (& (| (...
    assertEquals(2, andNodes.size());
    OrNode orFilter = (OrNode) andNodes.get(0);
    assertNotNull(orFilter);
    // (& (| (obectclass=top) (...
    List<ExprNode> orNodes = orFilter.getChildren();
    assertEquals(2, orNodes.size());
    EqualityNode<?> equalityNode = (EqualityNode<?>) orNodes.get(0);
    assertNotNull(equalityNode);
    assertEquals("objectclass", equalityNode.getAttribute());
    assertEquals("top", equalityNode.getValue().getValue());
    // (& (| (objectclass=top) (ou=contacts) ) (...
    equalityNode = (EqualityNode<?>) orNodes.get(1);
    assertNotNull(equalityNode);
    assertEquals("ou", equalityNode.getAttribute());
    assertEquals("contacts", equalityNode.getValue().getValue());
    // (& (| (objectclass=top) (ou=contacts) ) (! ...
    NotNode notNode = (NotNode) andNodes.get(1);
    assertNotNull(notNode);
    // (& (| (objectclass=top) (ou=contacts) ) (! (objectclass=ttt) ) )
    equalityNode = (EqualityNode<?>) notNode.getFirstChild();
    assertNotNull(equalityNode);
    assertEquals("objectclass", equalityNode.getAttribute());
    assertEquals("ttt", equalityNode.getValue().getValue());
    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(0x90, bb.limit());
        String encodedPdu = Strings.dumpBytes(bb.array());
        assertEquals(encodedPdu.substring(0, 0x81), decodedPdu.substring(0, 0x81));
    } 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) NotNode(org.apache.directory.api.ldap.model.filter.NotNode) 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) OrNode(org.apache.directory.api.ldap.model.filter.OrNode) Test(org.junit.Test) AbstractCodecServiceTest(org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)

Example 2 with OrNode

use of org.apache.directory.api.ldap.model.filter.OrNode 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 3 with OrNode

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

the class SearchRequestTest method testDecodeSearchRequestGlobalNoControlsOidAndAlias.

/**
 * Test the decoding of a SearchRequest with no controls but with oid
 * attributes. The search filter is :
 * (&(|(objectclass=top)(2.5.4.11=contacts))(!(organizationalUnitName=ttt)))
 */
@Test
public void testDecodeSearchRequestGlobalNoControlsOidAndAlias() {
    Asn1Decoder ldapDecoder = new Asn1Decoder();
    ByteBuffer stream = ByteBuffer.allocate(0xA1);
    stream.put(new byte[] { 0x30, (byte) 0x81, // LDAPMessage ::=SEQUENCE {
    (byte) 0x9E, 0x02, 0x01, // messageID MessageID
    0x01, 0x63, (byte) 0x81, // CHOICE { ...,
    (byte) 0x98, // 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) 0xA0, // Filter ::= CHOICE {
    0x4D, // and [0] SET OF Filter,
    (byte) 0xA1, // or [1] SET of Filter,
    0x2A, (byte) 0xA3, // equalityMatch [3]
    0x12, // attributeDesc AttributeDescription (LDAPString),
    0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', // assertionValue AssertionValue (OCTET STRING) }
    0x04, 0x03, 't', 'o', 'p', (byte) 0xA3, // equalityMatch
    0x14, // Assertion ::= SEQUENCE {
    0x04, 0x08, '2', '.', '5', '.', '4', '.', '1', // attributeDesc
    '1', // assertionValue AssertionValue (OCTET STRING) }
    0x04, 0x08, 'c', 'o', 'n', 't', 'a', 'c', 't', 's', (byte) 0xA2, // not
    0x1F, // Filter,
    (byte) 0xA3, // equalityMatch [3]
    0x1D, // attributeDesc AttributeDescription (LDAPString),
    0x04, 0x16, 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a', 'l', 'U', 'n', 'i', 't', 'N', 'a', 'm', 'e', // assertionValue AssertionValue (OCTET STRING) }
    0x04, 0x03, 't', 't', 't', // attributes AttributeDescriptionList }
    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
    });
    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(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());
    // (& (...
    ExprNode filter = searchRequest.getFilter();
    AndNode andNode = (AndNode) filter;
    assertNotNull(andNode);
    List<ExprNode> andNodes = andNode.getChildren();
    // (& (| (...
    assertEquals(2, andNodes.size());
    OrNode orFilter = (OrNode) andNodes.get(0);
    assertNotNull(orFilter);
    // (& (| (obectclass=top) (...
    List<ExprNode> orNodes = orFilter.getChildren();
    assertEquals(2, orNodes.size());
    EqualityNode<?> equalityNode = (EqualityNode<?>) orNodes.get(0);
    assertNotNull(equalityNode);
    assertEquals("objectclass", equalityNode.getAttribute());
    assertEquals("top", equalityNode.getValue().getValue());
    // (& (| (objectclass=top) (ou=contacts) ) (...
    equalityNode = (EqualityNode<?>) orNodes.get(1);
    assertNotNull(equalityNode);
    assertEquals("2.5.4.11", equalityNode.getAttribute());
    assertEquals("contacts", equalityNode.getValue().getValue());
    // (& (| (objectclass=top) (ou=contacts) ) (! ...
    NotNode notNode = (NotNode) andNodes.get(1);
    assertNotNull(notNode);
    // (& (| (objectclass=top) (ou=contacts) ) (! (objectclass=ttt) ) )
    equalityNode = (EqualityNode<?>) notNode.getFirstChild();
    assertNotNull(equalityNode);
    assertEquals("organizationalUnitName", equalityNode.getAttribute());
    assertEquals("ttt", equalityNode.getValue().getValue());
    List<String> attributes = searchRequest.getAttributes();
    for (String attribute : attributes) {
        assertNotNull(attribute);
    }
// We won't check the encoding, as it has changed because of
// attributes transformations
}
Also used : LdapMessageContainer(org.apache.directory.api.ldap.codec.api.LdapMessageContainer) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) NotNode(org.apache.directory.api.ldap.model.filter.NotNode) 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 4 with OrNode

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

the class SearchRequestDsml method toDsml.

/**
 * Recursively converts the filter of the Search Request into a DSML representation and adds
 * it to the XML Element corresponding to the Search Request
 *
 * @param element
 *      the parent Element
 * @param filter
 *      the filter to convert
 */
private void toDsml(Element element, ExprNode filter) {
    // AND FILTER
    if (filter instanceof AndNode) {
        Element newElement = element.addElement("and");
        List<ExprNode> filterList = ((AndNode) filter).getChildren();
        for (int i = 0; i < filterList.size(); i++) {
            toDsml(newElement, filterList.get(i));
        }
    } else // OR FILTER
    if (filter instanceof OrNode) {
        Element newElement = element.addElement("or");
        List<ExprNode> filterList = ((OrNode) filter).getChildren();
        for (int i = 0; i < filterList.size(); i++) {
            toDsml(newElement, filterList.get(i));
        }
    } else // NOT FILTER
    if (filter instanceof NotNode) {
        Element newElement = element.addElement("not");
        toDsml(newElement, ((NotNode) filter).getFirstChild());
    } else // SUBSTRING FILTER
    if (filter instanceof SubstringNode) {
        Element newElement = element.addElement("substrings");
        SubstringNode substringFilter = (SubstringNode) filter;
        newElement.addAttribute(NAME, substringFilter.getAttribute());
        String initial = substringFilter.getInitial();
        if ((initial != null) && (!"".equals(initial))) {
            newElement.addElement("initial").setText(initial);
        }
        List<String> anyList = substringFilter.getAny();
        for (int i = 0; i < anyList.size(); i++) {
            newElement.addElement("any").setText(anyList.get(i));
        }
        String finalString = substringFilter.getFinal();
        if ((finalString != null) && (!"".equals(finalString))) {
            newElement.addElement("final").setText(finalString);
        }
    } else // APPROXMATCH, EQUALITYMATCH, GREATEROREQUALS & LESSOREQUAL FILTERS
    if (filter instanceof SimpleNode) {
        Element newElement;
        if (filter instanceof ApproximateNode) {
            newElement = element.addElement("approxMatch");
        } else if (filter instanceof EqualityNode) {
            newElement = element.addElement("equalityMatch");
        } else if (filter instanceof GreaterEqNode) {
            newElement = element.addElement("greaterOrEqual");
        } else // it is a LessEqNode )
        {
            newElement = element.addElement("lessOrEqual");
        }
        String attributeName = ((SimpleNode<?>) filter).getAttribute();
        newElement.addAttribute(NAME, attributeName);
        Value value = ((SimpleNode<?>) filter).getValue();
        if (value != null) {
            if (ParserUtils.needsBase64Encoding(value)) {
                Namespace xsdNamespace = new Namespace("xsd", ParserUtils.XML_SCHEMA_URI);
                Namespace xsiNamespace = new Namespace("xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI);
                element.getDocument().getRootElement().add(xsdNamespace);
                element.getDocument().getRootElement().add(xsiNamespace);
                Element valueElement = newElement.addElement(VALUE).addText(ParserUtils.base64Encode(value));
                valueElement.addAttribute(new QName("type", xsiNamespace), "xsd:" + ParserUtils.BASE64BINARY);
            } else {
                newElement.addElement(VALUE).setText(value.getValue());
            }
        }
    } else // PRESENT FILTER
    if (filter instanceof PresenceNode) {
        Element newElement = element.addElement("present");
        newElement.addAttribute(NAME, ((PresenceNode) filter).getAttribute());
    } else // EXTENSIBLEMATCH
    if (filter instanceof ExtensibleNode) {
        Element newElement = element.addElement("extensibleMatch");
        Value value = ((ExtensibleNode) filter).getValue();
        if (value != null) {
            if (ParserUtils.needsBase64Encoding(value)) {
                Namespace xsdNamespace = new Namespace("xsd", ParserUtils.XML_SCHEMA_URI);
                Namespace xsiNamespace = new Namespace("xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI);
                element.getDocument().getRootElement().add(xsdNamespace);
                element.getDocument().getRootElement().add(xsiNamespace);
                Element valueElement = newElement.addElement(VALUE).addText(ParserUtils.base64Encode(value.getValue()));
                valueElement.addAttribute(new QName("type", xsiNamespace), "xsd:" + ParserUtils.BASE64BINARY);
            } else {
                newElement.addElement(VALUE).setText(value.getValue());
            }
        }
        if (((ExtensibleNode) filter).hasDnAttributes()) {
            newElement.addAttribute("dnAttributes", "true");
        }
        String matchingRule = ((ExtensibleNode) filter).getMatchingRuleId();
        if ((matchingRule != null) && ("".equals(matchingRule))) {
            newElement.addAttribute("matchingRule", matchingRule);
        }
    }
}
Also used : SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) ApproximateNode(org.apache.directory.api.ldap.model.filter.ApproximateNode) NotNode(org.apache.directory.api.ldap.model.filter.NotNode) QName(org.dom4j.QName) PresenceNode(org.apache.directory.api.ldap.model.filter.PresenceNode) Element(org.dom4j.Element) AndNode(org.apache.directory.api.ldap.model.filter.AndNode) ExtensibleNode(org.apache.directory.api.ldap.model.filter.ExtensibleNode) Namespace(org.dom4j.Namespace) SimpleNode(org.apache.directory.api.ldap.model.filter.SimpleNode) ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) GreaterEqNode(org.apache.directory.api.ldap.model.filter.GreaterEqNode) Value(org.apache.directory.api.ldap.model.entry.Value) ArrayList(java.util.ArrayList) List(java.util.List) EqualityNode(org.apache.directory.api.ldap.model.filter.EqualityNode) OrNode(org.apache.directory.api.ldap.model.filter.OrNode)

Example 5 with OrNode

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

the class SearchRequestTest method testRequestWithOrFilter.

/**
 * Test parsing of a request with an Or Filter
 */
@Test
public void testRequestWithOrFilter() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(SearchRequestTest.class.getResource("filters/request_with_or.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchRequest searchRequest = (SearchRequest) parser.getBatchRequest().getCurrentRequest();
    ExprNode filter = searchRequest.getFilter();
    assertTrue(filter instanceof OrNode);
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) OrNode(org.apache.directory.api.ldap.model.filter.OrNode) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Aggregations

OrNode (org.apache.directory.api.ldap.model.filter.OrNode)16 AndNode (org.apache.directory.api.ldap.model.filter.AndNode)14 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)13 DecoderException (org.apache.directory.api.asn1.DecoderException)11 EqualityNode (org.apache.directory.api.ldap.model.filter.EqualityNode)11 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)11 Test (org.junit.Test)11 ByteBuffer (java.nio.ByteBuffer)10 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)10 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)10 SearchRequestDecorator (org.apache.directory.api.ldap.codec.decorators.SearchRequestDecorator)10 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)10 NotNode (org.apache.directory.api.ldap.model.filter.NotNode)9 PresenceNode (org.apache.directory.api.ldap.model.filter.PresenceNode)8 EncoderException (org.apache.directory.api.asn1.EncoderException)7 GreaterEqNode (org.apache.directory.api.ldap.model.filter.GreaterEqNode)7 SubstringNode (org.apache.directory.api.ldap.model.filter.SubstringNode)6 ApproximateNode (org.apache.directory.api.ldap.model.filter.ApproximateNode)5 Value (org.apache.directory.api.ldap.model.entry.Value)4 ExtensibleNode (org.apache.directory.api.ldap.model.filter.ExtensibleNode)4