Java Code Examples for org.apache.directory.api.ldap.model.message.SearchRequest#getFilter()
The following examples show how to use
org.apache.directory.api.ldap.model.message.SearchRequest#getFilter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * 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 ); }
Example 2
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with a Substrings Filter with 1 Any element */ @Test public void testRequestWithSubstrings1Any() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_substrings_1_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( "kate", initials.get( 0 ) ); }
Example 3
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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() ); }
Example 4
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with a Substrings Filter with 1 Initial and 1 Final elements */ @Test public void testRequestWithSubstrings1Initial1Final() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_substrings_1_initial_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( "jack", substringFilter.getInitial() ); assertEquals( "john", substringFilter.getFinal() ); }
Example 5
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with an approxMatch Filter with empty value */ @Test public void testRequestWithApproxMatchFilterEmptyValue() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_approxMatch_with_empty_value.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 ApproximateNode ); ApproximateNode<?> approxMatchFilter = ( ApproximateNode<?> ) filter; assertEquals( "sn", approxMatchFilter.getAttribute() ); assertEquals( "", approxMatchFilter.getValue().getString() ); }
Example 6
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with an greaterOrEqual Filter */ @Test public void testRequestWithGreaterOrEqualFilter() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_greaterOrEqual.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 GreaterEqNode ); GreaterEqNode<?> greaterEqFilter = ( GreaterEqNode<?> ) filter; assertEquals( "sn", greaterEqFilter.getAttribute() ); assertEquals( "foobar", greaterEqFilter.getValue().getString() ); }
Example 7
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with an ExtensibleMatch Filter with empty value */ @Test public void testRequestWithExtensibleMatchWithEmptyValue() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_extensibleMatch_with_empty_value.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; assertNull( extensibleMatchFilter.getValue() ); assertEquals( false, extensibleMatchFilter.hasDnAttributes() ); }
Example 8
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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 ) ); }
Example 9
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with a Substrings Filter with 1 empty Any element */ @Test public void testRequestWithSubstrings1EmptyAny() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_substrings_1_empty_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( 0, initials.size() ); }
Example 10
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with an ExtensibleMatch Filter */ @Test public void testRequestWithExtensibleMatchFilterBase64Value() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_extensibleMatch_base64_value.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; assertEquals( "DSMLv2.0 rocks!!", extensibleMatchFilter.getValue().getString() ); assertEquals( false, extensibleMatchFilter.hasDnAttributes() ); }
Example 11
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with a matchingRule attribute */ @Test public void testRequestWithExtensibleMatchWithMatchingRule() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_extensibleMatch_with_matchingRule.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; assertEquals( "AMatchingRuleName", extensibleMatchFilter.getMatchingRuleId() ); }
Example 12
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with an Equality Filter */ @Test public void testRequestWithEqualityMatchFilter() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_equalityMatch.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 EqualityNode ); EqualityNode<?> equalityFilter = ( EqualityNode<?> ) filter; assertEquals( "sn", equalityFilter.getAttribute() ); assertEquals( "foobar", equalityFilter.getValue().getString() ); }
Example 13
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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() ); }
Example 14
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Test parsing of a request with an Equality Filter with an empty value */ @Test public void testRequestWithEqualityMatchFilterWithEmptyValue() { Dsmlv2Parser parser = null; try { parser = newParser(); parser.setInput( SearchRequestTest.class.getResource( "filters/request_with_equalityMatch_with_empty_value.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 EqualityNode ); EqualityNode<?> equalityFilter = ( EqualityNode<?> ) filter; assertEquals( "sn", equalityFilter.getAttribute() ); assertEquals( "", equalityFilter.getValue().getString() ); }
Example 15
Source File: SearchRequestTest.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * 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() ); }
Example 16
Source File: SearchRequestSubstringTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Test the decoding of a SearchRequest with a substring filter. Test the * initial filter : (objectclass=t*t*) */ @Test public void testDecodeSearchRequestSubstringInitialAnyAnyFinal() throws DecoderException, EncoderException, LdapException { ByteBuffer stream = ByteBuffer.allocate( 0x67 ); stream.put( new byte[] { 0x30, 0x65, // LDAPMessage ::=SEQUENCE { 0x02, 0x01, 0x01, // messageID 0x63, 0x60, // CHOICE { ..., searchRequest SearchRequest, ... // SearchRequest ::= APPLICATION[3] SEQUENCE { 0x04, 0x1F, // baseObject LDAPDN, '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, // scope ENUMERATED { // baseObject (0), // singleLevel (1), // wholeSubtree (2) }, 0x0A, 0x01, 0x03, // derefAliases ENUMERATED { // neverDerefAliases (0), // derefInSearching (1), // derefFindingBaseObj (2), // derefAlways (3) }, 0x02, 0x02, 0x03, ( byte ) 0xE8, // sizeLimit INTEGER (0 .. maxInt), (1000) 0x02, 0x02, 0x03, ( byte ) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000) 0x01, 0x01, ( byte ) 0xFF, // typesOnly BOOLEAN, (TRUE) filter Filter, ( byte ) 0xA4, 0x15, // Filter ::= CHOICE { // substrings [4] SubstringFilter // } // SubstringFilter ::= SEQUENCE { 0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x30, 0x06, ( byte ) 0x80, 0x01, 't', ( byte ) 0x81, 0x01, 't', 0x30, 0x15, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription 0x04, 0x05, 'a', 't', 't', 'r', '0', // AttributeDescription ::= LDAPString 0x04, 0x05, 'a', 't', 't', 'r', '1', // AttributeDescription ::= LDAPString 0x04, 0x05, 'a', 't', 't', 'r', '2' // AttributeDescription ::= LDAPString } ); stream.flip(); // Allocate a BindRequest Container LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); Asn1Decoder.decode( stream, ldapMessageContainer ); 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() ); // (objectclass=t*) ExprNode node = searchRequest.getFilter(); SubstringNode substringNode = ( SubstringNode ) node; assertNotNull( substringNode ); assertEquals( "objectclass", substringNode.getAttribute() ); assertEquals( "t", substringNode.getInitial() ); assertEquals( "t", substringNode.getAny().get( 0 ) ); // The attributes List<String> attributes = searchRequest.getAttributes(); for ( String attribute : attributes ) { assertNotNull( attribute ); } // Check encode reverse Asn1Buffer buffer = new Asn1Buffer(); LdapEncoder.encodeMessage( buffer, codec, searchRequest ); assertArrayEquals( stream.array(), buffer.getBytes().array() ); }
Example 17
Source File: SearchRequestSubstringTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Test the decoding of a SearchRequest with a substring filter. Test the * initial filter : (objectclass=*Amos) */ @Test public void testDecodeSearchRequestSubstringFinal() throws DecoderException, EncoderException, LdapException { ByteBuffer stream = ByteBuffer.allocate( 0x67 ); stream.put( new byte[] { 0x30, 0x65, // LDAPMessage ::=SEQUENCE { 0x02, 0x01, 0x01, // messageID 0x63, 0x60, // CHOICE { ..., searchRequest SearchRequest, ... // SearchRequest ::= APPLICATION[3] SEQUENCE { 0x04, 0x1F, // baseObject LDAPDN, '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, // scope ENUMERATED { // baseObject (0), // singleLevel (1), // wholeSubtree (2) }, 0x0A, 0x01, 0x03, // derefAliases ENUMERATED { // neverDerefAliases (0), // derefInSearching (1), // derefFindingBaseObj (2), // derefAlways (3) }, 0x02, 0x02, 0x03, ( byte ) 0xE8, // sizeLimit INTEGER (0 .. maxInt), (1000) 0x02, 0x02, 0x03, ( byte ) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000) 0x01, 0x01, ( byte ) 0xFF, // typesOnly BOOLEAN, (TRUE) filter Filter, ( byte ) 0xA4, 0x15, // Filter ::= CHOICE { // substrings [4] SubstringFilter // } // SubstringFilter ::= SEQUENCE { 0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x30, 0x06, ( byte ) 0x82, 0x04, 'A', 'm', 'o', 's', 0x30, 0x15, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription 0x04, 0x05, 'a', 't', 't', 'r', '0', // AttributeDescription ::= LDAPString 0x04, 0x05, 'a', 't', 't', 'r', '1', // AttributeDescription ::= LDAPString 0x04, 0x05, 'a', 't', 't', 'r', '2' // AttributeDescription ::= LDAPString } ); stream.flip(); // Allocate a BindRequest Container LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); Asn1Decoder.decode( stream, ldapMessageContainer ); 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() ); // (objectclass=t*) ExprNode node = searchRequest.getFilter(); SubstringNode substringNode = ( SubstringNode ) node; assertNotNull( substringNode ); assertEquals( "objectclass", substringNode.getAttribute() ); assertEquals( null, substringNode.getInitial() ); assertEquals( 0, substringNode.getAny().size() ); assertEquals( "Amos", substringNode.getFinal() ); // The attributes List<String> attributes = searchRequest.getAttributes(); for ( String attribute : attributes ) { assertNotNull( attribute ); } // Check encode reverse Asn1Buffer buffer = new Asn1Buffer(); LdapEncoder.encodeMessage( buffer, codec, searchRequest ); assertArrayEquals( stream.array(), buffer.getBytes().array() ); }
Example 18
Source File: SearchRequestSubstringTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Test the decoding of a SearchRequest with a substring filter. Test the * initial filter : (objectclass=t*) */ @Test public void testDecodeSearchRequestSubstringInitialAny() throws DecoderException, EncoderException, LdapException { ByteBuffer stream = ByteBuffer.allocate( 0x64 ); stream.put( new byte[] { 0x30, 0x62, // LDAPMessage ::=SEQUENCE { 0x02, 0x01, 0x01, // messageID 0x63, 0x5D, // CHOICE { ..., searchRequest SearchRequest, ... // SearchRequest ::= APPLICATION[3] SEQUENCE { 0x04, 0x1F, // baseObject LDAPDN, '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, // scope ENUMERATED { // baseObject (0), // singleLevel (1), // wholeSubtree (2) }, 0x0A, 0x01, 0x03, // derefAliases ENUMERATED { // neverDerefAliases (0), // derefInSearching (1), // derefFindingBaseObj (2), // derefAlways (3) }, 0x02, 0x02, 0x03, ( byte ) 0xE8, // sizeLimit INTEGER (0 .. maxInt), (1000) 0x02, 0x02, 0x03, ( byte ) 0xE8, // timeLimit INTEGER (0 .. maxInt), (1000) 0x01, 0x01, ( byte ) 0xFF, // typesOnly BOOLEAN, (TRUE) filter Filter, ( byte ) 0xA4, 0x12, // Filter ::= CHOICE { // substrings [4] SubstringFilter // } // SubstringFilter ::= SEQUENCE { 0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's', 0x30, 0x03, ( byte ) 0x80, 0x01, 't', 0x30, 0x15, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription 0x04, 0x05, 'a', 't', 't', 'r', '0', // AttributeDescription ::= LDAPString 0x04, 0x05, 'a', 't', 't', 'r', '1', // AttributeDescription ::= LDAPString 0x04, 0x05, 'a', 't', 't', 'r', '2' // AttributeDescription ::= LDAPString } ); stream.flip(); // Allocate a BindRequest Container LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); Asn1Decoder.decode( stream, ldapMessageContainer ); 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() ); // (objectclass=t*) ExprNode node = searchRequest.getFilter(); SubstringNode substringNode = ( SubstringNode ) node; assertNotNull( substringNode ); assertEquals( "objectclass", substringNode.getAttribute() ); assertEquals( "t", substringNode.getInitial() ); // The attributes List<String> attributes = searchRequest.getAttributes(); for ( String attribute : attributes ) { assertNotNull( attribute ); } // Check encode reverse Asn1Buffer buffer = new Asn1Buffer(); LdapEncoder.encodeMessage( buffer, codec, searchRequest ); assertArrayEquals( stream.array(), buffer.getBytes().array() ); }
Example 19
Source File: SearchRequestHandler.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * Alters the filter expression based on the presence of the * ManageDsaIT decorator. If the decorator is not present, the search * filter will be altered to become a disjunction with two terms. * The first term is the original filter. The second term is a * (objectClass=referral) assertion. When OR'd together these will * make sure we get all referrals so we can process continuations * properly without having the filter remove them from the result * set. * * NOTE: original filter is first since most entries are not referrals * so it has a higher probability on average of accepting and shorting * evaluation before having to waste cycles trying to evaluate if the * entry is a referral. * * @param session the session to use to construct the filter (schema access) * @param req the request to get the original filter from * @throws Exception if there are schema access problems */ private void modifyFilter( LdapSession session, SearchRequest req ) throws Exception { if ( req.hasControl( ManageDsaIT.OID ) ) { return; } /* * Most of the time the search filter is just (objectClass=*) and if * this is the case then there's no reason at all to OR this with an * (objectClass=referral). If we detect this case then we leave it * as is to represent the OR condition: * * (| (objectClass=referral)(objectClass=*)) == (objectClass=*) */ if ( req.getFilter() instanceof PresenceNode ) { PresenceNode presenceNode = ( PresenceNode ) req.getFilter(); if ( presenceNode.isSchemaAware() ) { AttributeType attributeType = presenceNode.getAttributeType(); if ( attributeType.equals( OBJECT_CLASS_AT ) ) { return; } } else { String attribute = presenceNode.getAttribute(); if ( attribute.equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT ) || attribute.equalsIgnoreCase( SchemaConstants.OBJECT_CLASS_AT_OID ) ) { return; } } } /* * Do not add the OR'd (objectClass=referral) expression if the user * searches for the subSchemaSubEntry as the SchemaIntercepter can't * handle an OR'd filter. */ if ( isSubSchemaSubEntrySearch( session, req ) ) { return; } // using varags to add two expressions to an OR node req.setFilter( new OrNode( req.getFilter(), newIsReferralEqualityNode( session ) ) ); }
Example 20
Source File: SearchRequestMatchingRuleAssertionTest.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Test the decoding of a SearchRequest with an extensible match and an * empty matchValue */ @Test public void testDecodeSearchRequestExtensibleMatchEmptyMatchValue() throws DecoderException, EncoderException, LdapException { byte[] asn1BER = new byte[] { 0x30, 0x41, 0x02, 0x01, 0x04, // messageID 0x63, 0x3C, 0x04, 0x1F, // baseObject LDAPDN, '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, 0x00, // matchValue [3] AssertionValue, 0x30, 0x00 // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription }; ByteBuffer stream = ByteBuffer.allocate( asn1BER.length ); stream.put( asn1BER ); stream.flip(); // Allocate a LdapMessage Container LdapMessageContainer<SearchRequest> ldapMessageContainer = new LdapMessageContainer<>( codec ); // Decode a SearchRequest message Asn1Decoder.decode( stream, ldapMessageContainer ); 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().getString() ); assertFalse( extensibleNode.hasDnAttributes() ); List<String> attributes = searchRequest.getAttributes(); assertEquals( 0, attributes.size() ); // Check encode reverse Asn1Buffer buffer = new Asn1Buffer(); LdapEncoder.encodeMessage( buffer, codec, searchRequest ); assertArrayEquals( stream.array(), buffer.getBytes().array() ); }