summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
diff options
context:
space:
mode:
authorAde Lee <alee@redhat.com>2012-01-11 13:58:57 -0500
committerAde Lee <alee@redhat.com>2012-01-11 13:58:57 -0500
commitfbbf6c77236902e726faafe380a5ddf1891e8dc9 (patch)
tree1e671265cbd3d4072838eeec51b6a2ec77bed7d1 /pki/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
parentf7a1d6a79d1b0367e556d5c53fe5e0c07c7b5c66 (diff)
downloadpki-fbbf6c77236902e726faafe380a5ddf1891e8dc9.tar.gz
pki-fbbf6c77236902e726faafe380a5ddf1891e8dc9.tar.xz
pki-fbbf6c77236902e726faafe380a5ddf1891e8dc9.zip
Formatting - no wrap in comments and code
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java')
-rw-r--r--pki/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java192
1 files changed, 94 insertions, 98 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java b/pki/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
index 0f00e815..af69e6a8 100644
--- a/pki/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
+++ b/pki/base/common/src/com/netscape/cmscore/policy/PolicyPredicateParser.java
@@ -17,7 +17,6 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.policy;
-
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
@@ -29,19 +28,18 @@ import com.netscape.certsrv.policy.EPolicyException;
import com.netscape.certsrv.policy.IExpression;
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 kanda
* @version $Revision$, $Date$
*/
@@ -57,22 +55,22 @@ public class PolicyPredicateParser {
/**
* 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 IExpression parse(String predicateExpression)
- throws EPolicyException {
- if (predicateExpression == null ||
- predicateExpression.length() == 0)
+ throws EPolicyException {
+ 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 +90,7 @@ public class PolicyPredicateParser {
int curType = getOP(token);
if ((prevType != EXPRESSION && curType != EXPRESSION) ||
- (prevType == EXPRESSION && curType == EXPRESSION)) {
+ (prevType == EXPRESSION && curType == EXPRESSION)) {
malformed = true;
break;
}
@@ -123,7 +121,7 @@ public class PolicyPredicateParser {
Debug.trace("Malformed expression: " + predicateExpression);
throw new EPolicyException(
CMS.getUserMessage("CMS_POLICY_BAD_POLICY_EXPRESSION",
- predicateExpression));
+ predicateExpression));
}
// Form an ORExpression
@@ -135,7 +133,7 @@ public class PolicyPredicateParser {
if (size == 0)
return null;
OrExpression orExp = new
- OrExpression((IExpression) expSet.elementAt(0), null);
+ OrExpression((IExpression) expSet.elementAt(0), null);
for (int i = 1; i < size; i++)
orExp = new OrExpression(orExp,
@@ -153,7 +151,7 @@ public class PolicyPredicateParser {
}
private static IExpression parseExpression(String input)
- throws EPolicyException {
+ throws EPolicyException {
// 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 PolicyPredicateParser {
while (commaIndex > 0) {
SimpleExpression exp = (SimpleExpression)
- SimpleExpression.parse(input.substring(currentIndex,
- commaIndex));
+ SimpleExpression.parse(input.substring(currentIndex,
+ commaIndex));
expVector.addElement(exp);
currentIndex = commaIndex + 1;
@@ -175,7 +173,7 @@ public class PolicyPredicateParser {
}
if (currentIndex < (input.length() - 1)) {
SimpleExpression exp = (SimpleExpression)
- SimpleExpression.parse(input.substring(currentIndex));
+ SimpleExpression.parse(input.substring(currentIndex));
expVector.addElement(exp);
}
@@ -194,79 +192,77 @@ public class PolicyPredicateParser {
public static void main(String[] args) {
/*********
- IRequest req = new IRequest();
- 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]);
- IExpression 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);
- IExpression 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(); }
-
+ * IRequest req = new IRequest();
+ * 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]);
+ * IExpression 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);
+ * IExpression 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 +344,30 @@ class PredicateTokenizer {
}
}
-
class AttributeSet implements IAttrSet {
/**
*
*/
private static final long serialVersionUID = -3985810281989018413L;
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);
}