org.apache.directory.api.ldap.model.filter.FilterParser Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.filter.FilterParser. 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: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubstringNoIniManyAnyNoFinal() throws ParseException
{
    SubstringNode node = ( SubstringNode ) FilterParser.parse( null, "(ou=*b*c*d*e*)" );
    // just check that it doesn't throw for now
    node = ( SubstringNode ) node.clone();

    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );
    assertEquals( 4, node.getAny().size() );
    assertFalse( node.getAny().contains( "" ) );
    assertTrue( node.getAny().contains( "e" ) );
    assertTrue( node.getAny().contains( "b" ) );
    assertTrue( node.getAny().contains( "c" ) );
    assertTrue( node.getAny().contains( "d" ) );
    assertEquals( null, node.getInitial() );
    assertEquals( null, node.getFinal() );
}
 
Example #2
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubstringManyAny() throws ParseException
{
    String str = "(ou=a*b*c*d*e*f)";
    SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );

    assertEquals( 4, node.getAny().size() );
    assertFalse( node.getAny().contains( "" ) );
    assertTrue( node.getAny().contains( "b" ) );
    assertTrue( node.getAny().contains( "c" ) );
    assertTrue( node.getAny().contains( "d" ) );
    assertTrue( node.getAny().contains( "e" ) );
    assertEquals( "a", node.getInitial() );
    assertEquals( "f", node.getFinal() );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #3
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testThreeByteUTF8Escaped() throws ParseException
{
    byte[] bytes =
        { ( byte ) 0xE2, ( byte ) 0x89, ( byte ) 0xA0 }; // unicode U+2260: "not equal to" sign in decimal signed bytes is -30, -119, -96

    String str = "(cn=\\E2\\89\\A0aa)";
    String strEscaped = "(cn=\\E2\\89\\A0\\61\\61)";
    new String( bytes, StandardCharsets.UTF_8 );

    SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str );

    assertEquals( "cn", node.getAttribute() );
    String val = node.getValue().getString();
    assertEquals( "2260", Integer.toHexString( val.charAt( 0 ) ) );
    String str2 = node.toString();
    assertEquals( strEscaped, str2 );
}
 
Example #4
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubstringNoIniManyAny() throws ParseException
{
    String str = "(ou=*b*c*d*e*f)";
    SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );

    assertEquals( 4, node.getAny().size() );
    assertFalse( node.getAny().contains( new Value( "" ).getString() ) );
    assertTrue( node.getAny().contains( "e" ) );
    assertTrue( node.getAny().contains( "b" ) );
    assertTrue( node.getAny().contains( "c" ) );
    assertTrue( node.getAny().contains( "d" ) );
    assertEquals( null, node.getInitial() );
    assertEquals( "f", node.getFinal() );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #5
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubstringManyAnyNoFinal() throws ParseException
{
    String str = "(ou=a*b*c*d*e*)";
    SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );

    assertEquals( 4, node.getAny().size() );
    assertFalse( node.getAny().contains( "" ) );
    assertTrue( node.getAny().contains( "e" ) );
    assertTrue( node.getAny().contains( "b" ) );
    assertTrue( node.getAny().contains( "c" ) );
    assertTrue( node.getAny().contains( "d" ) );
    assertEquals( "a", node.getInitial() );
    assertEquals( null, node.getFinal() );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #6
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubstringNoIniManyAnyNoFinal() throws ParseException
{
    String str = "(ou=*b*c*d*e*)";
    SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );

    assertEquals( 4, node.getAny().size() );
    assertFalse( node.getAny().contains( new Value( "" ).getString() ) );
    assertTrue( node.getAny().contains( "e" ) );
    assertTrue( node.getAny().contains( "b" ) );
    assertTrue( node.getAny().contains( "c" ) );
    assertTrue( node.getAny().contains( "d" ) );
    assertEquals( null, node.getInitial() );
    assertEquals( null, node.getFinal() );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #7
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubstringNoAnyDoubleSpaceStar() throws ParseException
{
    String str = "(ou=foo* *bar)";
    SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );

    assertEquals( 1, node.getAny().size() );
    assertFalse( node.getAny().contains( "" ) );
    assertTrue( node.getAny().contains( " " ) );
    assertEquals( "foo", node.getInitial() );
    assertEquals( "bar", node.getFinal() );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #8
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubstringAnyDoubleSpaceStar() throws ParseException
{
    String str = "(ou=foo* a *bar)";
    SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );

    assertEquals( 1, node.getAny().size() );
    assertFalse( node.getAny().contains( "" ) );
    assertTrue( node.getAny().contains( " a " ) );
    assertEquals( "foo", node.getInitial() );
    assertEquals( "bar", node.getFinal() );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #9
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Enrique just found this bug with the filter parser when parsing substring
 * expressions like *any*. Here's the JIRA issue: <a
 * href="http://nagoya.apache.org/jira/browse/DIRLDAP-21">DIRLDAP-21</a>.
 */
