You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ws.apache.org by sa...@apache.org on 2005/12/30 19:58:38 UTC
svn commit: r360141 - in /webservices/commons/trunk/policy/src:
examples/SimplePolicyExample.java
org/apache/ws/policy/CompositeAssertion.java org/apache/ws/policy/Policy.java
org/apache/ws/policy/util/StAXPolicyWriter.java
Author: sanka
Date: Fri Dec 30 10:58:28 2005
New Revision: 360141
URL: http://svn.apache.org/viewcvs?rev=360141&view=rev
Log:
Fixed: see: http://www.opensubscriber.com/message/wss4j-dev@ws.apache.org/2944470.html
Modified:
webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java
webservices/commons/trunk/policy/src/org/apache/ws/policy/CompositeAssertion.java
webservices/commons/trunk/policy/src/org/apache/ws/policy/Policy.java
webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java
Modified: webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java?rev=360141&r1=360140&r2=360141&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java (original)
+++ webservices/commons/trunk/policy/src/examples/SimplePolicyExample.java Fri Dec 30 10:58:28 2005
@@ -36,8 +36,8 @@
if (args.length > 0) {
fis = new FileInputStream(args[0]);
} else {
- fis = new FileInputStream("policy/src/examples/policy2.xml");
-// fis = new FileInputStream("policy/src/examples/SecurityPolicyMsg.xml");
+// fis = new FileInputStream("policy/src/examples/policy2.xml");
+ fis = new FileInputStream("policy/src/examples/SecurityPolicyMsg.xml");
}
PolicyReader prdr = PolicyFactory
Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/CompositeAssertion.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/CompositeAssertion.java?rev=360141&r1=360140&r2=360141&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/CompositeAssertion.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/CompositeAssertion.java Fri Dec 30 10:58:28 2005
@@ -27,7 +27,7 @@
public abstract class CompositeAssertion implements Assertion {
/** */
- protected boolean flag = true;
+ protected boolean flag = false;
/** */
private List list = new ArrayList();
@@ -124,7 +124,7 @@
while (children.hasNext()) {
Object child = children.next();
if (child instanceof CompositeAssertion) {
- ((CompositeAssertion) child).setNormalized(true);
+ ((CompositeAssertion) child).setNormalized(value);
}
}
flag = value;
Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/Policy.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/Policy.java?rev=360141&r1=360140&r2=360141&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/Policy.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/Policy.java Fri Dec 30 10:58:28 2005
@@ -24,16 +24,14 @@
import org.apache.commons.logging.Log;
import org.apache.ws.policy.util.PolicyRegistry;
-
/**
* Policy is the access point for policy framework. It the object model that
* represents a policy at runtime.
*
*/
public class Policy extends AndCompositeAssertion implements Assertion {
- private Log log =
- LogFactory.getLog(this.getClass().getName());
-
+ private Log log = LogFactory.getLog(this.getClass().getName());
+
private String policyURI = null;
private String xmlBase = null;
@@ -41,7 +39,6 @@
private String id = null;
public Policy() {
- setNormalized(false);
}
public Policy(String id) {
@@ -81,8 +78,10 @@
public Assertion normalize(PolicyRegistry reg) {
log.debug("Enter: Policy::normalize");
-
- if (isNormalized()) { return this;}
+
+ if (isNormalized()) {
+ return this;
+ }
String xmlBase = getBase();
String id = getId();
@@ -98,37 +97,46 @@
Assertion term;
while (terms.hasNext()) {
-
term = (Assertion) terms.next();
- term = (term instanceof Policy) ? term : term.normalize(reg);
-
+ term = term.normalize(reg);
+
if (term instanceof Policy) {
- Assertion wrapper = new AndCompositeAssertion();
- ((AndCompositeAssertion) wrapper).addTerms(((Policy) term).getTerms());
- term = wrapper.normalize(reg);
+ XorCompositeAssertion Xor = (XorCompositeAssertion) ((Policy) term)
+ .getTerms().get(0);
+
+ if (Xor.size() != 1) {
+ term = Xor;
+
+ } else {
+ AND
+ .addTerms(((AndCompositeAssertion) Xor.getTerms()
+ .get(0)).getTerms());
+ continue;
+ }
}
-
+
if (term instanceof XorCompositeAssertion) {
+
if (((XorCompositeAssertion) term).isEmpty()) {
XorCompositeAssertion emptyXor = new XorCompositeAssertion();
emptyXor.setNormalized(true);
-
+
policy.addTerm(emptyXor);
policy.setNormalized(true);
-
+
return policy;
}
-
+
childXorTermList.add(term);
continue;
}
-
+
if (term instanceof AndCompositeAssertion) {
-
+
if (((AndCompositeAssertion) term).isEmpty()) {
AndCompositeAssertion emptyAnd = new AndCompositeAssertion();
XOR.addTerm(emptyAnd);
-
+
} else {
AND.addTerms(((AndCompositeAssertion) term).getTerms());
}
@@ -143,7 +151,7 @@
for (int i = 0; i < childXorTermList.size(); i++) {
for (int j = i; j < childXorTermList.size(); j++) {
-
+
if (i != j) {
XorCompositeAssertion xorTermA = (XorCompositeAssertion) childXorTermList
.get(i);
@@ -155,9 +163,9 @@
while (iterA.hasNext()) {
CompositeAssertion andTermA = (CompositeAssertion) iterA
.next();
-
+
Iterator iterB = xorTermB.getTerms().iterator();
-
+
while (iterB.hasNext()) {
CompositeAssertion andTermB = (CompositeAssertion) iterB
.next();
@@ -179,9 +187,10 @@
if (childXorTermList.isEmpty()) {
XorCompositeAssertion xor = new XorCompositeAssertion();
-
+
xor.addTerm(AND);
policy.addTerm(xor);
+ policy.setNormalized(true);
return policy;
}
@@ -189,20 +198,18 @@
Iterator andTerms = XOR.getTerms().iterator();
while (andTerms.hasNext()) {
- CompositeAssertion anAndTerm = (CompositeAssertion) andTerms
- .next();
+ CompositeAssertion anAndTerm = (CompositeAssertion) andTerms.next();
anAndTerm.addTerms(primTerms);
}
-
+
policy.addTerm(XOR);
policy.setNormalized(true);
return policy;
-
}
public Assertion intersect(Assertion assertion, PolicyRegistry reg) {
log.debug("Enter: Policy::intersect");
-
+
Policy result = new Policy(getBase(), getId());
Policy normalizedMe = (Policy) ((isNormalized()) ? this
: normalize(reg));
@@ -233,7 +240,7 @@
public Assertion merge(Assertion assertion, PolicyRegistry reg) {
log.debug("Enter: Policy::merge");
-
+
Policy result = new Policy(getBase(), getId());
Policy normalizedMe = (Policy) ((isNormalized()) ? this
: normalize(reg));
Modified: webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java?rev=360141&r1=360140&r2=360141&view=diff
==============================================================================
--- webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java (original)
+++ webservices/commons/trunk/policy/src/org/apache/ws/policy/util/StAXPolicyWriter.java Fri Dec 30 10:58:28 2005
@@ -200,7 +200,26 @@
private void writePolicyReference(PolicyReference assertion,
XMLStreamWriter writer) throws XMLStreamException {
- throw new UnsupportedOperationException();
+
+ String writerPrefix = writer
+ .getPrefix(PolicyConstants.WS_POLICY_NAMESPACE_URI);
+ if (writerPrefix != null) {
+ writer.writeStartElement(PolicyConstants.WS_POLICY_NAMESPACE_URI,
+ PolicyConstants.WS_POLICY_REFERENCE);
+ } else {
+
+ writer.writeStartElement(PolicyConstants.WS_POLICY_PREFIX,
+ PolicyConstants.WS_POLICY_REFERENCE,
+ PolicyConstants.WS_POLICY_NAMESPACE_URI);
+ writer.writeNamespace(PolicyConstants.WS_POLICY_PREFIX,
+ PolicyConstants.WS_POLICY_NAMESPACE_URI);
+ writer.setPrefix(PolicyConstants.WS_POLICY_PREFIX,
+ PolicyConstants.WS_POLICY_NAMESPACE_URI);
+
+ }
+ writer.writeAttribute("URI", assertion.getPolicyURIString());
+
+ writer.writeEndElement();
}
private void writeTerms(List terms, XMLStreamWriter writer)