Class LDAPFilter

java.lang.Object
com.isode.dsapi.util.LDAPFilter

public class LDAPFilter extends Object
LDAP Filter validation, querying and conversion to other formats; see RFC4515. Accepts 'extensible' matching rules now. Validates attribute value wildcards and escapes. Doesn't validate attribute type or OID syntax or options. Doesn't validate attribute values against attribute type.

In non-strict mode, accepts whitespace in some places when parsing, but when the filter is rewritten with toString(), these will be stripped out. Also removes redundancy from the filter -- if there is an AND or OR operation with a list of just one item, it is substituted with that one item.

A plain-language version of the filter can be fetched with toPlainLangString(). This has less parentheses and uses 'and', 'or' and 'not' between the expressions.

Author:
jp
  • Field Details

    • operations

      public static final String[] operations
    • filter

      public LDAPFilter.Expression filter
      The LDAP filter top-level Expression
  • Constructor Details

    • LDAPFilter

      public LDAPFilter(String filter_str) throws ParseException
      Construct an LDAPFilter instance from an LDAP filter string, using strict parsing.
      Parameters:
      filter_str - String to parse
      Throws:
      ParseException
    • LDAPFilter

      public LDAPFilter(String filter_str, boolean strict) throws ParseException
      Construct an LDAPFilter instance from an LDAP filter string. Excess white space is accepted but stripped out if 'strict' is false.
      Parameters:
      filter_str - String to parse
      strict - 'true' to be strict, and complain about spaces where they're not allowed. 'false' to be flexible and to allow certain errors, and to clean them up when toString() is called.
      Throws:
      ParseException
  • Method Details

    • toPlainLangString

      public String toPlainLangString()
      Output the filter in plain-language format (i.e. as it might be read in English)
    • toPlainLangString

      public String toPlainLangString(boolean mark)
      Output the filter in plain-language format (i.e. as it might be read in English), optionally marking some parts as bold. Bold is used for the matching expressions, and normal for everything else.
      Parameters:
      mark - Mark text as bold or normal, using NUL () to separate bold and normal parts. Text starts out in normal.
    • toString

      public String toString()
      Reconstruct the filter into an LDAP string, with no excess white space.
      Overrides:
      toString in class Object
    • evaluate

      public LDAPFilter.TriBool evaluate(Entry entry)
      Evaluate the filter expression on the given Entry. There are a number of limitations, which might be removed later on:
      • Extensible matching is not supported
      • Approximate matching is treated the same as an exact match
      • Only the exact attributes mentioned will be tested: subtypes are not currently searched for.
      • Only string values can be compared, not binary or BER values.
      • Case-insensitive substring matching is supported in a slightly backwards way: if the lowercased version of the value compares the same as the uppercased version through DSAPI's comparison code, then it is assumed that it is okay to do a case-insensitive match in Java. The code make no attempt to handle any other folding that might be done by the syntax.

      See X.511 section 7.8.1 onwards for evaluation rules.

    • evaluate

      public LDAPFilter.TriBool evaluate(MapEntry entry)
      Evaluate the filter expression on the given MapEntry. There are a number of limitations, which might be removed later on:
      • Extensible matching is not supported
      • Approximate matching is treated the same as an exact match
      • Only the exact attributes mentioned will be tested: subtypes are not currently searched for.
      • Only string values can be compared, not binary or BER values.
      • Case-insensitive substring matching is supported in a slightly backwards way: if the lowercased version of the value compares the same as the uppercased version through DSAPI's comparison code, then it is assumed that it is okay to do a case-insensitive match in Java. The code make no attempt to handle any other folding that might be done by the syntax.

      See X.511 section 7.8.1 onwards for evaluation rules.