@Test
public void testSubstringStarAnyStar() throws ParseException
{
    String str = "(ou=*foo*)";
    SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );

    assertEquals( 1, node.getAny().size() );
    assertTrue( node.getAny().contains( "foo" ) );
    assertNull( node.getInitial() );
    assertNull( node.getFinal() );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #10
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubstringOneAny() throws ParseException
{
    String str = "(ou=foo*guy*bar)";
    SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );

    assertEquals( 1, node.getAny().size() );
    assertFalse( node.getAny().contains( "" ) );
    assertTrue( node.getAny().contains( "guy" ) );
    assertEquals( "foo", node.getInitial() );
    assertEquals( "bar", node.getFinal() );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #11
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoByteUTF8Raw() throws ParseException
{
    byte[] bytes =
        { ( byte ) 0xC2, ( byte ) 0xA2 }; // unicode U+00A2: cents sign

    new String( bytes, StandardCharsets.UTF_8 );
    String str = "(cn=\\C2\\A2)";
    SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str );

    assertEquals( "cn", node.getAttribute() );
    String val = node.getValue().getString();
    assertEquals( "a2", Integer.toHexString( val.charAt( 0 ) ) ); // char is U+00A2
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #12
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testQuotedSubstringManyAny() throws ParseException
{
    String str = "(ou=\\5C*\\00*\\3D*\\2Abb)";
    SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );

    assertEquals( 2, node.getAny().size() );
    assertFalse( node.getAny().contains( "" ) );
    assertEquals( "\\", node.getInitial() );
    assertTrue( node.getAny().contains( "\0" ) );
    assertTrue( node.getAny().contains( "=" ) );
    assertEquals( "*bb", node.getFinal() );
    String str2 = node.toString();
    assertEquals( "(ou=\\5C*\\00*=*\\2Abb)", str2 );
}
 
Example #13
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testTwoByteUTF8Escaped() throws ParseException
{
    byte[] bytes =
        { ( byte ) 0xC2, ( byte ) 0xA2 }; // unicode U+00A2: cents sign

    String str = "(cn=\\C2\\A2)";
    new String( bytes, StandardCharsets.UTF_8 );

    SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str );

    assertEquals( "cn", node.getAttribute() );
    String val = node.getValue().getString();
    assertEquals( "a2", Integer.toHexString( val.charAt( 0 ) ) ); // char is U+00A2
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #14
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testRelaxedFilterParse() throws ParseException
{
    String str = " ( cn =*) ";
    ExprNode node = FilterParser.parse( str, false );
    
    assertTrue( node instanceof PresenceNode );
    assertEquals( "cn", ((PresenceNode)node).attribute );
    
    str = " ( & ( cn =*) ) ";
    node = FilterParser.parse( str, false );

    assertTrue( node instanceof AndNode );
    assertEquals( 1, ((AndNode)node).children.size() );
    
    ExprNode child = ((AndNode)node).children.get( 0 );
    assertTrue( child instanceof PresenceNode );
    assertEquals( "cn", ((PresenceNode)child).attribute );
}
 
