diff options
author | Ade Lee <alee@redhat.com> | 2012-01-09 23:32:31 -0500 |
---|---|---|
committer | Ade Lee <alee@redhat.com> | 2012-01-09 23:32:31 -0500 |
commit | 466533710c179f62865e08b3031748072a0247a3 (patch) | |
tree | 4c04c20d50239be26ba8319076de90226526a542 /pki/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java | |
parent | c9e3c48de53fce6908f625f40ac2b2f75d66b5a1 (diff) | |
download | pki-466533710c179f62865e08b3031748072a0247a3.tar.gz pki-466533710c179f62865e08b3031748072a0247a3.tar.xz pki-466533710c179f62865e08b3031748072a0247a3.zip |
Formatting (no wrap)
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java')
-rw-r--r-- | pki/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java | 159 |
1 files changed, 59 insertions, 100 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java b/pki/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java index 3ac8f750..8c6be490 100644 --- a/pki/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java +++ b/pki/base/common/src/com/netscape/cmscore/ldap/LdapPredicateParser.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.ldap; - import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; @@ -29,19 +28,16 @@ import com.netscape.certsrv.ldap.ELdapException; import com.netscape.certsrv.publish.ILdapExpression; import com.netscape.cmscore.util.Debug; - /** * Default implementation of predicate parser. - * + * * Limitations: - * - * 1. Currently parentheses are not suported. - * 2. Only ==, != <, >, <= and >= operators are supported. - * 3. The only boolean operators supported are AND and OR. AND takes precedence - * over OR. Example: a AND b OR e OR c AND d - * is treated as (a AND b) OR e OR (c AND d) - * 4. If this is n't adequate, roll your own. - * + * + * 1. Currently parentheses are not suported. 2. Only ==, != <, >, <= and >= + * operators are supported. 3. The only boolean operators supported are AND and + * OR. AND takes precedence over OR. Example: a AND b OR e OR c AND d is treated + * as (a AND b) OR e OR (c AND d) 4. If this is n't adequate, roll your own. + * * @author mzhao * @version $Revision$, $Date$ */ @@ -57,22 +53,23 @@ public class LdapPredicateParser { /** * Parse the predicate expression and return a vector of expressions. - * - * @param predicateExp The predicate expression as read from the config file. - * @return expVector The vector of expressions. + * + * @param predicateExp The predicate expression as read from the config + * file. + * @return expVector The vector of expressions. */ public static ILdapExpression parse(String predicateExpression) - throws ELdapException { - if (predicateExpression == null || - predicateExpression.length() == 0) + throws ELdapException { + if (predicateExpression == null || + predicateExpression.length() == 0) return null; PredicateTokenizer pt = new PredicateTokenizer(predicateExpression); if (pt == null || !pt.hasMoreTokens()) return null; - // The first token cannot be an operator. We are not dealing with - // reverse-polish notation. + // The first token cannot be an operator. We are not dealing with + // reverse-polish notation. String token = pt.nextToken(); boolean opANDSeen; boolean opORSeen; @@ -92,7 +89,7 @@ public class LdapPredicateParser { int curType = getOP(token); if ((prevType != EXPRESSION && curType != EXPRESSION) || - (prevType == EXPRESSION && curType == EXPRESSION)) { + (prevType == EXPRESSION && curType == EXPRESSION)) { malformed = true; break; } @@ -103,7 +100,8 @@ public class LdapPredicateParser { continue; } - // If the previous type was an OR token, add the current expression to + // If the previous type was an OR token, add the current expression + // to // the expression set; if (prevType == OP_OR) { expSet.addElement(current); @@ -122,8 +120,8 @@ public class LdapPredicateParser { if (Debug.ON) Debug.trace("Malformed expression: " + predicateExpression); throw new ELdapException( - CMS.getUserMessage("CMS_LDAP_BAD_LDAP_EXPRESSION", - predicateExpression)); + CMS.getUserMessage("CMS_LDAP_BAD_LDAP_EXPRESSION", + predicateExpression)); } // Form an LdapOrExpression @@ -135,7 +133,7 @@ public class LdapPredicateParser { if (size == 0) return null; LdapOrExpression orExp = new - LdapOrExpression((ILdapExpression) expSet.elementAt(0), null); + LdapOrExpression((ILdapExpression) expSet.elementAt(0), null); for (int i = 1; i < size; i++) orExp = new LdapOrExpression(orExp, @@ -153,7 +151,7 @@ public class LdapPredicateParser { } private static ILdapExpression parseExpression(String input) - throws ELdapException { + throws ELdapException { // If the expression has multiple parts separated by commas // we need to construct an AND expression. Else we will return a // simple expression. @@ -166,8 +164,8 @@ public class LdapPredicateParser { while (commaIndex > 0) { LdapSimpleExpression exp = (LdapSimpleExpression) - LdapSimpleExpression.parse(input.substring(currentIndex, - commaIndex)); + LdapSimpleExpression.parse(input.substring(currentIndex, + commaIndex)); expVector.addElement(exp); currentIndex = commaIndex + 1; @@ -175,7 +173,7 @@ public class LdapPredicateParser { } if (currentIndex < (input.length() - 1)) { LdapSimpleExpression exp = (LdapSimpleExpression) - LdapSimpleExpression.parse(input.substring(currentIndex)); + LdapSimpleExpression.parse(input.substring(currentIndex)); expVector.addElement(exp); } @@ -194,79 +192,40 @@ public class LdapPredicateParser { public static void main(String[] args) { /** - AttributeSet req = new AttributeSet(); - try - { - req.set("ou", "people"); - req.set("cn", "John Doe"); - req.set("uid", "jdoes"); - req.set("o", "airius.com"); - req.set("certtype", "client"); - req.set("request", "issuance"); - req.set("id", new Integer(10)); - req.set("dualcerts", new Boolean(true)); - - Vector v = new Vector(); - v.addElement("one"); - v.addElement("two"); - v.addElement("three"); - req.set("count", v); - } - catch (Exception e){e.printStackTrace();} - String[] array = { "ou == people AND certtype == client", - "ou == servergroup AND certtype == server", - "uid == jdoes, ou==people, o==airius.com OR ou == people AND certType == client OR certType == server AND cn == needles.mcom.com", - }; - for (int i = 0; i < array.length; i++) - { - System.out.println(); - System.out.println("String: " + array[i]); - ILdapExpression exp = null; - try - { - exp = parse(array[i]); - if (exp != null) - { - System.out.println("Parsed Expression: " + exp); - boolean result = exp.evaluate(req); - System.out.println("Result: " + result); - } - } - catch (Exception e) {e.printStackTrace(); } - } - - - try - { - BufferedReader rdr = new BufferedReader( - new FileReader(args[0])); - String line; - while((line=rdr.readLine()) != null) - { - System.out.println(); - System.out.println("Line Read: " + line); - ILdapExpression exp = null; - try - { - exp = parse(line); - if (exp != null) - { - System.out.println(exp); - boolean result = exp.evaluate(req); - System.out.println("Result: " + result); - } - - }catch (Exception e){e.printStackTrace();} - } - } - catch (Exception e){e.printStackTrace(); } - + * AttributeSet req = new AttributeSet(); try { req.set("ou", "people"); + * req.set("cn", "John Doe"); req.set("uid", "jdoes"); req.set("o", + * "airius.com"); req.set("certtype", "client"); req.set("request", + * "issuance"); req.set("id", new Integer(10)); req.set("dualcerts", new + * Boolean(true)); + * + * Vector v = new Vector(); v.addElement("one"); v.addElement("two"); + * v.addElement("three"); req.set("count", v); } catch (Exception + * e){e.printStackTrace();} String[] array = { + * "ou == people AND certtype == client", + * "ou == servergroup AND certtype == server", + * "uid == jdoes, ou==people, o==airius.com OR ou == people AND certType == client OR certType == server AND cn == needles.mcom.com" + * , }; for (int i = 0; i < array.length; i++) { System.out.println(); + * System.out.println("String: " + array[i]); ILdapExpression exp = + * null; try { exp = parse(array[i]); if (exp != null) { + * System.out.println("Parsed Expression: " + exp); boolean result = + * exp.evaluate(req); System.out.println("Result: " + result); } } catch + * (Exception e) {e.printStackTrace(); } } + * + * + * try { BufferedReader rdr = new BufferedReader( new + * FileReader(args[0])); String line; while((line=rdr.readLine()) != + * null) { System.out.println(); System.out.println("Line Read: " + + * line); ILdapExpression exp = null; try { exp = parse(line); if (exp + * != null) { System.out.println(exp); boolean result = + * exp.evaluate(req); System.out.println("Result: " + result); } + * + * }catch (Exception e){e.printStackTrace();} } } catch (Exception + * e){e.printStackTrace(); } **/ } } - class PredicateTokenizer { String input; int currentIndex; @@ -348,30 +307,30 @@ class PredicateTokenizer { } } - class AttributeSet implements IAttrSet { /** * */ private static final long serialVersionUID = -3155846653754028803L; Hashtable ht = new Hashtable(); + public AttributeSet() { } public void delete(String name) - throws EBaseException { + throws EBaseException { Object ob = ht.get(name); ht.remove(ob); } public Object get(String name) - throws EBaseException { + throws EBaseException { return ht.get(name); } public void set(String name, Object ob) - throws EBaseException { + throws EBaseException { ht.put(name, ob); } |