Search in sources :

Example 11 with ExtensibleNode

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

the class SearchRequestTest method testRequestWithExtensibleMatchWithDnAttributesTrue.

/**
 * Test parsing of a request with typesOnly to true
 */
@Test
public void testRequestWithExtensibleMatchWithDnAttributesTrue() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(SearchRequestTest.class.getResource("filters/request_with_extensibleMatch_with_dnAttributes_true.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 ExtensibleNode);
    ExtensibleNode extensibleMatchFilter = (ExtensibleNode) filter;
    assertTrue(extensibleMatchFilter.hasDnAttributes());
}
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) ExtensibleNode(org.apache.directory.api.ldap.model.filter.ExtensibleNode) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 12 with ExtensibleNode

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

the class SearchRequestTest method testRequestWithExtensibleMatchWithDnAttributes1.

/**
 * Test parsing of a request with typesOnly to 1
 */
@Test
public void testRequestWithExtensibleMatchWithDnAttributes1() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(SearchRequestTest.class.getResource("filters/request_with_extensibleMatch_with_dnAttributes_1.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 ExtensibleNode);
    ExtensibleNode extensibleMatchFilter = (ExtensibleNode) filter;
    assertTrue(extensibleMatchFilter.hasDnAttributes());
}
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) ExtensibleNode(org.apache.directory.api.ldap.model.filter.ExtensibleNode) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 13 with ExtensibleNode

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

the class SearchRequestTest method testRequestWithExtensibleMatchWithDnAttributes0.

/**
 * Test parsing of a request with typesOnly to 0
 */