Example #15
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testThreeByteUTF8Raw() throws ParseException
{
    byte[] bytes =
        { ( byte ) 0xE2, ( byte ) 0x89, ( byte ) 0xA0 }; // unicode U+2260: "not equal to" sign in decimal signed bytes is -30, -119, -96

    new String( bytes, StandardCharsets.UTF_8 );
    String str = "(cn=\\E2\\89\\A0)";
    SimpleNode<?> node = (SimpleNode<?> ) FilterParser.parse( str );

    assertEquals( "cn", node.getAttribute() );
    String val = node.getValue().getString();
    assertEquals( "2260", Integer.toHexString( val.charAt( 0 ) ) );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #16
Source File: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubstringNoIniManyAny() throws ParseException
{
    SubstringNode node = ( SubstringNode ) FilterParser.parse( null, "(ou=*b*c*d*e*f)" );
    // just check that it doesn't throw for now
    node = ( SubstringNode ) node.clone();
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );
    assertEquals( 4, node.getAny().size() );
    assertFalse( node.getAny().contains( "" ) );
    assertTrue( node.getAny().contains( "e" ) );
    assertTrue( node.getAny().contains( "b" ) );
    assertTrue( node.getAny().contains( "c" ) );
    assertTrue( node.getAny().contains( "d" ) );
    assertEquals( null, node.getInitial() );
    assertEquals( "f", node.getFinal() );
}
 
Example #17
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testThreeByteJapaneseUTF8Escaped() throws ParseException
{
    byte[] bytes =
        { ( byte ) 0xE3, ( byte ) 0x81, ( byte ) 0x99 }; // unicode U+3059: Japanese 'T' with squiggle on down-stroke.

    String str = "(cn=\\E3\\81\\99)";
    new String( bytes, StandardCharsets.UTF_8 );

    SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str );
    assertEquals( "cn", node.getAttribute() );
    String val = node.getValue().getString();
    assertEquals( "3059", Integer.toHexString( val.charAt( 0 ) ) );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #18
Source File: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubstringManyAnyNoFinal() throws ParseException
{
    SubstringNode node = ( SubstringNode ) FilterParser.parse( null, "(ou=a*b*c*d*e*)" );
    // just check that it doesn't throw for now
    node = ( SubstringNode ) node.clone();
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );
    assertEquals( 4, node.getAny().size() );
    assertFalse( node.getAny().contains( "" ) );
    assertTrue( node.getAny().contains( "e" ) );
    assertTrue( node.getAny().contains( "b" ) );
    assertTrue( node.getAny().contains( "c" ) );
    assertTrue( node.getAny().contains( "d" ) );
    assertEquals( "a", node.getInitial() );
    assertEquals( null, node.getFinal() );
}
 
Example #19
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testReuseParser() throws ParseException
{
    FilterParser.parse( "(ou~=people)" );
    FilterParser.parse( "(&(ou~=people)(age>=30)) " );
    FilterParser.parse( "(|(ou~=people)(age>=30)) " );
    FilterParser.parse( "(!(&(ou~=people)(age>=30)))" );
    FilterParser.parse( "(ou;lang-de>=\\23\\42asdl fkajsd)" );
    FilterParser.parse( "(ou;lang-de;version-124>=\\23\\42asdl fkajsd)" );
    FilterParser.parse( "(1.3.4.2;lang-de;version-124>=\\23\\42asdl fkajsd)" );
    FilterParser.parse( "(ou=*)" );
    FilterParser.parse( "(1.2.3.4=*)" );
    FilterParser.parse( "(ou=people)" );
    FilterParser.parse( "(ou=people/in/my/company)" );
    FilterParser.parse( "(ou:dn:stupidMatch:=dummyAssertion\\23\\c4\\8d)" );
    FilterParser.parse( "(1.2.3.4:dn:1.3434.23.2:=dummyAssertion\\23\\c4\\8d)" );
    FilterParser.parse( "(ou:stupidMatch:=dummyAssertion\\23\\c4\\8d)" );
    FilterParser.parse( "(ou:=dummyAssertion\\23\\c4\\8d)" );
    FilterParser.parse( "(1.2.3.4:1.3434.23.2:=dummyAssertion\\23\\c4\\8d)" );
    FilterParser.parse( "(:dn:stupidMatch:=dummyAssertion\\23\\c4\\8d)" );
    FilterParser.parse( "(:dn:1.3434.23.2:=dummyAssertion\\23\\c4\\8d)" );
    FilterParser.parse( "(:stupidMatch:=dummyAssertion\\23\\c4\\8d)" );
    FilterParser.parse( "(:1.3434.23.2:=dummyAssertion\\23\\c4\\8d)" );
}
 
