Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/cond
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21866/com/sun/xacml/cond
Modified Files:
Apply.java Evaluatable.java Expression.java
ExpressionHandler.java Function.java FunctionBase.java
HigherOrderFunction.java MapFunction.java NOfFunction.java
VariableDefinition.java VariableManager.java
VariableReference.java
Added Files:
Condition.java
Log Message:
substantial update to align 2.0 features (Target and Condition) and code
re-factoring to better handle Expression/Evaluatable, versions, Target, etc.
Index: NOfFunction.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/cond/NOfFunction.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** NOfFunction.java 18 Mar 2004 21:13:09 -0000 1.4
--- NOfFunction.java 5 Dec 2005 23:34:51 -0000 1.5
***************
*** 3,7 ****
* @(#)NOfFunction.java
*
! * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 3,7 ----
* @(#)NOfFunction.java
*
! * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
***************
*** 177,181 ****
Object [] list = inputs.toArray();
for (int i = 0; i < list.length; i++)
! if (((Evaluatable)(list[i])).evaluatesToBag())
throw new IllegalArgumentException("n-of can't use bags");
--- 177,181 ----
Object [] list = inputs.toArray();
for (int i = 0; i < list.length; i++)
! if (((Evaluatable)(list[i])).returnsBag())
throw new IllegalArgumentException("n-of can't use bags");
Index: Evaluatable.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/cond/Evaluatable.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Evaluatable.java 7 Jan 2005 23:49:32 -0000 1.5
--- Evaluatable.java 5 Dec 2005 23:34:51 -0000 1.6
***************
*** 3,7 ****
* @(#)Evaluatable.java
*
! * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 3,7 ----
* @(#)Evaluatable.java
*
! * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
***************
*** 50,57 ****
/**
! * Generic interface that is implemented by all objects that can appear in
! * an ApplyType. This lets the evaluation code of <code>Apply</code> and
! * functions iterate through their members and evaluate them, working only
! * on the returned values or errors.
*
* @since 1.0
--- 50,57 ----
/**
! * Generic interface that is implemented by all objects that can be evaluated
! * directly (<code>AttributeDesignator</code>, <code>Apply</code>,
! * <code>AttributeValue</code>, etc.). As of version 2.0 several methods
! * were extracted to the new <code>Expression</code> super-interface.
*
* @since 1.0
***************
*** 72,86 ****
/**
- * Get the type of this object. This may be the data type of an
- * <code>Attribute</code> or the return type of an
- * <code>AttributeDesignator</code>, etc.
- *
- * @return the type of data represented by this object
- */
- public URI getType();
-
- /**
* Tells whether evaluation will return a bag or a single value.
*
* @return true if evaluation will return a bag, false otherwise
*/
--- 72,80 ----
/**
* Tells whether evaluation will return a bag or a single value.
*
+ * @deprecated As of 2.0, you should use the <code>returnsBag</code>
+ * method from the super-interface <code>Expression</code>.
+ *
* @return true if evaluation will return a bag, false otherwise
*/
***************
*** 96,117 ****
public List getChildren();
- /**
- * Encodes this <code>Evaluatable</code> into its XML representation and
- * writes this encoding to the given <code>OutputStream</code> with no
- * indentation.
- *
- * @param output a stream into which the XML-encoded data is written
- */
- public void encode(OutputStream output);
-
- /**
- * Encodes this <code>Evaluatable</code> into its XML representation and
- * writes this encoding to the given <code>OutputStream</code> with
- * indentation.
- *
- * @param output a stream into which the XML-encoded data is written
- * @param indenter an object that creates indentation strings
- */
- public void encode(OutputStream output, Indenter indenter);
-
}
--- 90,92 ----
Index: HigherOrderFunction.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/cond/HigherOrderFunction.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** HigherOrderFunction.java 7 Jan 2005 23:49:32 -0000 1.9
--- HigherOrderFunction.java 5 Dec 2005 23:34:51 -0000 1.10
***************
*** 3,7 ****
* @(#)HigherOrderFunction.java
*
! * Copyright 2003-20045Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
--- 3,7 ----
* @(#)HigherOrderFunction.java
*
! * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
***************
*** 38,41 ****
--- 38,42 ----
import com.sun.xacml.EvaluationCtx;
+ import com.sun.xacml.Indenter;
import com.sun.xacml.attr.AttributeValue;
***************
*** 43,46 ****
--- 44,50 ----
import com.sun.xacml.attr.BooleanAttribute;
+ import java.io.OutputStream;
+ import java.io.PrintStream;
+
import java.net.URI;
import java.net.URISyntaxException;
***************
*** 180,192 ****
/**
- * Returns false since functions aren't directly evaluatable.
- *
- * @return false
- */
- public boolean isEvaluatable() {
- return false;
- }
-
- /**
* Returns a <code>Set</code> containing all the function identifiers
* supported by this class.
--- 184,187 ----
***************
*** 265,278 ****
}
! // get the two inputs ... note that unlike other functions, we don't
! // have to evaluate here, since the Apply code did it for us already
! // to handle any Indeterminate cases
AttributeValue [] args = new AttributeValue[2];
- args[0] = (AttributeValue)(iterator.next());
- args[1] = (AttributeValue)(iterator.next());
! // now we're ready to do the evaluation
! EvaluationResult result = null;
switch(functionId) {
--- 260,281 ----
}
! // get the two inputs, and if anything is INDETERMINATE, then we
! // stop right away
AttributeValue [] args = new AttributeValue[2];
! Evaluatable eval = (Evaluatable)(iterator.next());
! EvaluationResult result = eval.evaluate(context);
! if (result.indeterminate())
! return result;
! args[0] = (AttributeValue)(result.getAttributeValue());
! eval = (Evaluatable)(iterator.next());
! result = eval.evaluate(context);
! if (result.indeterminate())
! return result;
! args[1] = (AttributeValue)(result.getAttributeValue());
!
! // now we're ready to do the evaluation
! result = null;
switch(functionId) {
***************
*** 433,441 ****
// the first arg might be a bag
! if (secondIsBag && (! eval1.evaluatesToBag()))
throw new IllegalArgumentException("first arg has to be a bag");
// the second arg must be a bag
! if (! eval2.evaluatesToBag())
throw new IllegalArgumentException("second arg has to be a bag");
--- 436,444 ----
// the first arg might be a bag
! if (secondIsBag && (! eval1.returnsBag()))
throw new IllegalArgumentException("first arg has to be a bag");
// the second arg must be a bag
! if (! eval2.returnsBag())
throw new IllegalArgumentException("second arg has to be a bag");
***************
*** 564,566 ****
--- 567,594 ----
}
+ /**
+ * Encodes this <code>HigherOrderFunction</code> into its XML
+ * representation and writes this encoding to the given
+ * <code>OutputStream</code> with no indentation.
+ *
+ * @param output a stream into which the XML-encoded data is written
+ */
+ public void encode(OutputStream output) {
+ encode(output, new Indenter(0));
+ }
+
+ /**
+ * Encodes this <code>HigherOrderFunction</code> into its XML
+ * representation and writes this encoding to the given
+ * <code>OutputStream</code> with indentation.
+ *
+ * @param output a stream into which the XML-encoded data is written
+ * @param indenter an object that creates indentation strings
+ */
+ public void encode(OutputStream output, Indenter indenter) {
+ PrintStream out = new PrintStream(output);
+ out.println(indenter.makeString() + "<Function FunctionId=\"" +
+ getIdentifier().toString() + "\"/>");
+ }
+
}
Index: FunctionBase.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/cond/FunctionBase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** FunctionBase.java 7 Jan 2005 23:49:32 -0000 1.4
--- FunctionBase.java 5 Dec 2005 23:34:51 -0000 1.5
***************
*** 38,41 ****
--- 38,42 ----
import com.sun.xacml.EvaluationCtx;
+ import com.sun.xacml.Indenter;
import com.sun.xacml.attr.AttributeValue;
***************
*** 46,49 ****
--- 47,53 ----
import java.net.URISyntaxException;
+ import java.io.OutputStream;
+ import java.io.PrintStream;
+
import java.util.ArrayList;
import java.util.Arrays;
***************
*** 223,235 ****
/**
- * Returns false since functions aren't directly evaluatable.
- *
- * @return false
- */
- public boolean isEvaluatable() {
- return false;
- }
-
- /**
* Returns the full identifier of this function, as known by the factories.
*
--- 227,230 ----
***************
*** 401,405 ****
if ((! eval.getType().toString().equals(paramType)) ||
! (eval.evaluatesToBag() != paramIsBag))
throw new IllegalArgumentException("illegal parameter");
}
--- 396,400 ----
if ((! eval.getType().toString().equals(paramType)) ||
! (eval.returnsBag() != paramIsBag))
throw new IllegalArgumentException("illegal parameter");
}
***************
*** 417,421 ****
if ((! eval.getType().toString().equals(paramTypes[i])) ||
! (eval.evaluatesToBag() != paramsAreBags[i]))
throw new IllegalArgumentException("illegal parameter");
--- 412,416 ----
if ((! eval.getType().toString().equals(paramTypes[i])) ||
! (eval.returnsBag() != paramsAreBags[i]))
throw new IllegalArgumentException("illegal parameter");
***************
*** 483,485 ****
--- 478,505 ----
}
+ /**
+ * Encodes this <code>FunctionBase</code> into its XML representation and
+ * writes this encoding to the given <code>OutputStream</code> with no
+ * indentation.
+ *
+ * @param output a stream into which the XML-encoded data is written
+ */
+ public void encode(OutputStream output) {
+ encode(output, new Indenter(0));
+ }
+
+ /**
+ * Encodes this <code>FunctionBase</code> into its XML representation and
+ * writes this encoding to the given <code>OutputStream</code> with
+ * indentation.
+ *
+ * @param output a stream into which the XML-encoded data is written
+ * @param indenter an object that creates indentation strings
+ */
+ public void encode(OutputStream output, Indenter indenter) {
+ PrintStream out = new PrintStream(output);
+ out.println(indenter.makeString() + "<Function FunctionId=\"" +
+ getFunctionName() + "\"/>");
+ }
+
}
Index: Expression.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/cond/Expression.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** Expression.java 7 Jan 2005 23:49:32 -0000 1.1
--- Expression.java 5 Dec 2005 23:34:51 -0000 1.2
***************
*** 37,42 ****
--- 37,46 ----
package com.sun.xacml.cond;
+ import com.sun.xacml.Indenter;
+
import java.net.URI;
+ import java.io.OutputStream;
+
/**
***************
*** 48,67 ****
public interface Expression
{
!
/**
! * Returns true if this expression is evaluatable. Typically, this
! * is any expression type except for functions, which can't be
! * evaluated directly.
*
! * @return true if this expression is evaluatable
*/
! public boolean isEvaluatable();
/**
! * Returns the type of the expression.
*
! * @return the attribute type of the referenced expression
*/
! public URI getType();
}
--- 52,92 ----
public interface Expression
{
!
/**
! * Returns the type of the expression. This may be the data type of
! * an <code>AttributeValue</code>, the return type of a
! * <code>Function</code>, etc.
*
! * @return the attribute type of the referenced expression
*/
! public URI getType();
/**
! * Returns whether or not this expression returns, or evaluates to a
! * Bag. Note that <code>Evaluatable</code>, which extends this interface,
! * defines <code>evaluatesToBag</code> which is essentially the same
! * function. This method has been deprecated, and <code>returnsBag</code>
! * is now the preferred way to query all <code>Expression</code>s.
! */
! public boolean returnsBag();
!
! /**
! * Encodes this <code>Expression</code> into its XML representation and
! * writes this encoding to the given <code>OutputStream</code> with no
! * indentation.
*
! * @param output a stream into which the XML-encoded data is written
*/
! public void encode(OutputStream output);
!
! /**
! * Encodes this <code>Expression</code> into its XML representation and
! * writes this encoding to the given <code>OutputStream</code> with
! * indentation.
! *
! * @param output a stream into which the XML-encoded data is written
! * @param indenter an object that creates indentation strings
! */
! public void encode(OutputStream output, Indenter indenter);
}
Index: VariableReference.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/cond/VariableReference.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** VariableReference.java 7 Jan 2005 23:49:33 -0000 1.1
--- VariableReference.java 5 Dec 2005 23:34:51 -0000 1.2
***************
*** 40,43 ****
--- 40,44 ----
import com.sun.xacml.Indenter;
import com.sun.xacml.ParsingException;
+ import com.sun.xacml.PolicyMetaData;
import com.sun.xacml.ProcessingException;
***************
*** 65,69 ****
* @author Seth Proctor
*/
! public class VariableReference implements Evaluatable
{
--- 66,70 ----
* @author Seth Proctor
*/
! public class VariableReference implements Expression
{
***************
*** 124,127 ****
--- 125,129 ----
*
* @param root the DOM root of a VariableReferenceType XML type
+ * @param metaData the meta-data associated with the containing policy
* @param manager the <code>VariableManager</code> used to connect this
* reference to its definition
***************
*** 130,133 ****
--- 132,136 ----
*/
public static VariableReference getInstance(Node root,
+ PolicyMetaData metaData,
VariableManager manager)
throws ParsingException
***************
*** 144,156 ****
/**
- * Returns true since this expression is evaluatable.
- *
- * @return true
- */
- public boolean isEvaluatable() {
- return true;
- }
-
- /**
* Returns the reference identifier.
*
--- 147,150 ----
***************
*** 189,203 ****
*
* @return the result of evaluation
- *
- * @throws ProcessingException if the expression isn't evaluatable
*/
public EvaluationResult evaluate(EvaluationCtx context) {
Expression xpr = getReferencedDefinition().getExpression();
! if (xpr.isEvaluatable())
! return ((Evaluatable)xpr).evaluate(context);
!
! throw new ProcessingException("tried to evaluate an expression " +
! "that isn't evaluatable");
}
--- 183,197 ----
*
* @return the result of evaluation
*/
public EvaluationResult evaluate(EvaluationCtx context) {
Expression xpr = getReferencedDefinition().getExpression();
! // Note that it's technically possible for this expression to
! // be something like a Function, which isn't Evaluatable. It
! // wouldn't make sense to have this, but it is possible. Because
! // it makes no sense, however, it's unlcear exactly what the
! // error should be, so raising the ClassCastException here seems
! // as good an approach as any for now...
! return ((Evaluatable)xpr).evaluate(context);
}
***************
*** 231,249 ****
* @throws ProcessingException if the return type couldn't be resolved
*/
! public boolean evaluatesToBag() {
// see comment in getType()
if (definition != null) {
! Expression xpr = getReferencedDefinition().getExpression();
!
! // FIXME: for now we need to do this casting, but this should
! // change soon when the Function interface comes in line with
! // the Evaluatable type methods through the Expression interface
! if (xpr.isEvaluatable())
! return ((Evaluatable)xpr).evaluatesToBag();
! else
! return ((Function)xpr).returnsBag();
} else {
if (manager != null)
! return manager.evaluatesToBag(variableId);
}
--- 225,235 ----
* @throws ProcessingException if the return type couldn't be resolved
*/
! public boolean returnsBag() {
// see comment in getType()
if (definition != null) {
! return getReferencedDefinition().getExpression().returnsBag();
} else {
if (manager != null)
! return manager.returnsBag(variableId);
}
***************
*** 252,255 ****
--- 238,255 ----
/**
+ * Tells whether evaluation will return a bag or a single value.
+ *
+ * @return true if evaluation will return a bag, false otherwise
+ *
+ * @deprecated As of 2.0, you should use the <code>returnsBag</code>
+ * method from the super-interface <code>Expression</code>.
+ *
+ * @throws ProcessingException if the return type couldn't be resolved
+ */
+ public boolean evaluatesToBag() {
+ return returnsBag();
+ }
+
+ /**
* Always returns an empty list since references never have children in
* the policy tree. Note that the referenced definition may still have
--- NEW FILE: Condition.java ---
/*
* @(#)Condition.java
*
* Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN")
* AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
* AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for use in
* the design, construction, operation or maintenance of any nuclear facility.
*/
package com.sun.xacml.cond;
import com.sun.xacml.EvaluationCtx;
import com.sun.xacml.Indenter;
import com.sun.xacml.ParsingException;
import com.sun.xacml.PolicyMetaData;
import com.sun.xacml.attr.BooleanAttribute;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* Represents the XACML ConditionType type. It contains exactly one child
* expression that is boolean and returns a single value. This class was
* added in XACML 2.0
*
* @since 2.0
* @author Seth Proctor
*/
public class Condition implements Evaluatable
{
// a local Boolean URI that is used as the return type
private static URI booleanIdentifier;
// regardless of version, this contains the Condition's children
private List children;
// regardless of version, this is an expression that can be evaluated
// directly
private Expression expression;
// the condition function, which is only used if this is a 1.x condition
private Function function;
// flags whether this is XACML 1.x or 2.0
private boolean isVersionOne;
// initialize the boolean identifier
static {
try {
booleanIdentifier = new URI(BooleanAttribute.identifier);
} catch (Exception e) {
// we ignore this, since it cannot happen, but it should be
// flagged in case something changes to trip this case
booleanIdentifier = null;
}
}
/**
* Constructs a <code>Condition</code> as used in XACML 1.x.
*
* @param function the <code>Function</code> to use in evaluating the
* elements in the Condition
* @param xprs the contents of the Condition which will be the parameters
* to the function, each of which is an
* <code>Expression</code>
*
* @throws IllegalArgumentException if the input expressions don't
* match the signature of the function or
* if the function is invalid for use
* in a Condition
*/
public Condition(Function function, List expressions)
throws IllegalArgumentException
{
isVersionOne = true;
// check that the function is valid for a Condition
checkExpression(function);
// turn the parameters into an Apply for simplicity
expression = new Apply(function, expressions);
// keep track of the function and the children
this.function = function;
children = ((Apply)expression).getChildren();
}
/**
* Constructs a <code>Condition</code> as used in XACML 2.0.
*
* @param expression the child <code>Expression</code>
*
* @throws IllegalArgumentException if the expression is not boolean or
* returns a bag
*/
public Condition(Expression expression)
throws IllegalArgumentException
{
isVersionOne = false;
// check that the function is valid for a Condition
checkExpression(expression);
// store the expression
this.expression = expression;
// there is no function in a 2.0 Condition
function = null;
// store the expression as the child
List list = new ArrayList();
list.add(this.expression);
children = Collections.unmodifiableList(list);
}
/**
* Private helper for the constructors that checks if a given expression
* is valid for the root of a Condition
*/
private void checkExpression(Expression xpr) {
// make sure it's a boolean expression...
if (! xpr.getType().equals(booleanIdentifier))
throw new IllegalArgumentException("A Condition must return a " +
"boolean...cannot create " +
"with " + xpr.getType());
// ...and that it never returns a bag
if (xpr.returnsBag())
throw new IllegalArgumentException("A Condition must not return " +
"a Bag");
}
/**
* Returns an instance of <code>Condition</code> based on the given
* DOM root.
*
* @param root the DOM root of a ConditionType XML type
* @param metaData the meta-data associated with the containing policy
* @param manager <code>VariableManager</code> used to connect references
* and definitions while parsing
*
* @throws ParsingException if this is not a valid ConditionType
*/
public static Condition getInstance(Node root, PolicyMetaData metaData,
VariableManager manager)
throws ParsingException
{
if (metaData.getXACMLVersion() < PolicyMetaData.XACML_VERSION_2_0) {
Apply cond =
Apply.getConditionInstance(root, metaData.getXPathIdentifier(),
manager);
return new Condition(cond.getFunction(), cond.getChildren());
} else {
Expression xpr = null;
NodeList nodes = root.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
if (nodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
xpr = ExpressionHandler.
parseExpression(nodes.item(i), metaData, manager);
break;
}
}
return new Condition(xpr);
}
}
/**
* Returns the <code>Function</code> used by this <code>Condition</code>
* if this is a 1.x condition, or null if this is a 2.0 condition.
*
* @return a <code>Function</code> or null
*/
public Function getFunction() {
return function;
}
/**
* Returns the <code>List</code> of children for this
* <code>Condition</code>. The <code>List</code> contains
* <code>Expression</code>s. The list is unmodifiable.
*
* @return a <code>List</code> of <code>Expression</code>s
*/
public List getChildren() {
return children;
}
/**
* Returns the type of attribute that this object will return on a call
* to <code>evaluate</code>. This is always a boolean, since that's
* all that a Condition is allowed to return.
*
* @return the boolean type
*/
public URI getType() {
return booleanIdentifier;
}
/**
* Returns whether or not this <code>Condition</code> will return a bag
* of values on evaluation. This always returns false, since a Condition
* isn't allowed to return a bag.
*
* @return false
*/
public boolean returnsBag() {
return false;
}
/**
* Returns whether or not this <code>Condition</code> will return a bag
* of values on evaluation. This always returns false, since a Condition
* isn't allowed to return a bag.
*
* @deprecated As of 2.0, you should use the <code>returnsBag</code>
* method from the super-interface <code>Expression</code>.
*
* @return false
*/
public boolean evaluatesToBag() {
return false;
}
/**
* Evaluates the <code>Condition</code> by evaluating its child
* <code>Expression</code>.
*
* @param context the representation of the request
*
* @return the result of trying to evaluate this condition object
*/
public EvaluationResult evaluate(EvaluationCtx context) {
// Note that it's technically possible for this expression to
// be something like a Function, which isn't Evaluatable. It
// wouldn't make sense to have this, but it is possible. Because
// it makes no sense, however, it's unlcear exactly what the
// error should be, so raising the ClassCastException here seems
// as good an approach as any for now...
return ((Evaluatable)expression).evaluate(context);
}
/**
* Encodes this <code>Condition</code> into its XML representation and
* writes this encoding to the given <code>OutputStream</code> with no
* indentation.
*
* @param output a stream into which the XML-encoded data is written
*/
public void encode(OutputStream output) {
encode(output, new Indenter(0));
}
/**
* Encodes this <code>Condition</code> into its XML representation and
* writes this encoding to the given <code>OutputStream</code> with
* indentation.
*
* @param output a stream into which the XML-encoded data is written
* @param indenter an object that creates indentation strings
*/
public void encode(OutputStream output, Indenter indenter) {
PrintStream out = new PrintStream(output);
String indent = indenter.makeString();
if (isVersionOne) {
out.println(indent + "<Condition FunctionId=\"" +
function.getIdentifier() + "\">");
indenter.in();
Iterator it = children.iterator();
while (it.hasNext()) {
Expression xpr = (Expression)(it.next());
xpr.encode(output, indenter);
}
} else {
out.println(indent + "<Condition>");
indenter.in();
expression.encode(output, indenter);
}
indenter.out();
out.println(indent + "</Condition>");
}
}
Index: Apply.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/cond/Apply.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** Apply.java 7 Jan 2005 23:49:31 -0000 1.9
--- Apply.java 5 Dec 2005 23:34:51 -0000 1.10
***************
*** 40,49 ****
import com.sun.xacml.Indenter;
import com.sun.xacml.ParsingException;
! import com.sun.xacml.UnknownIdentifierException;
- import com.sun.xacml.attr.AttributeDesignator;
import com.sun.xacml.attr.AttributeFactory;
- import com.sun.xacml.attr.AttributeSelector;
- import com.sun.xacml.attr.AttributeValue;
import java.io.OutputStream;
--- 40,46 ----
import com.sun.xacml.Indenter;
import com.sun.xacml.ParsingException;
! import com.sun.xacml.PolicyMetaData;
import com.sun.xacml.attr.AttributeFactory;
import java.io.OutputStream;
***************
*** 63,66 ****
--- 60,75 ----
/**
* Represents the XACML ApplyType and ConditionType XML types.
+ * <p>
+ * Note well: as of 2.0, there is no longer a notion of a separate higher-
+ * order bag function. Instead, if needed, it is supplied as one of the
+ * <code>Expression</code>s in the parameter list. As such, when this
+ * <code>Apply</code> is evaluated, it no longer pre-evaluates all the
+ * parameters if a bag function is used. It is now up to the implementor
+ * of a higher-order function to do this.
+ * <p>
+ * Also, as of 2.0, the <code>Apply</code> is no longer used to represent
+ * a Condition, since the XACML 2.0 specification changed how Condition
+ * works. Instead, there is now a <code>Condition</code> class that
+ * represents both 1.x and 2.0 style Conditions.
*
* @since 1.0
***************
*** 74,138 ****
// the paramaters to the function...ie, the contents of the apply
! private List evals;
!
! // an apply may have an entry that's a function for bag operations
! private Function bagFunction;
!
! // whether or not this is a condition
! private boolean isCondition;
/**
! * Constructs an <code>Apply</code> object. Throws an
! * <code>IllegalArgumentException</code> if the given parameter list
! * isn't valid for the given function.
! *
* @param function the <code>Function</code> to use in evaluating the
* elements in the apply
! * @param evals the contents of the apply which will be the parameters
* to the function, each of which is an
! * <code>Evaluatable</code>
! * @param isCondition true if this <code>Apply</code> is a Condition,
! * false otherwise
*/
! public Apply(Function function, List evals, boolean isCondition)
throws IllegalArgumentException
{
! this(function, evals, null, isCondition);
}
/**
! * Constructs an <code>Apply</code> object that contains a higher-order
! * bag function. Throws an <code>IllegalArgumentException</code> if the
! * given parameter list isn't valid for the given function.
*
* @param function the <code>Function</code> to use in evaluating the
* elements in the apply
! * @param evals the contents of the apply which will be the parameters
* to the function, each of which is an
! * <code>Evaluatable</code>
! * @param bagFunction the higher-order function to use
! * @param isCondition true if this <code>Apply</code> is a Condition,
! * false otherwise
*/
! public Apply(Function function, List evals, Function bagFunction,
! boolean isCondition)
throws IllegalArgumentException
{
// check that the given inputs work for the function
! List inputs = evals;
! if (bagFunction != null) {
! inputs = new ArrayList();
! inputs.add(bagFunction);
! inputs.addAll(evals);
! }
! function.checkInputs(inputs);
// if everything checks out, then store the inputs
this.function = function;
! this.evals = Collections.unmodifiableList(new ArrayList(evals));
! this.bagFunction = bagFunction;
! this.isCondition = isCondition;
}
!
/**
* Returns an instance of an <code>Apply</code> based on the given DOM
--- 83,148 ----
// the paramaters to the function...ie, the contents of the apply
! private List xprs;
/**
! * Constructs an <code>Apply</code> instance.
! *
* @param function the <code>Function</code> to use in evaluating the
* elements in the apply
! * @param xprs the contents of the apply which will be the parameters
* to the function, each of which is an
! * <code>Expression</code>
! *
! * @throws IllegalArgumentException if the input expressions don't
! * match the signature of the function
*/
! public Apply(Function function, List xprs)
throws IllegalArgumentException
{
! // check that the given inputs work for the function
! function.checkInputs(xprs);
!
! // if everything checks out, then store the inputs
! this.function = function;
! this.xprs = Collections.unmodifiableList(new ArrayList(xprs));
}
/**
! * Constructs an <code>Apply</code> instance.
*
+ * @deprecated As of 2.0 <code>Apply</code> is no longer used for
+ * Conditions, so the <code>isCondition</code> parameter
+ * is no longer needed. You should now use the 2 parameter
+ * constructor. This constructor will be removed in a
+ * future release.
+ *
* @param function the <code>Function</code> to use in evaluating the
* elements in the apply
! * @param xprs the contents of the apply which will be the parameters
* to the function, each of which is an
! * <code>Expression</code>
! * @param isCondition as of 2.0, this must always be false
! *
! * @throws IllegalArgumentException if the input expressions don't
! * match the signature of the function or
! * if <code>isCondition</code> is true
*/
! public Apply(Function function, List xprs, boolean isCondition)
throws IllegalArgumentException
{
+ // make sure that no is using this constructor to create a Condition
+ if (isCondition)
+ throw new IllegalArgumentException("As of version 2.0 an Apply" +
+ " may not represent a" +
+ " Condition");
+
// check that the given inputs work for the function
! function.checkInputs(xprs);
// if everything checks out, then store the inputs
this.function = function;
! this.xprs = Collections.unmodifiableList(new ArrayList(xprs));
}
!
/**
* Returns an instance of an <code>Apply</code> based on the given DOM
***************
*** 142,145 ****
--- 152,164 ----
* as an ApplyType except that it must use a FunctionId that returns
* a boolean value.
+ * <p>
+ * Note that as of 2.0 there is a separate <code>Condition</code> class
+ * used to support the different kinds of Conditions in XACML 1.x and
+ * 2.0. As such, the system no longer treats a ConditionType as a
+ * special kind of ApplyType. You may still use this method to get a
+ * 1.x style ConditionType, but you will need to convert it into a
+ * <code>Condition</code> to use it in evaluation. The preferred way
+ * to create a Condition is now through the <code>getInstance</code>
+ * method on <code>Condition</code>.
*
* @param root the DOM root of a ConditionType XML type
***************
*** 156,170 ****
throws ParsingException
{
! return getInstance(root, FunctionFactory.getConditionInstance(), true,
! xpathVersion, manager);
}
/**
! * Returns an instance of <code>Apply</code> based on the given DOM root.
*
! * @param root the DOM root of an ApplyType XML type
* @param xpathVersion the XPath version to use in any selectors or XPath
* functions, or null if this is unspecified (ie, not
* supplied in the defaults section of the policy)
* @param manager <code>VariableManager</code> used to connect references
* and definitions while parsing
--- 175,222 ----
throws ParsingException
{
! return getInstance(root, FunctionFactory.getConditionInstance(),
! new PolicyMetaData(
! PolicyMetaData.XACML_1_0_IDENTIFIER,
! xpathVersion),
! manager);
}
/**
! * Returns an instance of an <code>Apply</code> based on the given DOM
! * root node. This will actually return a special kind of
! * <code>Apply</code>, namely an XML ConditionType, which is the root
! * of the condition logic in a RuleType. A ConditionType is the same
! * as an ApplyType except that it must use a FunctionId that returns
! * a boolean value.
*
! * @deprecated As of 2.0 you should avoid using this method, since it
! * does not provide a <code>Condition</code> instance and
! * does not handle XACML 2.0 policies correctly. If you need
! * a similar method you can use the new version that
! * accepts a <code>VariableManager</code>. This will return
! * an <code>Apply</code> instance for XACML 1.x policies.
! *
! * @param root the DOM root of a ConditionType XML type
* @param xpathVersion the XPath version to use in any selectors or XPath
* functions, or null if this is unspecified (ie, not
* supplied in the defaults section of the policy)
+ *
+ * @throws ParsingException if this is not a valid ConditionType
+ */
+ public static Apply getConditionInstance(Node root, String xpathVersion)
+ throws ParsingException
+ {
+ return getInstance(root, FunctionFactory.getConditionInstance(),
+ new PolicyMetaData(
+ PolicyMetaData.XACML_1_0_IDENTIFIER,
+ xpathVersion),
+ null);
+ }
+
+ /**
+ * Returns an instance of <code>Apply</code> based on the given DOM root.
+ *
+ * @param root the DOM root of an ApplyType XML type
+ * @param metaData the meta-data associated with the containing policy
* @param manager <code>VariableManager</code> used to connect references
* and definitions while parsing
***************
*** 172,181 ****
* @throws ParsingException if this is not a valid ApplyType
*/
! public static Apply getInstance(Node root, String xpathVersion,
VariableManager manager)
throws ParsingException
{
! return getInstance(root, FunctionFactory.getGeneralInstance(), false,
! xpathVersion, manager);
}
--- 224,259 ----
* @throws ParsingException if this is not a valid ApplyType
*/
! public static Apply getInstance(Node root, PolicyMetaData metaData,
VariableManager manager)
throws ParsingException
{
! return getInstance(root, FunctionFactory.getGeneralInstance(),
! metaData, manager);
! }
!
! /**
! * Returns an instance of <code>Apply</code> based on the given DOM root.
! *
! * @deprecated As of 2.0 you should avoid using this method, since it
! * does not handle XACML 2.0 policies correctly. If you need
! * a similar method you can use the new version that
! * accepts a <code>VariableManager</code>. This will return
! * an <code>Apply</code> instance for XACML 1.x policies.
! *
! * @param root the DOM root of an ApplyType XML type
! * @param xpathVersion the XPath version to use in any selectors or XPath
! * functions, or null if this is unspecified (ie, not
! * supplied in the defaults section of the policy)
! *
! * @throws ParsingException if this is not a valid ApplyType
! */
! public static Apply getInstance(Node root, String xpathVersion)
! throws ParsingException
! {
! return getInstance(root, FunctionFactory.getGeneralInstance(),
! new PolicyMetaData(
! PolicyMetaData.XACML_1_0_IDENTIFIER,
! xpathVersion),
! null);
}
***************
*** 186,236 ****
*/
private static Apply getInstance(Node root, FunctionFactory factory,
! boolean isCondition, String xpathVersion,
VariableManager manager)
throws ParsingException
{
! Function function = ExpressionHandler.
! getFunction(root, xpathVersion, factory);
! Function bagFunction = null;
! List evals = new ArrayList();
!
! AttributeFactory attrFactory = AttributeFactory.getInstance();
NodeList nodes = root.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Expression xpr = ExpressionHandler.
! parseExpression(nodes.item(i), xpathVersion, manager);
! if (xpr != null) {
! if (! xpr.isEvaluatable()) {
! // see if it's a function...
! if (xpr instanceof Function) {
! // while the schema doesn't enforce this, it's illegal
! // to have more than one FunctionType in a given
! // ApplyType ... FIXME: should I remove this?
! if (bagFunction != null)
! throw new
! ParsingException("Too many FunctionTypes");
!
! bagFunction = (Function)xpr;
! } else {
! evals.add(xpr);
! }
! } else {
! evals.add(xpr);
! }
! }
}
! return new Apply(function, evals, bagFunction, isCondition);
! }
!
! /**
! * Returns true since this expression is evaluatable.
! *
! * @return true
! */
! public boolean isEvaluatable() {
! return true;
}
--- 264,285 ----
*/
private static Apply getInstance(Node root, FunctionFactory factory,
! PolicyMetaData metaData,
VariableManager manager)
throws ParsingException
{
! Function function =
! ExpressionHandler.getFunction(root, metaData, factory);
! List xprs = new ArrayList();
NodeList nodes = root.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Expression xpr = ExpressionHandler.
! parseExpression(nodes.item(i), metaData, manager);
! if (xpr != null)
! xprs.add(xpr);
}
! return new Apply(function, xprs);
}
***************
*** 246,275 ****
/**
* Returns the <code>List</code> of children for this <code>Apply</code>.
! * The <code>List</code> contains <code>Evaluatable</code>s. The list is
* unmodifiable, and may be empty.
*
! * @return a <code>List</code> of <code>Evaluatable</code>s
*/
public List getChildren() {
! return evals;
}
/**
! * Returns the higher order bag function used by this <code>Apply</code>
! * if it exists, or null if no higher order function is used.
*
! * @return the higher order <code>Function</code> or null
! */
! public Function getHigherOrderFunction() {
! return bagFunction;
! }
!
! /**
! * Returns whether or not this ApplyType is actually a ConditionType.
*
! * @return whether or not this represents a ConditionType
*/
public boolean isCondition() {
! return isCondition;
}
--- 295,318 ----
/**
* Returns the <code>List</code> of children for this <code>Apply</code>.
! * The <code>List</code> contains <code>Expression</code>s. The list is
* unmodifiable, and may be empty.
*
! * @return a <code>List</code> of <code>Expression</code>s
*/
public List getChildren() {
! return xprs;
}
/**
! * Returns whether or not this ApplyType is actually a ConditionType. As
! * of 2.0 this always returns false;
*
! * @deprecated As of 2.0 this method should not be used, since an
! * <code>Apply</code> is never a Condition.
*
! * @return false
*/
public boolean isCondition() {
! return false;
}
***************
*** 284,315 ****
*/
public EvaluationResult evaluate(EvaluationCtx context) {
! List parameters = evals;
!
! // see if there is a higher-order function in here
! if (bagFunction != null) {
! // this is a special case, so we setup the parameters, starting
! // with the function
! parameters = new ArrayList();
! parameters.add(bagFunction);
!
! // now we evaluate all the parameters, returning INDETERMINATE
! // if that's what any of them return, and otherwise tracking
! // all the AttributeValues that get returned
! Iterator it = evals.iterator();
! while (it.hasNext()) {
! Evaluatable eval = (Evaluatable)(it.next());
! EvaluationResult result = eval.evaluate(context);
!
! // in a higher-order case, if anything is INDETERMINATE, then
! // we stop right away
! if (result.indeterminate())
! return result;
!
! parameters.add(result.getAttributeValue());
! }
! }
!
! // now we can call the base function
! return function.evaluate(parameters, context);
}
--- 327,337 ----
*/
public EvaluationResult evaluate(EvaluationCtx context) {
! // Note that prior to the 2.0 codebase, this method was much more
! // complex, pre-evaluating the higher-order functions. Because this
! // was never really the right behavior (there's no reason that a
! // function can only be at the start of an Apply), we no longer make
! // assumptions at this point, so the higher order functions are
! // left to evaluate their own parameters.
! return function.evaluate(xprs, context);
}
***************
*** 332,335 ****
--- 354,371 ----
* @return true if evaluation will return a bag of values, false otherwise
*/
+ public boolean returnsBag() {
+ return function.returnsBag();
+ }
+
+ /**
+ * Returns whether or not the <code>Function</code> will return a bag
+ * of values on evaluation.
+ *
+ *
+ * @deprecated As of 2.0, you should use the <code>returnsBag</code>
+ * method from the super-interface <code>Expression</code>.
+ *
+ * @return true if evaluation will return a bag of values, false otherwise
+ */
public boolean evaluatesToBag() {
return function.returnsBag();
***************
*** 359,385 ****
String indent = indenter.makeString();
! if (isCondition)
! out.println(indent + "<Condition FunctionId=\"" +
! function.getIdentifier() + "\">");
! else
! out.println(indent + "<Apply FunctionId=\"" +
! function.getIdentifier() + "\">");
indenter.in();
! if (bagFunction != null)
! out.println(indenter.makeString() + "<Function FunctionId=\"" +
! bagFunction.getIdentifier() + "\"/>");
!
! Iterator it = evals.iterator();
while (it.hasNext()) {
! Evaluatable eval = (Evaluatable)(it.next());
! eval.encode(output, indenter);
}
indenter.out();
! if (isCondition)
! out.println(indent + "</Condition>");
! else
! out.println(indent + "</Apply>");
}
--- 395,410 ----
String indent = indenter.makeString();
! out.println(indent + "<Apply FunctionId=\"" +
! function.getIdentifier() + "\">");
indenter.in();
! Iterator it = xprs.iterator();
while (it.hasNext()) {
! Expression xpr = (Expression)(it.next());
! xpr.encode(output, indenter);
}
indenter.out();
! out.println(indent + "</Apply>");
}
Index: VariableDefinition.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/cond/VariableDefinition.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** VariableDefinition.java 7 Jan 2005 23:49:32 -0000 1.1
--- VariableDefinition.java 5 Dec 2005 23:34:51 -0000 1.2
***************
*** 39,42 ****
--- 39,43 ----
import com.sun.xacml.Indenter;
import com.sun.xacml.ParsingException;
+ import com.sun.xacml.PolicyMetaData;
import java.io.OutputStream;
***************
*** 84,90 ****
*
* @param root the DOM root of a VariableDefinitionType XML type
! * @param xpathVersion the XPath version to use in any selectors or XPath
! * functions, or null if this is unspecified (ie, not
! * supplied in the defaults section of the policy)
* @param manager <code>VariableManager</code> used to connect references
* to this definition
--- 85,89 ----
*
* @param root the DOM root of a VariableDefinitionType XML type
! * @param metaData the meta-data associated with the containing policy
* @param manager <code>VariableManager</code> used to connect references
* to this definition
***************
*** 93,97 ****
*/
public static VariableDefinition getInstance(Node root,
! String xpathVersion,
VariableManager manager)
throws ParsingException
--- 92,96 ----
*/
public static VariableDefinition getInstance(Node root,
! PolicyMetaData metaData,
VariableManager manager)
throws ParsingException
***************
*** 109,113 ****
// use that node to get the expression
Expression xpr = ExpressionHandler.
! parseExpression(xprNode, xpathVersion, manager);
return new VariableDefinition(variableId, xpr);
--- 108,112 ----
// use that node to get the expression
Expression xpr = ExpressionHandler.
! parseExpression(xprNode, metaData, manager);
return new VariableDefinition(variableId, xpr);
***************
*** 157,167 ****
indenter.in();
! if (expression.isEvaluatable()) {
! ((Evaluatable)expression).encode(output, indenter);
! } else {
! Function function = (Function)expression;
! out.println(indenter.makeString() + "<Function FunctionId=\"" +
! function.getIdentifier() + "\"/>");
! }
out.println("</VariableDefinition>");
--- 156,160 ----
indenter.in();
! expression.encode(output, indenter);
out.println("</VariableDefinition>");
Index: ExpressionHandler.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/cond/ExpressionHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ExpressionHandler.java 7 Jan 2005 23:49:32 -0000 1.1
--- ExpressionHandler.java 5 Dec 2005 23:34:51 -0000 1.2
***************
*** 11,14 ****
--- 11,16 ----
package com.sun.xacml.cond;
+ import com.sun.xacml.PolicyMetaData;
+
import com.sun.xacml.ParsingException;
import com.sun.xacml.UnknownIdentifierException;
***************
*** 37,44 ****
* Parses an expression, recursively handling any sub-elements. This is
* provided as a utility class, but in practice is used only by
! * <code>Apply</code> and <code>VariableDefinition</code>.
*
*/
! public static Expression parseExpression(Node root, String xpathVersion,
VariableManager manager)
throws ParsingException
--- 39,55 ----
* Parses an expression, recursively handling any sub-elements. This is
* provided as a utility class, but in practice is used only by
! * <code>Apply</code>, <code>Condition</code>, and
! * <code>VariableDefinition</code>.
*
+ * @param root the DOM root of an ExpressionType XML type
+ * @param metaData the meta-data associated with the containing policy
+ * @param manager <code>VariableManager</code> used to connect references
+ * and definitions while parsing
+ *
+ * @return an <code>Expression</code> or null if the root node cannot be
+ * parsed as a valid Expression
*/
! public static Expression parseExpression(Node root,
! PolicyMetaData metaData,
VariableManager manager)
throws ParsingException
***************
*** 47,51 ****
if (name.equals("Apply")) {
! return Apply.getInstance(root, xpathVersion, manager);
} else if (name.equals("AttributeValue")) {
try {
--- 58,62 ----
if (name.equals("Apply")) {
! return Apply.getInstance(root, metaData, manager);
} else if (name.equals("AttributeValue")) {
try {
***************
*** 56,76 ****
} else if (name.equals("SubjectAttributeDesignator")) {
return AttributeDesignator.
! getInstance(root, AttributeDesignator.SUBJECT_TARGET);
} else if (name.equals("ResourceAttributeDesignator")) {
return AttributeDesignator.
! getInstance(root, AttributeDesignator.RESOURCE_TARGET);
} else if (name.equals("ActionAttributeDesignator")) {
return AttributeDesignator.
! getInstance(root, AttributeDesignator.ACTION_TARGET);
} else if (name.equals("EnvironmentAttributeDesignator")) {
return AttributeDesignator.
! getInstance(root, AttributeDesignator.ENVIRONMENT_TARGET);
} else if (name.equals("AttributeSelector")) {
! return AttributeSelector.getInstance(root, xpathVersion);
} else if (name.equals("Function")) {
! return getFunction(root, xpathVersion,
FunctionFactory.getGeneralInstance());
} else if (name.equals("VariableReference")) {
! return VariableReference.getInstance(root, manager);
}
--- 67,91 ----
} else if (name.equals("SubjectAttributeDesignator")) {
return AttributeDesignator.
! getInstance(root, AttributeDesignator.SUBJECT_TARGET,
! metaData);
} else if (name.equals("ResourceAttributeDesig...
[truncated message content] |