Java Code Examples for org.apache.directory.api.ldap.model.filter.FilterParser#parse()

The following examples show how to use org.apache.directory.api.ldap.model.filter.FilterParser#parse() . 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: 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 2
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 3
Source File: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubstringManyAny() throws ParseException
{
    SubstringNode node = ( SubstringNode ) FilterParser.parse( null, "(ou=a*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( "b" ) );
    assertTrue( node.getAny().contains( "c" ) );
    assertTrue( node.getAny().contains( "d" ) );
    assertTrue( node.getAny().contains( "e" ) );
    assertEquals( "a", node.getInitial() );
    assertEquals( "f", node.getFinal() );
}
 
Example 4
Source File: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualsFilterNullValue() throws ParseException
{
    SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( null, "(ou=)" );
    // just check that it doesn't throw for now
    node = ( SimpleNode<?> ) node.clone();

    assertEquals( "ou", node.getAttribute() );
    assertEquals( "", node.getValue().getString() );
    assertTrue( node instanceof EqualityNode );
}
 
Example 5
Source File: ProtectedItem_ClassesTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize name instances
 */
@BeforeEach
public void initNames() throws Exception
{
    ExprNode filterA = FilterParser.parse( "(&(cn=test)(sn=test))" );
    ExprNode filterB = FilterParser.parse( "(&(cn=test)(sn=test))" );
    ExprNode filterC = FilterParser.parse( "(&(cn=sample)(sn=sample))" );
    classesA = new ClassesItem( filterA );
    classesACopy = new ClassesItem( filterA );
    classesB = new ClassesItem( filterB );
    classesC = new ClassesItem( filterC );
}
 
Example 6
Source File: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtensibleFilterForm1NoDnAttr() throws ParseException
{
    ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( null, "(ou:stupidMatch:=dummyAssertion\\23\\2A)" );
    // just check that it doesn't throw for now
    node = ( ExtensibleNode ) node.clone();
    assertEquals( "ou", node.getAttribute() );
    assertEquals( "dummyAssertion#*", node.getValue().getString() );
    assertEquals( "stupidMatch", node.getMatchingRuleId() );
    assertFalse( node.hasDnAttributes() );
    assertTrue( node instanceof ExtensibleNode );
}
 
Example 7
Source File: ProtectedItem_RangeOfValuesTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize name instances
 */
@BeforeEach
public void initNames() throws Exception
{

    ExprNode filterA = FilterParser.parse( "(&(cn=test)(sn=test))" );
    ExprNode filterB = FilterParser.parse( "(&(cn=test)(sn=test))" );
    ExprNode filterC = FilterParser.parse( "(&(cn=sample)(sn=sample))" );

    rangeOfValuesA = new RangeOfValuesItem( filterA );
    rangeOfValuesACopy = new RangeOfValuesItem( filterA );
    rangeOfValuesB = new RangeOfValuesItem( filterB );
    rangeOfValuesC = new RangeOfValuesItem( filterC );
}
 
Example 8
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testPresentFilter() throws ParseException
{
    String str = "(ou=*)";
    PresenceNode node = ( PresenceNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof PresenceNode );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example 9
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testQuotedChars() throws ParseException
{
    String str = "(cn='~%\\28'$'\\5C)"; // note \28='(' and \5c='\'
    ExprNode node = FilterParser.parse( str );
    assertTrue( node instanceof EqualityNode );
    assertEquals( "'~%('$'\\", ( ( EqualityNode<?> ) node ).getValue().getString() );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example 10
Source File: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testNumericoidPresentFilter() throws ParseException
{
    PresenceNode node = ( PresenceNode ) FilterParser.parse( null, "(1.2.3.4=*)" );
    // just check that it doesn't throw for now
    node = ( PresenceNode ) node.clone();
    assertEquals( "1.2.3.4", node.getAttribute() );
    assertTrue( node instanceof PresenceNode );
}
 
Example 11
Source File: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testPresentFilter() throws ParseException
{
    PresenceNode node = ( PresenceNode ) FilterParser.parse( null, "(ou=*)" );
    // just check that it doesn't throw for now
    node = ( PresenceNode ) node.clone();
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof PresenceNode );
}
 
Example 12
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 13
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtensibleFilterForm1NoAttrNoMatchingRule() throws ParseException
{
    String str = "(ou:=dummyAssertion\\23\\c4\\8d)";
    ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertEquals( "dummyAssertion#\u010D", node.getValue().getString() );
    assertEquals( null, node.getMatchingRuleId() );
    assertFalse( node.hasDnAttributes() );
    assertTrue( node instanceof ExtensibleNode );
}
 
Example 14
Source File: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtensibleFilterForm2NoDnAttrWithNumericOidNoAttr() throws ParseException
{
    ExtensibleNode node = ( ExtensibleNode ) FilterParser.parse( null, "(:1.3434.23.2:=dummyAssertion\\23\\2A)" );
    // just check that it doesn't throw for now
    node = ( ExtensibleNode ) node.clone();
    assertEquals( null, node.getAttribute() );
    assertEquals( "dummyAssertion#*", node.getValue().getString() );
    assertEquals( "1.3434.23.2", node.getMatchingRuleId() );
    assertFalse( node.hasDnAttributes() );
    assertTrue( node instanceof ExtensibleNode );
}
 
Example 15
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubstringNoAny() throws ParseException
{
    String str = "(ou=foo*bar)";
    SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );

    assertEquals( 0, node.getAny().size() );
    assertFalse( node.getAny().contains( "" ) );
    assertEquals( "foo", node.getInitial() );
    assertEquals( "bar", node.getFinal() );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example 16
Source File: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAndFilterOneChildOnly() throws ParseException
{
    BranchNode node = ( BranchNode ) FilterParser.parse( null, "(&(ou~=people))" );
    // just check that it doesn't throw for now
    node = ( BranchNode ) node.clone();
    assertEquals( 1, node.getChildren().size() );
    assertTrue( node instanceof AndNode );
}
 
Example 17
Source File: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAndFilter() throws ParseException
{
    BranchNode node = ( BranchNode ) FilterParser.parse( null, "(&(ou~=people)(age>=30))" );
    // just check that it doesn't throw for now
    node = ( BranchNode ) node.clone();
    assertEquals( 2, node.getChildren().size() );
    assertTrue( node instanceof AndNode );
}
 
Example 18
Source File: FilterCloneTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testItemFilter() throws ParseException
{
    SimpleNode<?> node = ( SimpleNode<?> ) FilterParser.parse( null, "(ou~=people)" );
    // just check that it doesn't throw for now
    node = ( SimpleNode<?> ) node.clone();
    assertEquals( "ou", node.getAttribute() );
    assertEquals( "people", node.getValue().getString() );
    assertTrue( node instanceof ApproximateNode );
}
 
Example 19
Source File: FilterParserTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubstringNoAnyNoIni() throws ParseException
{
    String str = "(ou=*bar)";
    SubstringNode node = ( SubstringNode ) FilterParser.parse( str );
    assertEquals( "ou", node.getAttribute() );
    assertTrue( node instanceof SubstringNode );

    assertEquals( 0, node.getAny().size() );
    assertFalse( node.getAny().contains( "" ) );
    assertEquals( null, node.getInitial() );
    assertEquals( "bar", node.getFinal() );
    String str2 = node.toString();
    assertEquals( str, str2 );
}
 
Example 20
Source File: BranchNormalizedVisitorTest.java    From directory-ldap-api with Apache License 2.0 3 votes vote down vote up
public void testBranchNormalizedVisitor4() throws Exception
{
    ExprNode ori = FilterParser.parse( "(&(!(sn=Bob))(ou=Human Resources)(uid=akarasulu))" );

    ExprNode altered = FilterParser.parse( "(&(ou=Human Resources)(uid=akarasulu)(!(sn=Bob)))" );

    BranchNormalizedVisitor visitor = new BranchNormalizedVisitor();

    visitor.visit( altered );

    assertTrue( ori.toString().equals( altered.toString() ) );

}