@Test
public void testRequestWithExtensibleMatchWithDnAttributes0() {
    Dsmlv2Parser parser = null;
    try {
        parser = newParser();
        parser.setInput(SearchRequestTest.class.getResource("filters/request_with_extensibleMatch_with_dnAttributes_0.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 ExtensibleNode);
    ExtensibleNode extensibleMatchFilter = (ExtensibleNode) filter;
    assertFalse(extensibleMatchFilter.hasDnAttributes());
}
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) ExtensibleNode(org.apache.directory.api.ldap.model.filter.ExtensibleNode) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test) AbstractTest(org.apache.directory.api.dsmlv2.AbstractTest)

Example 14 with ExtensibleNode

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

the class SearchRequestDsml method transform.

/**
 * Transform the Filter part of a SearchRequest to an ExprNode
 *
 * @param filter The filter to be transformed
 * @return An ExprNode
 */
@SuppressWarnings({ "rawtypes" })
private ExprNode transform(Filter filter) throws LdapSchemaException {
    if (filter != null) {
        // Transform OR, AND or NOT leaves
        if (filter instanceof ConnectorFilter) {
            BranchNode branch;
            if (filter instanceof AndFilter) {
                branch = new AndNode();
            } else if (filter instanceof OrFilter) {
                branch = new OrNode();
            } else {
                branch = new NotNode();
            }
            List<Filter> filtersSet = ((ConnectorFilter) filter).getFilterSet();
            // Loop on all AND/OR children
            if (filtersSet != null) {
                for (Filter node : filtersSet) {
                    branch.addNode(transform(node));
                }
            }
            return branch;
        } else {
            // Transform PRESENT or ATTRIBUTE_VALUE_ASSERTION
            LeafNode branch = null;
            if (filter instanceof PresentFilter) {
                branch = new PresenceNode(((PresentFilter) filter).getAttributeDescription());
            } else if (filter instanceof AttributeValueAssertionFilter) {
                AttributeValueAssertionFilter avaFilter = (AttributeValueAssertionFilter) filter;
                AttributeValueAssertion ava = avaFilter.getAssertion();
                // Transform =, >=, <=, ~= filters
                int filterType = avaFilter.getFilterType();
                byte[] value = null;
                if (ava.getAssertionValue() != null) {
                    value = ava.getAssertionValue().getBytes();
                }
                switch(filterType) {
                    case LdapCodecConstants.EQUALITY_MATCH_FILTER:
                        branch = new EqualityNode(ava.getAttributeDesc(), value);
                        break;
                    case LdapCodecConstants.GREATER_OR_EQUAL_FILTER:
                        branch = new GreaterEqNode(ava.getAttributeDesc(), value);
                        break;
                    case LdapCodecConstants.LESS_OR_EQUAL_FILTER:
                        branch = new LessEqNode(ava.getAttributeDesc(), value);
                        break;
                    case LdapCodecConstants.APPROX_MATCH_FILTER:
                        branch = new ApproximateNode(ava.getAttributeDesc(), value);
                        break;
                    default:
                        throw new IllegalStateException("Unexpected filter type " + filterType);
                }
            } else if (filter instanceof SubstringFilter) {
                // Transform Substring filters
                SubstringFilter substrFilter = (SubstringFilter) filter;
                String initialString = null;
                String finalString = null;
                List<String> anyString = null;
                if (substrFilter.getInitialSubstrings() != null) {
                    initialString = substrFilter.getInitialSubstrings();
                }
                if (substrFilter.getFinalSubstrings() != null) {
                    finalString = substrFilter.getFinalSubstrings();
                }
                if (substrFilter.getAnySubstrings() != null) {
                    anyString = new ArrayList<>();
                    for (String any : substrFilter.getAnySubstrings()) {
                        anyString.add(any);
                    }
                }
                branch = new SubstringNode(anyString, substrFilter.getType(), initialString, finalString);
            } else if (filter instanceof ExtensibleMatchFilter) {
                // Transform Extensible Match Filter
                ExtensibleMatchFilter extFilter = (ExtensibleMatchFilter) filter;
                String matchingRule = null;
                Value value = extFilter.getMatchValue();
                if (extFilter.getMatchingRule() != null) {
                    matchingRule = extFilter.getMatchingRule();
                }
                branch = new ExtensibleNode(extFilter.getType(), value, matchingRule, extFilter.isDnAttributes());
            }
            return branch;
        }
    } else {
        // We have found nothing to transform. Return null then.
        return null;
    }
}
Also used : ApproximateNode(org.apache.directory.api.ldap.model.filter.ApproximateNode) NotNode(org.apache.directory.api.ldap.model.filter.NotNode) PresenceNode(org.apache.directory.api.ldap.model.filter.PresenceNode) AndNode(org.apache.directory.api.ldap.model.filter.AndNode) ExtensibleNode(org.apache.directory.api.ldap.model.filter.ExtensibleNode) BranchNode(org.apache.directory.api.ldap.model.filter.BranchNode) LeafNode(org.apache.directory.api.ldap.model.filter.LeafNode) LessEqNode(org.apache.directory.api.ldap.model.filter.LessEqNode) OrNode(org.apache.directory.api.ldap.model.filter.OrNode) SubstringNode(org.apache.directory.api.ldap.model.filter.SubstringNode) GreaterEqNode(org.apache.directory.api.ldap.model.filter.GreaterEqNode) Value(org.apache.directory.api.ldap.model.entry.Value) EqualityNode(org.apache.directory.api.ldap.model.filter.EqualityNode)

Example 15 with ExtensibleNode

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

the class SearchRequestMatchingRuleAssertionTest method testDecodeSearchRequestExtensibleMatchEmptyMatchValue.

/**
 * Test the decoding of a SearchRequest with an extensible match and an
 * empty matchValue
 */
@Test
public void testDecodeSearchRequestExtensibleMatchEmptyMatchValue() {
    byte[] asn1BER = new byte[] { 0x30, 0x43, 0x02, 0x01, // messageID
    0x04, 0x63, 0x3E, 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) 0xA9, 0x08, (byte) 0x81, 0x04, 't', 'e', 's', 't', (byte) 0x83, // matchValue      [3] AssertionValue,
    0x00, 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) {
        de.printStackTrace();
        fail(de.getMessage());
    }
    SearchRequest searchRequest = ldapMessageContainer.getMessage();
    assertEquals(4, searchRequest.getMessageId());
    assertEquals("uid=akarasulu,dc=example,dc=com", searchRequest.getBase().toString());
    assertEquals(SearchScope.ONELEVEL, searchRequest.getScope());
    assertEquals(AliasDerefMode.DEREF_ALWAYS, searchRequest.getDerefAliases());
    assertEquals(0, searchRequest.getSizeLimit());
    assertEquals(0, searchRequest.getTimeLimit());
    assertEquals(true, searchRequest.getTypesOnly());
    // Extended
    ExprNode filter = searchRequest.getFilter();
    ExtensibleNode extensibleNode = (ExtensibleNode) filter;
    assertNotNull(extensibleNode);
    assertEquals("test", extensibleNode.getMatchingRuleId());
    assertNull(extensibleNode.getAttribute());
    assertEquals("", extensibleNode.getValue().getValue());
    assertFalse(extensibleNode.hasDnAttributes());
    List<String> attributes = searchRequest.getAttributes();
    assertEquals(0, attributes.size());
}
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) Asn1Decoder(org.apache.directory.api.asn1.ber.Asn1Decoder) ExtensibleNode(org.apache.directory.api.ldap.model.filter.ExtensibleNode) 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

ExtensibleNode (org.apache.directory.api.ldap.model.filter.ExtensibleNode)15 ExprNode (org.apache.directory.api.ldap.model.filter.ExprNode)13 SearchRequest (org.apache.directory.api.ldap.model.message.SearchRequest)11 Test (org.junit.Test)11 AbstractTest (org.apache.directory.api.dsmlv2.AbstractTest)9 Dsmlv2Parser (org.apache.directory.api.dsmlv2.Dsmlv2Parser)9 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)9 Value (org.apache.directory.api.ldap.model.entry.Value)4 AndNode (org.apache.directory.api.ldap.model.filter.AndNode)4 ApproximateNode (org.apache.directory.api.ldap.model.filter.ApproximateNode)4 EqualityNode (org.apache.directory.api.ldap.model.filter.EqualityNode)4 GreaterEqNode (org.apache.directory.api.ldap.model.filter.GreaterEqNode)4 OrNode (org.apache.directory.api.ldap.model.filter.OrNode)4 PresenceNode (org.apache.directory.api.ldap.model.filter.PresenceNode)4 SubstringNode (org.apache.directory.api.ldap.model.filter.SubstringNode)4 DecoderException (org.apache.directory.api.asn1.DecoderException)3 BranchNode (org.apache.directory.api.ldap.model.filter.BranchNode)3 LessEqNode (org.apache.directory.api.ldap.model.filter.LessEqNode)3 NotNode (org.apache.directory.api.ldap.model.filter.NotNode)3 ByteBuffer (java.nio.ByteBuffer)2