You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2026/07/10 10:45:27 UTC
(ws-neethi) branch coheigea/policy-containing-primitive created (now 113d784)
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a change to branch coheigea/policy-containing-primitive
in repository https://gitbox.apache.org/repos/asf/ws-neethi.git
at 113d784 Policy Containing Primitive fix
This branch includes the following new commits:
new 113d784 Policy Containing Primitive fix
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(ws-neethi) 01/01: Policy Containing Primitive fix
Posted by co...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch coheigea/policy-containing-primitive
in repository https://gitbox.apache.org/repos/asf/ws-neethi.git
commit 113d7845c381bdb190e21962870ecfe3ad8478b2
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Fri Jul 10 11:45:03 2026 +0100
Policy Containing Primitive fix
---
.../PolicyContainingPrimitiveAssertion.java | 4 ++
.../builders/xml/XMLPrimitiveAssertionBuilder.java | 1 +
.../java/org/apache/neethi/BasicTestCases.java | 16 ++++++++
.../apache/neethi/PolicyNormalizationDoSTest.java | 45 ++++++++++++++++++++++
4 files changed, 66 insertions(+)
diff --git a/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java b/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
index 87ef19a..c31b00b 100644
--- a/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
+++ b/src/main/java/org/apache/neethi/builders/PolicyContainingPrimitiveAssertion.java
@@ -29,6 +29,7 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.neethi.All;
+import org.apache.neethi.AbstractPolicyOperator;
import org.apache.neethi.Assertion;
import org.apache.neethi.ExactlyOne;
import org.apache.neethi.Policy;
@@ -72,6 +73,7 @@ public class PolicyContainingPrimitiveAssertion
if (isOptional()) {
ea.addPolicyComponent(new All());
}
+ long alternativesSoFar = ea.getPolicyComponents().size();
// for all alternatives in normalized nested policy
Iterator<List<Assertion>> alternatives = normalisedNested.getAlternatives();
while (alternatives.hasNext()) {
@@ -85,7 +87,9 @@ public class PolicyContainingPrimitiveAssertion
nea.addPolicyComponent(na);
na.addPolicyComponents(alternative);
all.addPolicyComponent(a);
+ AbstractPolicyOperator.checkMaximumAlternativeCount(alternativesSoFar + 1, "normalization");
ea.addPolicyComponent(all);
+ alternativesSoFar++;
}
return p;
}
diff --git a/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java b/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
index e7ce716..7276ecf 100644
--- a/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
+++ b/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
@@ -90,6 +90,7 @@ public class XMLPrimitiveAssertionBuilder implements AssertionBuilder<Element> {
public Assertion newPolicyContainingAssertion(Element element, Map<QName, String> atts, Policy policy) {
return new PolicyContainingPrimitiveAssertion(getQName(element),
isOptional(element), isIgnorable(element),
+ atts,
policy);
}
diff --git a/src/test/java/org/apache/neethi/BasicTestCases.java b/src/test/java/org/apache/neethi/BasicTestCases.java
index c11420d..618adac 100644
--- a/src/test/java/org/apache/neethi/BasicTestCases.java
+++ b/src/test/java/org/apache/neethi/BasicTestCases.java
@@ -40,6 +40,7 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.apache.neethi.builders.PrimitiveAssertion;
+import org.apache.neethi.builders.PolicyContainingPrimitiveAssertion;
import org.apache.neethi.builders.xml.XMLPrimitiveAssertionBuilder;
import org.junit.Test;
@@ -129,6 +130,21 @@ public class BasicTestCases extends PolicyTestCase {
assertEquals("Header", el.getLocalName());
}
+ @Test
+ public void testPolicyContainingPrimitiveAssertionPreservesAttributes() throws Exception {
+ String text = "<p:Wrapper FooAtt=\"blah\" xmlns:p=\"urn:test\" "
+ + "xmlns:wsp=\"http://www.w3.org/ns/ws-policy\">"
+ + "<wsp:Policy><wsp:ExactlyOne><wsp:All/></wsp:ExactlyOne></wsp:Policy>"
+ + "</p:Wrapper>";
+
+ Assertion as = new XMLPrimitiveAssertionBuilder().build(getElementFromString(text),
+ policyEngine.getAssertionBuilderFactory());
+ assertNotNull(as);
+ assertTrue(as instanceof PolicyContainingPrimitiveAssertion);
+
+ assertEquals("blah", ((PolicyContainingPrimitiveAssertion)as).getAttribute(new QName("FooAtt")));
+ }
+
private Element getElementFromString(String s)
throws ParserConfigurationException, SAXException, IOException {
diff --git a/src/test/java/org/apache/neethi/PolicyNormalizationDoSTest.java b/src/test/java/org/apache/neethi/PolicyNormalizationDoSTest.java
index dfbf351..afdd817 100644
--- a/src/test/java/org/apache/neethi/PolicyNormalizationDoSTest.java
+++ b/src/test/java/org/apache/neethi/PolicyNormalizationDoSTest.java
@@ -19,6 +19,10 @@
package org.apache.neethi;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+
import javax.xml.namespace.QName;
import org.apache.neethi.builders.PrimitiveAssertion;
@@ -100,6 +104,18 @@ public class PolicyNormalizationDoSTest extends PolicyTestCase {
}
}
+ @Test
+ public void testUnknownPolicyContainingAssertionEnforcesGlobalAlternativeLimit() {
+ Policy policy = policyEngine.getPolicy(xmlStream(buildUnknownWrapperAggregationBypassPolicyXml(2, 13)));
+
+ try {
+ policy.normalize(registry, true);
+ fail("Expected RuntimeException due to global alternative limit");
+ } catch (RuntimeException ex) {
+ assertTrue(ex.getMessage().contains("maximum number of alternatives"));
+ }
+ }
+
// -----------------------------------------------------------------------
// Helpers
// -----------------------------------------------------------------------
@@ -166,4 +182,33 @@ public class PolicyNormalizationDoSTest extends PolicyTestCase {
return policy;
}
+ private static InputStream xmlStream(String xml) {
+ return new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
+ }
+
+ private static String buildUnknownWrapperAggregationBypassPolicyXml(int branchCount, int branchDepth) {
+ StringBuilder xml = new StringBuilder(4096);
+ xml.append("<wsp:Policy xmlns:wsp=\"http://www.w3.org/ns/ws-policy\" xmlns:p=\"urn:poc\">")
+ .append("<p:Wrapper>")
+ .append("<wsp:Policy>")
+ .append("<wsp:ExactlyOne>");
+
+ for (int branch = 0; branch < branchCount; branch++) {
+ xml.append("<wsp:All>");
+ for (int depth = 0; depth < branchDepth; depth++) {
+ xml.append("<wsp:ExactlyOne>")
+ .append("<wsp:All><p:A").append(branch).append('_').append(depth).append("/></wsp:All>")
+ .append("<wsp:All><p:B").append(branch).append('_').append(depth).append("/></wsp:All>")
+ .append("</wsp:ExactlyOne>");
+ }
+ xml.append("</wsp:All>");
+ }
+
+ xml.append("</wsp:ExactlyOne>")
+ .append("</wsp:Policy>")
+ .append("</p:Wrapper>")
+ .append("</wsp:Policy>");
+ return xml.toString();
+ }
+
}