Example #20
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testNumericoidOptionsAndEscapesFilter() throws ParseException
{
    String str = "(1.3.4.2;lang-de;version-124>=\\23\\42afdl fkajsd)";
    SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str );
    assertEquals( "1.3.4.2;lang-de;version-124", node.getAttribute() );
    assertEquals( "#Bafdl fkajsd", node.getValue().getString() );
    String str2 = node.toString();
    assertEquals( "(1.3.4.2;lang-de;version-124>=#Bafdl fkajsd)", str2 );
}
 
Example #21
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testOrFilter() throws ParseException
{
    String str = "(|(ou~=people)(age>=30))";
    BranchNode node = ( BranchNode ) FilterParser.parse( str );
    assertEquals( 2, node.getChildren().size() );
    assertTrue( node instanceof OrNode );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #22
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionAndEscapesFilter() throws ParseException
{
    String str = "(ou;lang-de>=\\23\\42asdl fkajsd)"; // \23 = '#'
    SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str );
    assertEquals( "ou;lang-de", node.getAttribute() );
    assertEquals( "#Basdl fkajsd", node.getValue().getString() );
    String str2 = node.toString();
    assertEquals( "(ou;lang-de>=#Basdl fkajsd)", str2 );
}
 
Example #23
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testNotFilter() throws ParseException
{
    String str = "(!(&(ou~= people)(age>=30)))";
    BranchNode node = ( BranchNode ) FilterParser.parse( str );
    assertEquals( 1, node.getChildren().size() );
    assertTrue( node instanceof NotNode );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #24
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testObjectClassAndFilterWithSpaces() throws ParseException
{
    String str = "(&(objectClass=person)(objectClass=organizationalUnit))";
    BranchNode node = ( BranchNode ) FilterParser.parse( str );
    assertEquals( 2, node.getChildren().size() );
    assertTrue( node instanceof AndNode );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #25
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testOptionsAndEscapesFilter() throws ParseException
{
    String str = "(ou;lang-de;version-124>=\\23\\42asdl fkajsd)";
    SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str );
    assertEquals( "ou;lang-de;version-124", node.getAttribute() );
    assertEquals( "#Basdl fkajsd", node.getValue().getString() );
    String str2 = node.toString();
    assertEquals( "(ou;lang-de;version-124>=#Basdl fkajsd)", str2 );
}
 
Example #26
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualsFilter() throws ParseException
{
    String str = "(ou=people)";
    SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertEquals( "people", node.getEscapedValue() );
    assertTrue( node instanceof EqualityNode );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #27
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testBadEqualsFilter()
{
    try
    {
        FilterParser.parse( "ou=people" );

        // The parsing should fail
        fail( "should fail with bad filter" );
    }
    catch ( ParseException pe )
    {
        assertTrue( true );
    }
}
 
Example #28
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAndFilterOneChildOnly() throws ParseException
{
    String str = "(&(ou~=people))";
    BranchNode node = ( BranchNode ) FilterParser.parse( str );
    assertEquals( 1, node.getChildren().size() );
    assertTrue( node instanceof AndNode );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example #29
Source File: LdapUrl.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Parse the filter part. We will use the FilterParserImpl class
 *
 * @param chars The char array to be checked
 * @param pos the starting position
 * @return -1 if the char array does not contains a filter
 */
private int parseFilter( char[] chars, int pos )
{

    int end = pos;

    for ( int i = pos; ( i < chars.length ) && ( chars[i] != '?' ); i++ )
    {
        end++;
    }

    if ( end == pos )
    {
        // We have no filter
        return end;
    }

    try
    {
        filter = decode( new String( chars, pos, end - pos ) );
        FilterParser.parse( filter );
    }
    catch ( LdapUriException | ParseException e )
    {
        return -1;
    }

    return end;
}
 
Example #30
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testNumericoidPresentFilter() throws ParseException
{
    String str = "(1.2.3.4=*)";
    PresenceNode node = ( PresenceNode ) FilterParser.parse( str );
    assertEquals( "1.2.3.4", node.getAttribute() );
    assertTrue( node instanceof PresenceNode );
    String str2 = node.toString();
    assertEquals( str, str2 );
}