Author: maeste
Date: 2007-05-03 18:43:23 -0400 (Thu, 03 May 2007)
New Revision: 2956
Added:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/util/
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/util/PrimitiveAssertionWriter.java
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/AssertionDeployer.java
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/PolicyDeployer.java
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/WSSecurityAssertionDeployer.java
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaExtension.java
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/MetaDataBuilder.java
Log:
Use of apche policy lib to represent policy in Unified metadata
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/AssertionDeployer.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/AssertionDeployer.java 2007-05-03
19:18:24 UTC (rev 2955)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/AssertionDeployer.java 2007-05-03
22:43:23 UTC (rev 2956)
@@ -1,10 +1,10 @@
package org.jboss.ws.extensions.policy.deployer;
-import org.jboss.ws.extensions.policy.PolicyAssertion;
+import org.apache.ws.policy.PrimitiveAssertion;
import org.jboss.ws.extensions.policy.deployer.exceptions.UnsupportedAssertion;
import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
public interface AssertionDeployer
{
- public void deploy(PolicyAssertion assertion, ExtensibleMetaData extMetaData) throws
UnsupportedAssertion;
+ public void deploy(PrimitiveAssertion assertion, ExtensibleMetaData extMetaData)
throws UnsupportedAssertion;
}
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/PolicyDeployer.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/PolicyDeployer.java 2007-05-03
19:18:24 UTC (rev 2955)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/PolicyDeployer.java 2007-05-03
22:43:23 UTC (rev 2956)
@@ -22,12 +22,14 @@
package org.jboss.ws.extensions.policy.deployer;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
-import org.jboss.ws.extensions.policy.Policy;
-import org.jboss.ws.extensions.policy.PolicyAlternative;
-import org.jboss.ws.extensions.policy.PolicyAssertion;
-import org.jboss.ws.extensions.policy.PolicyFactory;
+import org.apache.ws.policy.AndCompositeAssertion;
+import org.apache.ws.policy.Assertion;
+import org.apache.ws.policy.Policy;
+import org.apache.ws.policy.PrimitiveAssertion;
+import org.apache.ws.policy.XorCompositeAssertion;
import org.jboss.ws.extensions.policy.deployer.exceptions.UnsupportedAlternative;
import org.jboss.ws.extensions.policy.deployer.exceptions.UnsupportedAssertion;
import org.jboss.ws.extensions.policy.deployer.exceptions.UnsupportedPolicy;
@@ -74,14 +76,17 @@
public Policy deployServerside(Policy policy, ExtensibleMetaData extMetaData) throws
UnsupportedPolicy
{
- Policy returnedPolicy =
PolicyFactory.newInstance().createPolicy(policy.toElement());
- returnedPolicy.clearPolicyAlternatives();
- for (PolicyAlternative alternative : policy.getPolicyAlternatives())
+ Policy returnedPolicy = (Policy) policy.normalize();
+ ((XorCompositeAssertion) returnedPolicy.getTerms().get(0)).getTerms().clear();
+ Policy originalPolicy = (Policy) policy.normalize();
+// in normal form we have just one wsp:ExactlyOne elemnet containg unbounded wsp:All
(alternative)
+ XorCompositeAssertion exactlyOne = (XorCompositeAssertion)
originalPolicy.getTerms().get(0);
+ for (AndCompositeAssertion alternative: (List<AndCompositeAssertion>)
exactlyOne.getTerms() )
{
try
{
deployAlternativeServerSide(alternative,extMetaData);
- returnedPolicy.addPolicyAlternative(alternative);
+ ((XorCompositeAssertion)
returnedPolicy.getTerms().get(0)).addTerm(alternative);
}
catch (UnsupportedAlternative e)
{
@@ -89,7 +94,7 @@
}
}
- if (returnedPolicy.getPolicyAlternatives().size() == 0)
+ if (((XorCompositeAssertion) returnedPolicy.getTerms().get(0)).getTerms().size() ==
0)
{
throw new UnsupportedPolicy();
}
@@ -101,25 +106,43 @@
}
- private void deployAlternativeServerSide(PolicyAlternative alternative,
ExtensibleMetaData extMetaData) throws UnsupportedAlternative
+ private void deployAlternativeServerSide(AndCompositeAssertion alternative,
ExtensibleMetaData extMetaData) throws UnsupportedAlternative
{
- for (PolicyAssertion assertion : alternative.getPolicyAssertions())
+ for (Assertion assertion : (List<Assertion>) alternative.getTerms())
{
+
try
{
- deployAssertionServerSide(assertion,extMetaData);
+ if (assertion instanceof PrimitiveAssertion)
+ {
+ deployAssertionServerSide((PrimitiveAssertion) assertion,extMetaData);
+ }
+ else if (assertion instanceof Policy) //inner policy to be verified
+ {
+ deployServerside((Policy) assertion, extMetaData);
+ }
+ else
+ {
+ throw new UnsupportedAlternative();
+ }
+
}
catch (UnsupportedAssertion e)
{
//If there is al least one unsupported assertion the alternative isn't
supported
throw new UnsupportedAlternative();
}
+ catch (UnsupportedPolicy ep)
+ {
+ //If there is al least one unsupported assertion the alternative isn't
supported
+ throw new UnsupportedAlternative();
+ }
}
}
- private void deployAssertionServerSide(PolicyAssertion assertion, ExtensibleMetaData
extMetaData) throws UnsupportedAssertion
+ private void deployAssertionServerSide(PrimitiveAssertion assertion,
ExtensibleMetaData extMetaData) throws UnsupportedAssertion
{
- AssertionDeployer deployer = getDomainDeployerInstance(assertion.getNameSpace());
+ AssertionDeployer deployer =
getDomainDeployerInstance(assertion.getName().getNamespaceURI());
deployer.deploy(assertion,extMetaData);
}
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/WSSecurityAssertionDeployer.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/WSSecurityAssertionDeployer.java 2007-05-03
19:18:24 UTC (rev 2955)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/WSSecurityAssertionDeployer.java 2007-05-03
22:43:23 UTC (rev 2956)
@@ -1,7 +1,14 @@
package org.jboss.ws.extensions.policy.deployer;
+import java.io.StringWriter;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.ws.policy.PrimitiveAssertion;
import org.jboss.ws.extensions.policy.PolicyAssertion;
import org.jboss.ws.extensions.policy.deployer.exceptions.UnsupportedAssertion;
+import org.jboss.ws.extensions.policy.deployer.util.PrimitiveAssertionWriter;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
import org.jboss.ws.metadata.wsse.WSSecurityConfigFactory;
@@ -12,8 +19,9 @@
public class WSSecurityAssertionDeployer implements AssertionDeployer
{
- public void deploy(PolicyAssertion assertion, ExtensibleMetaData extMetaData) throws
UnsupportedAssertion
+ public void deploy(PrimitiveAssertion assertion, ExtensibleMetaData extMetaData)
throws UnsupportedAssertion
{
+ StringWriter writer = new StringWriter();
if (extMetaData instanceof EndpointMetaData)
{
EndpointMetaData ep = (EndpointMetaData) extMetaData;
@@ -21,15 +29,18 @@
WSSecurityConfiguration securityConfiguration;
try
{
+ //GET XML of security assertion
+ PrimitiveAssertionWriter.newInstance().writePrimitiveAssertion(assertion,
writer);
+
//Set security configuration
- securityConfiguration =
WSSecurityOMFactory.newInstance().parse(assertion.toXMLString(true));
+ securityConfiguration =
WSSecurityOMFactory.newInstance().parse(writer.toString());
WSSecurityConfigFactory.newInstance().initKeystorePath(ep.getRootFile(),
securityConfiguration);
ep.getServiceMetaData().setSecurityConfiguration(securityConfiguration);
//set up handler chain as defined in standard file
ep.setConfigName("Standard WSSecurity Endpoint");
ep.initEndpointConfig();
}
- catch (JBossXBException e)
+ catch (Exception e)
{
throw new UnsupportedAssertion();
}
Added:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/util/PrimitiveAssertionWriter.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/util/PrimitiveAssertionWriter.java
(rev 0)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/util/PrimitiveAssertionWriter.java 2007-05-03
22:43:23 UTC (rev 2956)
@@ -0,0 +1,88 @@
+
+package org.jboss.ws.extensions.policy.deployer.util;
+
+import java.io.StringWriter;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.ws.policy.PrimitiveAssertion;
+
+
+public class PrimitiveAssertionWriter {
+
+ private int num = 1;
+
+ PrimitiveAssertionWriter() {
+ }
+
+ public static PrimitiveAssertionWriter newInstance()
+ {
+ return new PrimitiveAssertionWriter();
+ }
+
+ public void writePrimitiveAssertion(PrimitiveAssertion assertion,
+ StringWriter stringWriter) throws XMLStreamException {
+
+ XMLStreamWriter writer =
XMLOutputFactory.newInstance().createXMLStreamWriter(stringWriter);
+
+ QName qname = assertion.getName();
+
+ String writerPrefix = writer.getPrefix(qname.getNamespaceURI());
+ if (writerPrefix != null) {
+ writer.writeStartElement(qname.getNamespaceURI(), qname
+ .getLocalPart());
+ } else {
+ String prefix = (qname.getPrefix() != null) ? qname.getPrefix()
+ : generateNamespace();
+ writer.writeStartElement(prefix, qname.getLocalPart(), qname
+ .getNamespaceURI());
+ writer.writeNamespace(prefix, qname.getNamespaceURI());
+ writer.setPrefix(prefix, qname.getNamespaceURI());
+
+ }
+
+ Hashtable attributes = assertion.getAttributes();
+ writeAttributes(attributes, writer);
+
+ String text = (String) assertion.getStrValue();
+ if (text != null) {
+ writer.writeCharacters(text);
+ }
+
+ //A Primitive assertion can't have terms----to be verified
+// List terms = assertion.getTerms();
+// writeTerms(terms, writer);
+
+ writer.writeEndElement();
+ }
+
+
+
+ private void writeAttributes(Hashtable attributes, XMLStreamWriter writer)
+ throws XMLStreamException {
+
+ Iterator iterator = attributes.keySet().iterator();
+ while (iterator.hasNext()) {
+ QName qname = (QName) iterator.next();
+ String value = (String) attributes.get(qname);
+
+ String prefix = qname.getPrefix();
+ if (prefix != null) {
+ writer.writeAttribute(prefix, qname.getNamespaceURI(), qname
+ .getLocalPart(), value);
+ } else {
+ writer.writeAttribute(qname.getNamespaceURI(), qname
+ .getLocalPart(), value);
+ }
+ }
+ }
+
+ private String generateNamespace() {
+ return "ns" + num++;
+ }
+}
\ No newline at end of file
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaExtension.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaExtension.java 2007-05-03
19:18:24 UTC (rev 2955)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaExtension.java 2007-05-03
22:43:23 UTC (rev 2956)
@@ -1,7 +1,7 @@
package org.jboss.ws.extensions.policy.metadata;
-import org.jboss.ws.extensions.policy.Policy;
+import org.apache.ws.policy.Policy;
import org.jboss.ws.metadata.umdm.MetaDataExtension;
public class PolicyMetaExtension extends MetaDataExtension
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/MetaDataBuilder.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/MetaDataBuilder.java 2007-05-03
19:18:24 UTC (rev 2955)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/MetaDataBuilder.java 2007-05-03
22:43:23 UTC (rev 2956)
@@ -44,6 +44,9 @@
import javax.xml.namespace.QName;
import javax.xml.ws.addressing.AddressingProperties;
+import org.apache.ws.policy.Policy;
+import org.apache.ws.policy.util.DOMPolicyReader;
+import org.apache.ws.policy.util.PolicyFactory;
import org.jboss.logging.Logger;
import org.jboss.ws.Constants;
import org.jboss.ws.WSException;
@@ -58,8 +61,6 @@
import org.jboss.ws.extensions.eventing.EventingUtils;
import org.jboss.ws.extensions.eventing.deployment.EventingEndpoint;
import org.jboss.ws.extensions.eventing.metadata.EventingEpMetaExt;
-import org.jboss.ws.extensions.policy.Policy;
-import org.jboss.ws.extensions.policy.PolicyFactory;
import org.jboss.ws.extensions.policy.deployer.PolicyDeployer;
import org.jboss.ws.extensions.policy.deployer.exceptions.UnsupportedPolicy;
import org.jboss.ws.extensions.policy.metadata.PolicyMetaExtension;
@@ -469,12 +470,12 @@
protected void processPolicyMetaDataExtension(EndpointMetaData epMetaData,
WSDLDefinitions wsdlDefinitions)
{
//Collect all policies defined in our wsdl definitions
- PolicyFactory factory = PolicyFactory.newInstance();
+ DOMPolicyReader reader = (DOMPolicyReader)
PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER);
Map<String,Policy> localPolicyElementsMap = new
HashMap<String,Policy>();
for (WSDLExtensibilityElement policyElement :
wsdlDefinitions.getExtensibilityElements(Constants.WSDL_ELEMENT_POLICY))
{
- Policy policy = factory.createPolicy(policyElement.getElement());
- localPolicyElementsMap.put(policy.getID(), policy);
+ Policy policy = reader.readPolicy(policyElement.getElement());
+ localPolicyElementsMap.put(policy.getId(), policy);
}
WSDLService wsdlService =
wsdlDefinitions.getService(epMetaData.getServiceMetaData().getServiceName().getLocalPart());
@@ -501,23 +502,23 @@
{
if (policyReferences != null && policyReferences.size() != 0 &&
extMetaData instanceof ServerEndpointMetaData)
{
- PolicyFactory factory = PolicyFactory.newInstance();
+ DOMPolicyReader reader = (DOMPolicyReader)
PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER);
for (WSDLExtensibilityElement element : policyReferences)
{
- boolean local = true;
- String uri = element.getElement().getAttribute("URI");
- //TODO!!!
- //process uri
- if (local)
- {
- Policy policy = localPolicies.get(uri.substring(1)); //get rid of
'#'
- //clone the policy before asking for deployment
- deployPolicy(factory.createPolicy(policy.toElement()),extMetaData);
- }
- else
- {
- //TODO!!! get the policy definition, create the policy and deploy it
- }
+// boolean local = true;
+// String uri = element.getElement().getAttribute("URI");
+// //TODO!!!
+// //process uri
+// if (local)
+// {
+// Policy policy = localPolicies.get(uri.substring(1)); //get rid of
'#'
+// //clone the policy before asking for deployment
+ deployPolicy((Policy)
reader.readPolicyReference(element.getElement()).normalize(),extMetaData);
+// }
+// else
+// {
+// //TODO!!! get the policy definition, create the policy and deploy it
+// }
}
}
}
@@ -535,7 +536,7 @@
{
if (log.isDebugEnabled())
{
- log.debug("Policy Not supported:" + policy.toXMLString(true));
+ log.debug("Policy Not supported:" + policy.getPolicyURI());
}
}
}