Search in sources :

Example 6 with SubstringNode

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

the class SearchRequestTest method testRequestWithSubstrings1Base64Any.

/**
 * Test parsing of a request with a Substrings Filter with 1 Any element
 */
@Test
public void testRequestWithSubstrings1Base64Any() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(SearchRequestTest.class.getResource("filters/request_with_substrings_1_base64_any.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 SubstringNode);
    SubstringNode substringFilter = (SubstringNode) filter;
    List<String> initials = substringFilter.getAny();
    assertEquals(1, initials.size());
    assertEquals("DSMLv2.0 rocks!!", initials.get(0));
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 7 with SubstringNode

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

the class SearchRequestTest method testRequestWithSubstrings1Final.

/**
 * Test parsing of a request with a Substrings Filter with 1 Final element
 */
@Test
public void testRequestWithSubstrings1Final() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(SearchRequestTest.class.getResource("filters/request_with_substrings_1_final.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 SubstringNode);
    SubstringNode substringFilter = (SubstringNode) filter;
    assertEquals("john", substringFilter.getFinal().toString());
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 8 with SubstringNode

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

the class SearchRequestTest method testRequestWithSubstrings2Any.

/**
 * Test parsing of a request with a Substrings Filter with 1 Any element
 */
@Test
public void testRequestWithSubstrings2Any() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(SearchRequestTest.class.getResource("filters/request_with_substrings_2_any.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 SubstringNode);
    SubstringNode substringFilter = (SubstringNode) filter;
    List<String> initials = substringFilter.getAny();
    assertEquals(2, initials.size());
    assertEquals("kate", initials.get(0));
    assertEquals("sawyer", initials.get(1));
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 9 with SubstringNode

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

the class SearchRequestTest method testRequestWithSubstrings1Base64Initial.

/**
 * Test parsing of a request with a Substrings Filter with 1 Initial element with Base64 value
 */
@Test
public void testRequestWithSubstrings1Base64Initial() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(SearchRequestTest.class.getResource("filters/request_with_substrings_1_base64_initial.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 SubstringNode);
    SubstringNode substringFilter = (SubstringNode) filter;
    assertEquals("DSMLv2.0 rocks!!", substringFilter.getInitial().toString());
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) SearchRequest(org.apache.directory.api.ldap.model.message.SearchRequest) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) Dsmlv2Parser(org.apache.directory.api.dsmlv2.Dsmlv2Parser) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 10 with SubstringNode

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

the class StructrLDAPWrapper method matches.

private boolean matches(final LDAPNode node, final ExprNode filter) throws FrameworkException, LdapInvalidAttributeValueException {
    if (filter instanceof SimpleNode) {
        return evaluateSimpleNode(node, (SimpleNode) filter);
    } else if (filter instanceof SubstringNode) {
        return evaluateSubstringNode(node, (SubstringNode) filter);
    } else if (filter instanceof PresenceNode) {
        final PresenceNode presence = (PresenceNode) filter;
        final Attribute attribute = new DefaultAttribute(presence.getAttributeType());
        return findAttribute(node, attribute.getId()) != null;
    } else if (filter instanceof OrNode) {
        final OrNode orNode = (OrNode) filter;
        for (final ExprNode child : orNode.getChildren()) {
            if (matches(node, child)) {
                return true;
            }
        }
        return false;
    } else if (filter instanceof AndNode) {
        final AndNode andNode = (AndNode) filter;
        boolean result = true;
        for (final ExprNode child : andNode.getChildren()) {
            result &= matches(node, child);
        }
        return result;
    } else {
        System.out.println("Unsupported filter type " + filter.getClass());
    }
    return false;
}
Also used : ExprNode(org.apache.directory.api.ldap.model.filter.ExprNode) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) NodeAttribute(org.structr.core.graph.NodeAttribute) LDAPAttribute(org.structr.ldap.entity.LDAPAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) PresenceNode(org.apache.directory.api.ldap.model.filter.PresenceNode) AndNode(org.apache.directory.api.ldap.model.filter.AndNode) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) SimpleNode(org.apache.directory.api.ldap.model.filter.SimpleNode) OrNode(org.apache.directory.api.ldap.model.filter.OrNode)

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