Author: dkulp
Date: Tue Feb 8 18:32:53 2011
New Revision: 1068510
URL: http://svn.apache.org/viewvc?rev=1068510&view=rev
Log:
Fix spelling mistake in class name
Add preliminary support for WS-Policy 1.5
Add ignorable attribute to assertions (for 1.5)
Added:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingAssertion.java
(contents, props changed)
- copied, changed from r1068260,
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/NestedPrimitiveAssertion.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java
(contents, props changed)
- copied, changed from r1068260,
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimtiveAssertion.java
webservices/commons/trunk/modules/neethi/src/test/test-resources/normalized/test26.xml
(with props)
webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test26.xml
(with props)
Removed:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/NestedPrimitiveAssertion.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimtiveAssertion.java
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/All.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Assertion.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/ExactlyOne.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyEngine.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyReference.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/util/PolicyComparator.java
webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/NormalizeTest.java
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/AbstractPolicyOperator.java
Tue Feb 8 18:32:53 2011
@@ -57,7 +57,7 @@ public abstract class AbstractPolicyOper
}
protected static Policy normalize(Policy policy, PolicyRegistry reg,
boolean deep) {
- Policy result = new Policy();
+ Policy result = new Policy(policy.getNamespace());
String policyName = policy.getName();
if (policyName != null) {
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/All.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/All.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/All.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/All.java
Tue Feb 8 18:32:53 2011
@@ -50,14 +50,15 @@ public class All extends AbstractPolicyO
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
- String prefix = writer.getPrefix(Constants.URI_POLICY_NS);
+ String namespace = Constants.findPolicyNamespace(writer);
+ String prefix = writer.getPrefix(namespace);
if (prefix == null) {
- writer.writeStartElement(Constants.ATTR_WSP, Constants.ELEM_ALL,
Constants.URI_POLICY_NS);
- writer.writeNamespace(Constants.ATTR_WSP, Constants.URI_POLICY_NS);
- writer.setPrefix(Constants.ATTR_WSP, Constants.URI_POLICY_NS);
+ writer.writeStartElement(Constants.ATTR_WSP, Constants.ELEM_ALL,
namespace);
+ writer.writeNamespace(Constants.ATTR_WSP, namespace);
+ writer.setPrefix(Constants.ATTR_WSP, namespace);
} else {
- writer.writeStartElement(Constants.URI_POLICY_NS,
Constants.ELEM_ALL);
+ writer.writeStartElement(namespace, Constants.ELEM_ALL);
}
for (PolicyComponent policyComponent : getPolicyComponents()){
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Assertion.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Assertion.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Assertion.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Assertion.java
Tue Feb 8 18:32:53 2011
@@ -44,6 +44,14 @@ public interface Assertion extends Polic
*/
public boolean isOptional();
+
+ /**
+ * Returns true if this Assertion is ignorable. Returns false otherwise.
+ *
+ * @return true if the assertion is ignorable.
+ */
+ public boolean isIgnorable();
+
/**
* Serialize this Assertion into its XML infoset using XMLStreamWriter.
*/
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Constants.java
Tue Feb 8 18:32:53 2011
@@ -20,6 +20,8 @@
package org.apache.neethi;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
/**
* Constants contains the set of Constants that are used throughout the Neethi2
@@ -39,6 +41,7 @@ public class Constants {
public static final String ATTR_URI = "URI";
public static final String URI_POLICY_NS =
"http://schemas.xmlsoap.org/ws/2004/09/policy";
+ public static final String URI_POLICY_15_NS =
"http://www.w3.org/ns/ws-policy";
public static final String URI_WSU_NS =
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
@@ -60,9 +63,43 @@ public class Constants {
public static final short TYPE_ASSERTION = 0x5;
- public static final QName Q_ELEM_POLICY = new QName(
- Constants.URI_POLICY_NS, Constants.ELEM_POLICY,
Constants.ATTR_WSP);
+
+ public static final String ATTR_OPTIONAL = "Optional";
+ public static final String ATTR_IGNORABLE = "Ignorable";
+
+ public static final QName Q_ELEM_POLICY
+ = new QName(Constants.URI_POLICY_NS, Constants.ELEM_POLICY,
Constants.ATTR_WSP);
+ public static final QName Q_ELEM_POLICY_15
+ = new QName(Constants.URI_POLICY_15_NS, Constants.ELEM_POLICY,
Constants.ATTR_WSP);
+
+ public static final QName Q_ELEM_OPTIONAL_ATTR
+ = new QName(Constants.URI_POLICY_NS, "Optional", Constants.ATTR_WSP);
+ public static final QName Q_ELEM_OPTIONAL_15_ATTR
+ = new QName(Constants.URI_POLICY_15_NS, "Optional",
Constants.ATTR_WSP);
- public static final QName Q_ELEM_OPTIONAL_ATTR = new QName(
- Constants.URI_POLICY_NS, "Optional", Constants.ATTR_WSP);
+ public static final QName Q_ELEM_IGNORABLE_15_ATTR
+ = new QName(Constants.URI_POLICY_15_NS, "Ignorable",
Constants.ATTR_WSP);
+
+ public static boolean isInPolicyNS(QName q) {
+ String ns = q.getNamespaceURI();
+ return URI_POLICY_NS.equals(ns)
+ || URI_POLICY_15_NS.equals(ns);
+ }
+ public static boolean isPolicyElement(QName q) {
+ return isInPolicyNS(q) && ELEM_POLICY.equals(q.getLocalPart());
+ }
+ public static boolean isPolicyRef(QName q) {
+ return isInPolicyNS(q) && ELEM_POLICY_REF.equals(q.getLocalPart());
+ }
+
+ //Try and figure out if we are outputting 1.5 or 1.2 policy
+ //kind of a hack. Would be better to add a "version" to the serialize
method,
+ //but that would be incompatible
+ public static String findPolicyNamespace(XMLStreamWriter writer) throws
XMLStreamException {
+ String prefix = writer.getPrefix(Constants.URI_POLICY_15_NS);
+ if (prefix == null || "".equals(prefix)) {
+ return Constants.URI_POLICY_NS;
+ }
+ return Constants.URI_POLICY_15_NS;
+ }
}
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/ExactlyOne.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/ExactlyOne.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/ExactlyOne.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/ExactlyOne.java
Tue Feb 8 18:32:53 2011
@@ -32,16 +32,17 @@ import javax.xml.stream.XMLStreamWriter;
public class ExactlyOne extends AbstractPolicyOperator {
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
- String prefix = writer.getPrefix(Constants.URI_POLICY_NS);
+ String namespace = Constants.findPolicyNamespace(writer);
+ String prefix = writer.getPrefix(namespace);
if (prefix == null) {
writer.writeStartElement(Constants.ATTR_WSP,
- Constants.ELEM_EXACTLYONE, Constants.URI_POLICY_NS);
+ Constants.ELEM_EXACTLYONE, namespace);
writer.writeNamespace(Constants.ATTR_WSP,
- Constants.URI_POLICY_NS);
- writer.setPrefix(Constants.ATTR_WSP, Constants.URI_POLICY_NS);
+ namespace);
+ writer.setPrefix(Constants.ATTR_WSP, namespace);
} else {
- writer.writeStartElement(Constants.URI_POLICY_NS,
+ writer.writeStartElement(namespace,
Constants.ELEM_EXACTLYONE);
}
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/Policy.java
Tue Feb 8 18:32:53 2011
@@ -36,6 +36,17 @@ import javax.xml.stream.XMLStreamWriter;
public class Policy extends All {
private Map<QName, String> attributes = new HashMap<QName, String>();
+ private String namespace;
+
+ public Policy() {
+ }
+ public Policy(String ns) {
+ namespace = ns;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
/**
* Returns a Normalized version of self. If <tt>deep</tt> is set
@@ -74,7 +85,7 @@ public class Policy extends All {
*/
public Policy merge(Policy policy) {
- Policy result = new Policy();
+ Policy result = new Policy(namespace);
result.addPolicyComponents(getPolicyComponents());
result.addPolicyComponents(policy.getPolicyComponents());
return result;
@@ -84,9 +95,6 @@ public class Policy extends All {
* Throws an UnSupportedOpertionException. TODO for a next version.
*/
public Policy intersect(Policy policy) {
- //Policy p1 = normalize(true);
- //Policy p2 = policy.normalize(true);
-
throw new UnsupportedOperationException();
}
@@ -94,11 +102,15 @@ public class Policy extends All {
* Serializes the Policy to a XMLStreamWriter.
*/
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
- String wspPrefix = writer.getPrefix(Constants.URI_POLICY_NS);
+ String nspace = namespace;
+ if (namespace == null) {
+ nspace = Constants.findPolicyNamespace(writer);
+ }
+ String wspPrefix = writer.getPrefix(nspace);
if (wspPrefix == null) {
wspPrefix = Constants.ATTR_WSP;
- writer.setPrefix(wspPrefix, Constants.URI_POLICY_NS);
+ writer.setPrefix(wspPrefix, nspace);
}
String wsuPrefix = writer.getPrefix(Constants.URI_WSU_NS);
@@ -108,7 +120,7 @@ public class Policy extends All {
}
writer.writeStartElement(wspPrefix, Constants.ELEM_POLICY,
- Constants.URI_POLICY_NS);
+ nspace);
QName key;
@@ -156,7 +168,7 @@ public class Policy extends All {
}
// writes xmlns:wsp=".."
- writer.writeNamespace(wspPrefix, Constants.URI_POLICY_NS);
+ writer.writeNamespace(wspPrefix, nspace);
String prefiX;
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyEngine.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyEngine.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyEngine.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyEngine.java
Tue Feb 8 18:32:53 2011
@@ -42,15 +42,6 @@ import org.apache.commons.logging.LogFac
public class PolicyEngine {
private static final Log log = LogFactory.getLog(PolicyEngine.class);
- public static final String POLICY_NAMESPACE =
"http://schemas.xmlsoap.org/ws/2004/09/policy";
-
- public static final String POLICY = "Policy";
-
- public static final String EXACTLY_ONE = "ExactlyOne";
-
- public static final String ALL = "All";
-
- public static final String POLICY_REF = "PolicyReference";
private static AssertionBuilderFactory factory = new
AssertionBuilderFactory();
@@ -134,10 +125,7 @@ public class PolicyEngine {
*/
public static PolicyReference getPolicyReference(OMElement element) {
- if (!(Constants.URI_POLICY_NS.equals(element.getNamespace()
- .getNamespaceURI()) && Constants.ELEM_POLICY_REF.equals(element
- .getLocalName()))) {
-
+ if (!Constants.isPolicyRef(element.getQName())) {
throw new RuntimeException(
"Specified element is not a <wsp:PolicyReference .. />
element");
}
@@ -150,7 +138,8 @@ public class PolicyEngine {
}
private static Policy getPolicyOperator(OMElement element) {
- return (Policy) processOperationElement(element, new Policy());
+ String ns = element.getNamespace().getNamespaceURI();
+ return (Policy) processOperationElement(element, new Policy(ns));
}
private static ExactlyOne getExactlyOneOperator(OMElement element) {
@@ -207,28 +196,19 @@ public class PolicyEngine {
log.debug("Problem occurred while logging trace " + t);
}
}
- } else if
(Constants.URI_POLICY_NS.equals(childElement.getNamespace()
- .getNamespaceURI())) {
-
+ } else if (Constants.isInPolicyNS(childElement.getQName())) {
if (Constants.ELEM_POLICY.equals(childElement.getLocalName()))
{
- operator
-
.addPolicyComponent(getPolicyOperator(childElement));
-
+
operator.addPolicyComponent(getPolicyOperator(childElement));
} else if (Constants.ELEM_EXACTLYONE.equals(childElement
.getLocalName())) {
- operator
-
.addPolicyComponent(getExactlyOneOperator(childElement));
-
+
operator.addPolicyComponent(getExactlyOneOperator(childElement));
} else if (Constants.ELEM_ALL.equals(childElement
.getLocalName())) {
operator.addPolicyComponent(getAllOperator(childElement));
-
} else if (Constants.ELEM_POLICY_REF.equals(childElement
.getLocalName())) {
- operator
-
.addPolicyComponent(getPolicyReference(childElement));
+
operator.addPolicyComponent(getPolicyReference(childElement));
}
-
} else {
operator.addPolicyComponent(factory.build(childElement));
}
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyReference.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyReference.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyReference.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/PolicyReference.java
Tue Feb 8 18:32:53 2011
@@ -123,16 +123,16 @@ public class PolicyReference implements
}
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
-
- String wspPrefix = writer.getPrefix(Constants.URI_POLICY_NS);
+ String namespace = Constants.findPolicyNamespace(writer);
+ String wspPrefix = writer.getPrefix(namespace);
if (wspPrefix == null) {
wspPrefix = Constants.ATTR_WSP;
- writer.setPrefix(wspPrefix, Constants.URI_POLICY_NS);
+ writer.setPrefix(wspPrefix, namespace);
}
- writer.writeStartElement(wspPrefix, Constants.ELEM_POLICY_REF,
Constants.URI_POLICY_NS);
- writer.writeNamespace(Constants.ATTR_WSP, Constants.URI_POLICY_NS);
+ writer.writeStartElement(wspPrefix, Constants.ELEM_POLICY_REF,
namespace);
+ writer.writeNamespace(Constants.ATTR_WSP, namespace);
writer.writeAttribute(Constants.ATTR_URI, getURI());
writer.writeEndElement();
@@ -141,30 +141,27 @@ public class PolicyReference implements
public OMElement getRemoteReferedElement(String uri){
OMElement documentElement = null;
- try{
-
- //create java.net URL pointing to remote resource
- URL url = new URL(uri);
- URLConnection connection = url.openConnection();
- connection.setDoInput(true);
-
- //create stax parser with the url content
- XMLStreamReader parser = XMLInputFactory.newInstance().
-
createXMLStreamReader(connection.getInputStream());
-
- //get the root element (in this case the envelope)
- StAXOMBuilder builder = new StAXOMBuilder(parser);
- documentElement = builder.getDocumentElement();
+ try {
+ //create java.net URL pointing to remote resource
+ URL url = new URL(uri);
+ URLConnection connection = url.openConnection();
+ connection.setDoInput(true);
+
+ //create stax parser with the url content
+ XMLStreamReader parser = XMLInputFactory.newInstance().
+ createXMLStreamReader(connection.getInputStream());
- }catch(XMLStreamException se){
+ //get the root element (in this case the envelope)
+ StAXOMBuilder builder = new StAXOMBuilder(parser);
+ documentElement = builder.getDocumentElement();
+ } catch(XMLStreamException se) {
throw new RuntimeException("Bad policy content: " + uri);
- }catch(MalformedURLException mue){
+ } catch(MalformedURLException mue) {
throw new RuntimeException("Malformed uri: " + uri);
- }catch(IOException ioe){
+ } catch(IOException ioe) {
throw new RuntimeException("Cannot reach remote resource: " +
uri);
- }
-
- return documentElement;
+ }
+ return documentElement;
}
@@ -178,6 +175,6 @@ public class PolicyReference implements
//call the policy engine with already extracted content
policy = PolicyEngine.getPolicy(policyElement);
- return policy;
+ return policy;
}
}
Copied:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingAssertion.java
(from r1068260,
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/NestedPrimitiveAssertion.java)
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingAssertion.java?p2=webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingAssertion.java&p1=webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/NestedPrimitiveAssertion.java&r1=1068260&r2=1068510&rev=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/NestedPrimitiveAssertion.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingAssertion.java
Tue Feb 8 18:32:53 2011
@@ -45,12 +45,12 @@ import org.apache.neethi.PolicyOperator;
* of type Policy (as does for examples the wsam:Addressing assertion).
*
*/
-public class NestedPrimitiveAssertion extends PrimitiveAssertion {
+public class PolicyContainingAssertion extends PrimitiveAssertion {
private Policy nested;
- public NestedPrimitiveAssertion(QName name, boolean optional, Policy p) {
- super(name, optional);
+ public PolicyContainingAssertion(QName name, boolean optional, boolean
ignorable, Policy p) {
+ super(name, optional, ignorable);
this.nested = p;
}
@@ -65,13 +65,14 @@ public class NestedPrimitiveAssertion ex
if (isOptional()) {
ea.addPolicyComponent(new All());
}
- // for all alternatives in normalised nested policy
+ // for all alternatives in normalized nested policy
Iterator<List<PolicyComponent>> alternatives =
normalisedNested.getAlternatives();
while (alternatives.hasNext()) {
All all = new All();
List<PolicyComponent> alternative = alternatives.next();
Policy n = new Policy();
- NestedPrimitiveAssertion a = new
NestedPrimitiveAssertion(getName(), false, nested);
+ PolicyContainingAssertion a
+ = new PolicyContainingAssertion(getName(), false, ignorable,
nested);
ExactlyOne nea = new ExactlyOne();
n.addPolicyComponent(nea);
All na = new All();
@@ -88,21 +89,24 @@ public class NestedPrimitiveAssertion ex
if (!super.equal(policyComponent)) {
return false;
}
- NestedPrimitiveAssertion other =
(NestedPrimitiveAssertion)policyComponent;
+ PolicyContainingAssertion other =
(PolicyContainingAssertion)policyComponent;
return getPolicy().equal(other.getPolicy());
}
- protected void setPolicy(Policy n) {
+ public void setPolicy(Policy n) {
nested = n;
}
public Policy getPolicy() {
return nested;
}
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+ String namespace = Constants.findPolicyNamespace(writer);
writer.writeStartElement(name.getNamespaceURI(), name.getLocalPart());
if (optional) {
-
writer.writeAttribute(Constants.Q_ELEM_OPTIONAL_ATTR.getNamespaceURI(),
-
Constants.Q_ELEM_OPTIONAL_ATTR.getLocalPart(), "true");
+ writer.writeAttribute(namespace, Constants.ATTR_OPTIONAL, "true");
+ }
+ if (ignorable) {
+ writer.writeAttribute(namespace, Constants.ATTR_IGNORABLE, "true");
}
nested.serialize(writer);
writer.writeEndElement();
Propchange:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingAssertion.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PolicyContainingAssertion.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/PrimitiveAssertion.java
Tue Feb 8 18:32:53 2011
@@ -40,6 +40,7 @@ public class PrimitiveAssertion implemen
protected QName name;
protected boolean optional;
+ protected boolean ignorable;
public PrimitiveAssertion() {
this((QName)null);
@@ -53,6 +54,11 @@ public class PrimitiveAssertion implemen
name = n;
optional = o;
}
+ public PrimitiveAssertion(QName n, boolean o, boolean i) {
+ name = n;
+ optional = o;
+ ignorable = i;
+ }
public String toString() {
return name.toString();
@@ -83,6 +89,13 @@ public class PrimitiveAssertion implemen
public void setOptional(boolean o) {
optional = o;
}
+ public boolean isIgnorable() {
+ return ignorable;
+ }
+
+ public void setIgnorable(boolean i) {
+ ignorable = i;
+ }
public PolicyComponent normalize() {
if (isOptional()) {
@@ -102,16 +115,19 @@ public class PrimitiveAssertion implemen
}
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
+ String namespace = Constants.findPolicyNamespace(writer);
writer.writeEmptyElement(name.getNamespaceURI(), name.getLocalPart());
if (optional) {
-
writer.writeAttribute(Constants.Q_ELEM_OPTIONAL_ATTR.getNamespaceURI(),
-
Constants.Q_ELEM_OPTIONAL_ATTR.getLocalPart(), "true");
+ writer.writeAttribute(namespace, Constants.ATTR_OPTIONAL, "true");
+ }
+ if (ignorable) {
+ writer.writeAttribute(namespace, Constants.ATTR_IGNORABLE, "true");
}
writer.writeEndElement();
}
protected Assertion cloneMandatory() {
- return new PrimitiveAssertion(name, false);
+ return new PrimitiveAssertion(name, false, ignorable);
}
public Policy getPolicy() {
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XMLPrimitiveAssertionBuilder.java
Tue Feb 8 18:32:53 2011
@@ -31,7 +31,7 @@ import org.apache.neethi.Constants;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.neethi.builders.AssertionBuilder;
-import org.apache.neethi.builders.NestedPrimitiveAssertion;
+import org.apache.neethi.builders.PolicyContainingAssertion;
public class XMLPrimitiveAssertionBuilder implements AssertionBuilder {
@@ -39,19 +39,30 @@ public class XMLPrimitiveAssertionBuilde
throws IllegalArgumentException {
Iterator it = element.getChildElements();
OMElement el = it.hasNext() ? (OMElement)it.next() : null;
- if (!it.hasNext() && el != null &&
el.getQName().equals(Constants.Q_ELEM_POLICY)) {
+ if (!it.hasNext() && el != null &&
Constants.isPolicyElement(el.getQName())) {
OMAttribute attribute = element
.getAttribute(Constants.Q_ELEM_OPTIONAL_ATTR);
- boolean isOptional = false;
+ if (attribute == null) {
+ attribute = element
+ .getAttribute(Constants.Q_ELEM_OPTIONAL_15_ATTR);
+ }
+ boolean optional = false;
+ if (attribute != null) {
+ optional = (new Boolean(attribute.getAttributeValue())
+ .booleanValue());
+ }
+ attribute = element
+ .getAttribute(Constants.Q_ELEM_IGNORABLE_15_ATTR);
+ boolean ignorable = false;
if (attribute != null) {
- isOptional = (new Boolean(attribute.getAttributeValue())
+ ignorable = (new Boolean(attribute.getAttributeValue())
.booleanValue());
}
Policy policy = PolicyEngine.getPolicy(el);
- return new NestedPrimitiveAssertion(element.getQName(),
isOptional, policy);
+ return new PolicyContainingAssertion(element.getQName(), optional,
ignorable, policy);
}
- return new XmlPrimtiveAssertion(element);
+ return new XmlPrimitiveAssertion(element);
}
public QName[] getKnownElements() {
Copied:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java
(from r1068260,
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimtiveAssertion.java)
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java?p2=webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java&p1=webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimtiveAssertion.java&r1=1068260&r2=1068510&rev=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimtiveAssertion.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java
Tue Feb 8 18:32:53 2011
@@ -39,11 +39,12 @@ import org.apache.neethi.PolicyRegistry;
* assertion from that OMElement.
*
*/
-public class XmlPrimtiveAssertion implements Assertion {
+public class XmlPrimitiveAssertion implements Assertion {
OMElement element;
- boolean isOptional;
+ boolean optional;
+ boolean ignorable;
/**
* Constructs a XmlPrimitiveAssertion from an OMElement.
@@ -51,11 +52,13 @@ public class XmlPrimtiveAssertion implem
* @param element
* the OMElement from which the XmlAssertion is constructed
*/
- public XmlPrimtiveAssertion(OMElement element) {
+ public XmlPrimitiveAssertion(OMElement element) {
setValue(element);
setOptionality(element);
+ setIgnorability(element);
}
+
/**
* Returns the QName of the wrapped OMElement.
*/
@@ -87,7 +90,14 @@ public class XmlPrimtiveAssertion implem
* assertion, is optional.
*/
public boolean isOptional() {
- return isOptional;
+ return optional;
+ }
+ /**
+ * Returns <tt>true</tt> if the wrapped element that assumed to be an
+ * assertion, is ignorable.
+ */
+ public boolean isIgnorable() {
+ return ignorable;
}
/**
@@ -95,16 +105,19 @@ public class XmlPrimtiveAssertion implem
* assumed to be an assertion.
*/
public PolicyComponent normalize() {
- if (isOptional) {
+ if (optional) {
Policy policy = new Policy();
ExactlyOne exactlyOne = new ExactlyOne();
All all = new All();
OMElement omElement = element.cloneOMElement();
- omElement.removeAttribute(omElement
- .getAttribute(Constants.Q_ELEM_OPTIONAL_ATTR));
- all.addPolicyComponent(new XmlPrimtiveAssertion(omElement));
+ OMAttribute att =
omElement.getAttribute(Constants.Q_ELEM_OPTIONAL_ATTR);
+ if (att == null) {
+ att =
omElement.getAttribute(Constants.Q_ELEM_OPTIONAL_15_ATTR);
+ }
+ omElement.removeAttribute(att);
+ all.addPolicyComponent(new XmlPrimitiveAssertion(omElement));
exactlyOne.addPolicyComponent(all);
exactlyOne.addPolicyComponent(new All());
@@ -143,13 +156,29 @@ public class XmlPrimtiveAssertion implem
private void setOptionality(OMElement element) {
OMAttribute attribute = element
.getAttribute(Constants.Q_ELEM_OPTIONAL_ATTR);
+ if (attribute == null) {
+ attribute = element
+ .getAttribute(Constants.Q_ELEM_OPTIONAL_15_ATTR);
+ }
if (attribute != null) {
- this.isOptional = (new Boolean(attribute.getAttributeValue())
+ this.optional = (new Boolean(attribute.getAttributeValue())
.booleanValue());
} else {
- this.isOptional = false;
+ this.optional = false;
+ }
+ }
+ private void setIgnorability(OMElement element2) {
+ OMAttribute attribute = element
+ .getAttribute(Constants.Q_ELEM_IGNORABLE_15_ATTR);
+ if (attribute != null) {
+ this.ignorable = (new Boolean(attribute.getAttributeValue())
+ .booleanValue());
+
+ } else {
+ this.ignorable = false;
}
+
}
public boolean equal(PolicyComponent policyComponent) {
Propchange:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/builders/xml/XmlPrimitiveAssertion.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/util/PolicyComparator.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/util/PolicyComparator.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/util/PolicyComparator.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/main/java/org/apache/neethi/util/PolicyComparator.java
Tue Feb 8 18:32:53 2011
@@ -57,13 +57,14 @@ public class PolicyComparator {
}
} else {
-
if (arg2.getName() != null) {
return false;
}
}
-
-
+ if (arg1.getNamespace() != null
+ && !arg1.getNamespace().equals(arg2.getNamespace())) {
+ return false;
+ }
// check Id attributes of each policies
if (arg1.getId() != null) {
Modified:
webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/NormalizeTest.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/NormalizeTest.java?rev=1068510&r1=1068509&r2=1068510&view=diff
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/NormalizeTest.java
(original)
+++
webservices/commons/trunk/modules/neethi/src/test/java/org/apache/neethi/NormalizeTest.java
Tue Feb 8 18:32:53 2011
@@ -38,7 +38,7 @@ public class NormalizeTest extends Polic
String r1, r2;
Policy p1, p2;
- for (int i =1; i < 26; i++) {
+ for (int i =1; i < 27; i++) {
r1 = "samples" + File.separator + "test" + i + ".xml";
r2 = "normalized" + File.separator + "test" + i + ".xml";
Added:
webservices/commons/trunk/modules/neethi/src/test/test-resources/normalized/test26.xml
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/test/test-resources/normalized/test26.xml?rev=1068510&view=auto
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/test/test-resources/normalized/test26.xml
(added)
+++
webservices/commons/trunk/modules/neethi/src/test/test-resources/normalized/test26.xml
Tue Feb 8 18:32:53 2011
@@ -0,0 +1,32 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy">
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sec:SecurityToken
xmlns:sec="http://schemas.xmlsoap.org/ws/2002/12/secext">
+ <sec:TokenType
xmlns:sec="http://schemas.xmlsoap.org/ws/2002/12/secext">sec:X509v3</sec:TokenType>
+ </sec:SecurityToken>
+ <sec:Integrity wsp:Ignorable="true"
xmlns:sec="http://schemas.xmlsoap.org/ws/2002/12/secext">
+ <sec:MessageParts
xmlns:sec="http://schemas.xmlsoap.org/ws/2002/12/secext"
Dialect="http://schemas.xmlsoap.org/ws/2002/12/wsse#soap">wsp:Body()</sec:MessageParts>
+ </sec:Integrity>
+ <ans1:SecurityHeader
xmlns:ans1="http://schemas.xmlsoap.org/ws/2002/12/secext"
MustManifestEncryption="true" MustPrepend="true" />
+ </wsp:All>
+ </wsp:ExactlyOne>
+</wsp:Policy>
\ No newline at end of file
Propchange:
webservices/commons/trunk/modules/neethi/src/test/test-resources/normalized/test26.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
webservices/commons/trunk/modules/neethi/src/test/test-resources/normalized/test26.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
webservices/commons/trunk/modules/neethi/src/test/test-resources/normalized/test26.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test26.xml
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test26.xml?rev=1068510&view=auto
==============================================================================
---
webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test26.xml
(added)
+++
webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test26.xml
Tue Feb 8 18:32:53 2011
@@ -0,0 +1,30 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<wsp:Policy xmlns:wsp="http://www.w3.org/ns/ws-policy"
xmlns:sec="http://schemas.xmlsoap.org/ws/2002/12/secext" ><!-- 1G -->
+ <wsp:All>
+ <sec:SecurityToken>
+ <sec:TokenType>sec:X509v3</sec:TokenType>
+ </sec:SecurityToken>
+ <sec:Integrity wsp:Ignorable="true">
+ <sec:MessageParts
Dialect="http://schemas.xmlsoap.org/ws/2002/12/wsse#soap"
>wsp:Body()</sec:MessageParts>
+ </sec:Integrity>
+ <sec:SecurityHeader MustPrepend="true" MustManifestEncryption="true" />
+ </wsp:All>
+</wsp:Policy>
\ No newline at end of file
Propchange:
webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test26.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test26.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
webservices/commons/trunk/modules/neethi/src/test/test-resources/samples/test26.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml