Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml
In directory sc8-pr-cvs1:/tmp/cvs-serv22245
Modified Files:
AbstractPolicy.java Indenter.java Obligation.java PDP.java
Policy.java PolicyReference.java PolicySet.java
PolicyTreeElement.java Rule.java Target.java TargetMatch.java
Log Message:
updated all existing encoding and added new encoding routines for all policy
related elements
Index: AbstractPolicy.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/AbstractPolicy.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** AbstractPolicy.java 14 Aug 2003 22:56:48 -0000 1.4
--- AbstractPolicy.java 25 Aug 2003 16:53:10 -0000 1.5
***************
*** 44,47 ****
--- 44,49 ----
import com.sun.xacml.ctx.Result;
+ import java.io.OutputStream;
+
import java.net.URI;
***************
*** 391,394 ****
--- 393,417 ----
// finally, return the result
return result;
+ }
+
+ /**
+ * Routine used by <code>Policy</code> and <code>PolicySet</code> to
+ * encode some common elements.
+ *
+ * @param output a stream into which the XML-encoded data is written
+ * @param indenter an object that creates indentation strings
+ */
+ protected void encodeCommonElements(OutputStream out, Indenter indenter) {
+ target.encode(out, indenter);
+
+ Iterator it = children.iterator();
+ while (it.hasNext()) {
+ ((PolicyTreeElement)(it.next())).encode(out, indenter);
+ }
+
+ it = obligations.iterator();
+ while (it.hasNext()) {
+ ((Obligation)(it.next())).encode(out, indenter);
+ }
}
Index: Indenter.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/Indenter.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Indenter.java 13 Feb 2003 22:19:10 -0000 1.1.1.1
--- Indenter.java 25 Aug 2003 16:53:10 -0000 1.2
***************
*** 51,60 ****
{
// The width of one indentation level
private int width;
! // Default width
! private final int defaultWidth = 2;
!
/**
--- 51,64 ----
{
+ /**
+ * The default indentation width
+ */
+ public static final int DEFAULT_WIDTH = 2;
+
// The width of one indentation level
private int width;
! // the current depth
! private int depth;
/**
***************
*** 63,67 ****
*/
public Indenter() {
! width = defaultWidth;
}
--- 67,71 ----
*/
public Indenter() {
! this(DEFAULT_WIDTH);
}
***************
*** 74,90 ****
public Indenter(int userWidth) {
width = userWidth;
}
/**
! * Create a <code>String</code> of spaces for indentation. Uses
! * width setting and depth parameter to generate string of correct
! * length.
! *
! * @param depth the current depth of the XML nesting
*
* @return an indent string to prepend to lines of XML
*/
! public String makeString(int depth) {
// Return quickly if no indenting
if (width <= 0) {
--- 78,105 ----
public Indenter(int userWidth) {
width = userWidth;
+ depth = 0;
+ }
+
+ /**
+ * Move in one width.
+ */
+ public void in() {
+ depth += width;
}
+ /**
+ * Move out one width.
+ */
+ public void out() {
+ depth -= width;
+ }
/**
! * Create a <code>String</code> of spaces for indentation based on the
! * current depth.
*
* @return an indent string to prepend to lines of XML
*/
! public String makeString() {
// Return quickly if no indenting
if (width <= 0) {
***************
*** 93,97 ****
// Make a char array and fill it with spaces
! char[] array = new char[depth * width];
Arrays.fill(array, ' ');
--- 108,112 ----
// Make a char array and fill it with spaces
! char[] array = new char[depth];
Arrays.fill(array, ' ');
***************
*** 99,103 ****
return new String(array);
}
-
}
--- 114,117 ----
Index: Obligation.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/Obligation.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Obligation.java 13 Feb 2003 22:19:10 -0000 1.1.1.1
--- Obligation.java 25 Aug 2003 16:53:10 -0000 1.2
***************
*** 190,210 ****
/**
* Encodes this <code>Obligation</code> into its XML form and writes this
* out to the provided <code>OutputStream<code> with indentation.
*
* @param output a stream into which the XML-encoded data is written
- * @param depth the nesting depth for indenting XML
* @param indenter an object that creates indentation strings
*/
! public void encode(OutputStream output, int depth, Indenter indenter) {
PrintStream out = new PrintStream(output);
! String indent = indenter.makeString(depth);
out.println(indent + "<Obligation ObligationId=\"" + id.toString() +
"\" FulfillOn=\"" + Result.DECISIONS[fulfillOn] + "\">");
Iterator it = assignments.iterator();
while (it.hasNext()) {
Attribute attr = (Attribute)(it.next());
! out.println(indenter.makeString(depth+1) +
"<AttributeAssignment AttributeId=\"" +
attr.getId().toString() + "\" DataType=\"" +
--- 190,222 ----
/**
* Encodes this <code>Obligation</code> into its XML form and writes this
+ * out to the provided <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>Obligation</code> into its XML form and writes this
* out to the provided <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();
out.println(indent + "<Obligation ObligationId=\"" + id.toString() +
"\" FulfillOn=\"" + Result.DECISIONS[fulfillOn] + "\">");
+
+ indenter.in();
Iterator it = assignments.iterator();
+
while (it.hasNext()) {
Attribute attr = (Attribute)(it.next());
! out.println(indenter.makeString() +
"<AttributeAssignment AttributeId=\"" +
attr.getId().toString() + "\" DataType=\"" +
***************
*** 213,216 ****
--- 225,230 ----
"</AttributeAssignment>");
}
+
+ indenter.out();
out.println(indent + "</Obligation>");
Index: PDP.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/PDP.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** PDP.java 13 Feb 2003 22:19:10 -0000 1.1.1.1
--- PDP.java 25 Aug 2003 16:53:10 -0000 1.2
***************
*** 252,256 ****
ByteArrayOutputStream out = new ByteArrayOutputStream();
! response.encode(out, 0, new Indenter());
return out;
--- 252,256 ----
ByteArrayOutputStream out = new ByteArrayOutputStream();
! response.encode(out, new Indenter());
return out;
Index: Policy.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/Policy.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Policy.java 14 Aug 2003 22:56:48 -0000 1.3
--- Policy.java 25 Aug 2003 16:53:10 -0000 1.4
***************
*** 41,45 ****
import com.sun.xacml.ctx.Result;
! import java.io.InputStream;
import java.net.URI;
--- 41,46 ----
import com.sun.xacml.ctx.Result;
! import java.io.OutputStream;
! import java.io.PrintStream;
import java.net.URI;
***************
*** 233,236 ****
--- 234,284 ----
return new Policy(root);
+ }
+
+ /**
+ * Encodes this <code>Policy</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>Policy</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();
+
+ out.println(indent + "<Policy PolicyId=\"" + getId().toString() +
+ "\" RuleCombiningAlgId=\"" +
+ getCombiningAlg().getIdentifier().toString() +
+ "\">");
+
+ indenter.in();
+ String nextIndent = indenter.makeString();
+
+ String description = getDescription();
+ if (description != null)
+ out.println(nextIndent + "<Description>" + description +
+ "</Description>");
+
+ String version = getDefaultVersion();
+ if (version != null)
+ out.println("<PolicyDefaults><XPathVersion>" + version +
+ "</XPathVersion></PolicyDefaults>");
+
+ encodeCommonElements(output, indenter);
+
+ indenter.out();
+ out.println(indent + "</Policy>");
}
Index: PolicyReference.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/PolicyReference.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PolicyReference.java 17 Jun 2003 18:23:52 -0000 1.2
--- PolicyReference.java 25 Aug 2003 16:53:10 -0000 1.3
***************
*** 45,48 ****
--- 45,51 ----
import com.sun.xacml.finder.PolicyFinderResult;
+ import java.io.OutputStream;
+ import java.io.PrintStream;
+
import java.net.URI;
***************
*** 311,314 ****
--- 314,349 ----
// we must have found a policy
return pfr.getPolicy().evaluate(context);
+ }
+
+ /**
+ * Encodes this <code>PolicyReference</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>PolicyReference</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 encoded = indenter.makeString();
+
+ if (policyType == POLICY_REFERENCE) {
+ out.println(encoded + "<PolicyIdReference>" +
+ reference.toString() + "</PolicyIdReference");
+ } else {
+ out.println(encoded + "<PolicySetIdReference>" +
+ reference.toString() + "</PolicySetIdReference>");
+ }
}
Index: PolicySet.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/PolicySet.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** PolicySet.java 14 Aug 2003 22:56:48 -0000 1.3
--- PolicySet.java 25 Aug 2003 16:53:10 -0000 1.4
***************
*** 43,47 ****
import com.sun.xacml.finder.PolicyFinder;
! import java.io.InputStream;
import java.net.URI;
--- 43,48 ----
import com.sun.xacml.finder.PolicyFinder;
! import java.io.OutputStream;
! import java.io.PrintStream;
import java.net.URI;
***************
*** 264,267 ****
--- 265,315 ----
return new PolicySet(root, finder);
+ }
+
+ /**
+ * Encodes this <code>PolicySet</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>PolicySet</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();
+
+ out.println(indent + "<PolicySet PolicySetId=\"" + getId().toString() +
+ "\" PolicyCombiningAlgId=\"" +
+ getCombiningAlg().getIdentifier().toString() +
+ "\">");
+
+ indenter.in();
+ String nextIndent = indenter.makeString();
+
+ String description = getDescription();
+ if (description != null)
+ out.println(nextIndent + "<Description>" + description +
+ "</Description>");
+
+ String version = getDefaultVersion();
+ if (version != null)
+ out.println("<PolicySetDefaults><XPathVersion>" + version +
+ "</XPathVersion></PolicySetDefaults>");
+
+ encodeCommonElements(output, indenter);
+
+ indenter.out();
+ out.println(indent + "</PolicySet>");
}
Index: PolicyTreeElement.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/PolicyTreeElement.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** PolicyTreeElement.java 17 Jun 2003 18:23:52 -0000 1.1
--- PolicyTreeElement.java 25 Aug 2003 16:53:10 -0000 1.2
***************
*** 39,42 ****
--- 39,44 ----
import com.sun.xacml.ctx.Result;
+ import java.io.OutputStream;
+
import java.net.URI;
***************
*** 110,113 ****
--- 112,134 ----
*/
public Result evaluate(EvaluationCtx context);
+
+ /**
+ * Encodes this element 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 element 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: Rule.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/Rule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Rule.java 17 Jun 2003 18:23:52 -0000 1.2
--- Rule.java 25 Aug 2003 16:53:10 -0000 1.3
***************
*** 45,48 ****
--- 45,51 ----
import com.sun.xacml.ctx.Status;
+ import java.io.OutputStream;
+ import java.io.PrintStream;
+
import java.net.URI;
import java.net.URISyntaxException;
***************
*** 80,84 ****
*
* @param id the rule's identifier
! * @param effect the effect to return if the rule applies
* @param description a textual description, or null
* @param target the rule's target, or null if the target is to be
--- 83,88 ----
*
* @param id the rule's identifier
! * @param effect the effect to return if the rule applies (either
! * Pemit or Deny) as specified in <code>Result</code>
* @param description a textual description, or null
* @param target the rule's target, or null if the target is to be
***************
*** 151,155 ****
/**
* Returns the effect that this <code>Rule</code> will return from
! * the evaluate method if the request applies.
*
* @return a decision effect, as defined in <code>Result</code>
--- 155,159 ----
/**
* Returns the effect that this <code>Rule</code> will return from
! * the evaluate method (Permit or Deny) if the request applies.
*
* @return a decision effect, as defined in <code>Result</code>
***************
*** 287,290 ****
--- 291,345 ----
else
return new Result(Result.DECISION_NOT_APPLICABLE);
+ }
+ }
+
+ /**
+ * Encodes this <code>Rule</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>Rule</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();
+
+ out.print(indent + "<Rule RuleId=\"" + idAttr.toString() +
+ "\" Effect=\"" + Result.DECISIONS[effectAttr] + "\"");
+
+ if ((description != null) || (target != null) || (condition != null)) {
+ // there is some content in the Rule
+ out.println(">");
+
+ indenter.in();
+ String nextIndent = indenter.makeString();
+
+ if (description != null)
+ out.println(nextIndent + "<Description>" + description +
+ "</Description>");
+
+ if (target != null)
+ target.encode(output, indenter);
+
+ if (condition != null)
+ condition.encode(output, indenter);
+
+ indenter.out();
+ out.println(indent + "</Rule>");
+ } else {
+ // the Rule is empty, so close the tag and we're done
+ out.println("/>");
}
}
Index: Target.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/Target.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Target.java 29 Jul 2003 22:01:46 -0000 1.2
--- Target.java 25 Aug 2003 16:53:10 -0000 1.3
***************
*** 39,42 ****
--- 39,45 ----
import com.sun.xacml.ctx.Status;
+ import java.io.OutputStream;
+ import java.io.PrintStream;
+
import java.util.ArrayList;
import java.util.Collections;
***************
*** 305,308 ****
--- 308,386 ----
return new MatchResult(MatchResult.INDETERMINATE,
firstIndeterminateStatus);
+ }
+
+ /**
+ * Encodes this <code>Target</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>Target</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();
+
+ out.println(indent + "<Target>");
+ indenter.in();
+
+ encodeSection(out, indenter, "Subject", subjects);
+ encodeSection(out, indenter, "Resource", resources);
+ encodeSection(out, indenter, "Action", actions);
+
+ indenter.out();
+ out.println(indent + "</Target>");
+ }
+
+ /**
+ * Helper function that encodes a section of the target.
+ */
+ private void encodeSection(PrintStream output, Indenter indenter,
+ String name, List list) {
+ String indent = indenter.makeString();
+
+ output.println(indent + "<" + name + "s>");
+
+ indenter.in();
+ String indentNext = indenter.makeString();
+
+ if (list == null) {
+ // the match is any
+ output.println(indentNext + "<Any" + name + "/>");
+ } else {
+ String nextIndent = indenter.makeString();
+
+ Iterator it = list.iterator();
+ indenter.in();
+
+ while (it.hasNext()) {
+ List items = (List)(it.next());
+ output.println(indentNext + "<" + name + ">");
+
+ Iterator matchIterator = items.iterator();
+ while (matchIterator.hasNext()) {
+ TargetMatch tm = (TargetMatch)(matchIterator.next());
+ tm.encode(output, indenter);
+ }
+
+ output.println(indentNext + "</" + name + ">");
+ }
+
+ indenter.out();
+ }
+
+ indenter.out();
+ output.println(indent + "</" + name + "s>");
}
Index: TargetMatch.java
===================================================================
RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/TargetMatch.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TargetMatch.java 29 Jul 2003 22:01:46 -0000 1.2
--- TargetMatch.java 25 Aug 2003 16:53:10 -0000 1.3
***************
*** 54,57 ****
--- 54,60 ----
import com.sun.xacml.ctx.Status;
+ import java.io.OutputStream;
+ import java.io.PrintStream;
+
import java.net.URI;
import java.net.URISyntaxException;
***************
*** 339,342 ****
--- 342,389 ----
else
return new MatchResult(MatchResult.NO_MATCH);
+ }
+
+ /**
+ * Encodes this <code>TargetMatch</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>TargetMatch</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();
+ String tagName = null;
+
+ switch (type) {
+ case SUBJECT: tagName = "SubjectMatch";
+ break;
+ case RESOURCE: tagName = "ResourceMatch";
+ break;
+ case ACTION: tagName = "ActionMatch";
+ break;
+ }
+
+ out.println(indent + "<" + tagName + " MatchId=\"" +
+ function.getIdentifier().toString()+ "\">");
+ indenter.in();
+
+ attrValue.encode(output, indenter);
+ eval.encode(output, indenter);
+
+ indenter.out();
+ out.println(indent + "</" + tagName + ">");
}
|