Author: maeste
Date: 2007-05-08 04:00:49 -0400 (Tue, 08 May 2007)
New Revision: 2999
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/WSSecurityAssertionDeployer.java
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/wsse/WSSecurityOMFactory.java
branches/JBWS-856/jbossws-tests/src/resources/jaxws/samples/wssecuritypolicy/PolicyAttachmentFragment.wsdl
Log:
Policy deployment seems to work in sample. Need to understand what is happening
ws-security config after deployment of specif assertion
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-07
21:57:25 UTC (rev 2998)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/PolicyDeployer.java 2007-05-08
08:00:49 UTC (rev 2999)
@@ -21,18 +21,29 @@
*/
package org.jboss.ws.extensions.policy.deployer;
+import java.io.ByteArrayOutputStream;
+import java.io.StringWriter;
+import java.nio.ByteOrder;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+
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.apache.ws.policy.util.PolicyFactory;
+import org.apache.ws.policy.util.PolicyWriter;
+import org.jboss.logging.Logger;
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;
+import org.jboss.ws.metadata.builder.MetaDataBuilder;
import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
@@ -44,14 +55,16 @@
*/
public class PolicyDeployer
{
-
+ private final static Logger log = Logger.getLogger(PolicyDeployer.class);
private static PolicyDeployer me;
private Map<String, Class> domainDeployerMap = new HashMap<String,
Class>();
static {
me = new PolicyDeployer();
-
me.domainDeployerMap.put("http://www.jboss.com/ws-security/config&qu...;
+
me.domainDeployerMap.put("http://www.jboss.com/ws-security/schema/jb...;
+
me.domainDeployerMap.put("mynamespace",WSSecurityAssertionDeployer.class);
+
}
//hide constructor
@@ -76,29 +89,50 @@
public Policy deployServerside(Policy policy, ExtensibleMetaData extMetaData) throws
UnsupportedPolicy
{
- Policy returnedPolicy = (Policy) policy.normalize();
- ((XorCompositeAssertion) returnedPolicy.getTerms().get(0)).getTerms().clear();
- Policy originalPolicy = (Policy) policy.normalize();
+// ByteArrayOutputStream stream = new ByteArrayOutputStream();
+// PolicyWriter writer =
+// PolicyFactory.getPolicyWriter(PolicyFactory.StAX_POLICY_WRITER);
+//
+// writer.writePolicy(policy, stream );
+// log.debug(stream.toString());
+
+ List<Assertion> returnedPolicyTerms = new LinkedList<Assertion>();
+
+ if (! policy.isNormalized())
+ {
+ policy.normalize();
+ }
+
// in normal form we have just one wsp:ExactlyOne elemnet containg unbounded wsp:All
(alternative)
- XorCompositeAssertion exactlyOne = (XorCompositeAssertion)
originalPolicy.getTerms().get(0);
+ XorCompositeAssertion exactlyOne = (XorCompositeAssertion)
policy.getTerms().get(0);
+ log.debug("####"+ exactlyOne.getClass());
+ log.debug("####"+ exactlyOne.getTerms());
for (AndCompositeAssertion alternative: (List<AndCompositeAssertion>)
exactlyOne.getTerms() )
{
+ log.debug("alternative");
try
{
deployAlternativeServerSide(alternative,extMetaData);
- ((XorCompositeAssertion)
returnedPolicy.getTerms().get(0)).addTerm(alternative);
+ returnedPolicyTerms.add(alternative);
}
catch (UnsupportedAlternative e)
{
+ log.debug("Unsupported Alternative");
//policy is unsupported only if it have all alternative unsupported
}
}
- if (((XorCompositeAssertion) returnedPolicy.getTerms().get(0)).getTerms().size() ==
0)
+ if (returnedPolicyTerms.size() == 0)
{
+ if (log.isDebugEnabled())
+ {
+ log.debug("XorComposite zero element...Policy not supported");
+ }
throw new UnsupportedPolicy();
}
- return returnedPolicy;
+ policy.getTerms().clear();
+ policy.addTerms(returnedPolicyTerms);
+ return policy;
}
public void deployClientSide(Policy policy)
@@ -123,6 +157,10 @@
}
else
{
+ if (log.isDebugEnabled())
+ {
+ log.debug("Unknown Alternative type....Alternative not
supported");
+ }
throw new UnsupportedAlternative();
}
@@ -157,10 +195,15 @@
try {
if (! domainDeployerMap.containsKey(namespace) )
{
+ if (log.isDebugEnabled())
+ {
+ log.debug("Unknown namespace:"+namespace+"...Assertion not
supported");
+ }
throw new UnsupportedAssertion();
}
return (AssertionDeployer) (domainDeployerMap.get(namespace)).newInstance();
} catch (Exception e) {
+
throw new UnsupportedAssertion();
}
}
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-07
21:57:25 UTC (rev 2998)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/WSSecurityAssertionDeployer.java 2007-05-08
08:00:49 UTC (rev 2999)
@@ -1,5 +1,6 @@
package org.jboss.ws.extensions.policy.deployer;
+import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.stream.XMLOutputFactory;
@@ -21,6 +22,7 @@
public void deploy(PrimitiveAssertion assertion, ExtensibleMetaData extMetaData)
throws UnsupportedAssertion
{
+ System.out.print("#########################");
StringWriter writer = new StringWriter();
if (extMetaData instanceof EndpointMetaData)
{
@@ -32,16 +34,21 @@
//GET XML of security assertion
PrimitiveAssertionWriter.newInstance().writePrimitiveAssertion(assertion,
writer);
+ StringReader reader = new StringReader(writer.toString());
+
//Set security configuration
- securityConfiguration =
WSSecurityOMFactory.newInstance().parse(writer.toString());
+ securityConfiguration = WSSecurityOMFactory.newInstance().parse(reader);
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();
+
+
System.out.print("-----------#########################-------------");
}
catch (Exception e)
{
+ e.printStackTrace();
throw new UnsupportedAssertion();
}
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/wsse/WSSecurityOMFactory.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/wsse/WSSecurityOMFactory.java 2007-05-07
21:57:25 UTC (rev 2998)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/wsse/WSSecurityOMFactory.java 2007-05-08
08:00:49 UTC (rev 2999)
@@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringReader;
import java.net.URL;
import java.util.HashMap;
@@ -114,7 +115,17 @@
return configuration;
}
+
+ public WSSecurityConfiguration parse(StringReader strReader) throws JBossXBException
+ {
+ if (strReader == null)
+ throw new IllegalArgumentException("Security InputStream cannot be
null");
+ Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+ WSSecurityConfiguration configuration = (WSSecurityConfiguration)
unmarshaller.unmarshal(strReader, this, null);
+ return configuration;
+ }
+
/**
* This method is called on the factory by the object model builder when the
* parsing starts.
Modified:
branches/JBWS-856/jbossws-tests/src/resources/jaxws/samples/wssecuritypolicy/PolicyAttachmentFragment.wsdl
===================================================================
---
branches/JBWS-856/jbossws-tests/src/resources/jaxws/samples/wssecuritypolicy/PolicyAttachmentFragment.wsdl 2007-05-07
21:57:25 UTC (rev 2998)
+++
branches/JBWS-856/jbossws-tests/src/resources/jaxws/samples/wssecuritypolicy/PolicyAttachmentFragment.wsdl 2007-05-08
08:00:49 UTC (rev 2999)
@@ -9,19 +9,23 @@
xmlns:sp="http://www.jboss.com/ws-security/schema/jboss-ws-security_...
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-w...
- <wsp:Policy wsu:Id="X509EndpointPolicy" >
- <sp:jboss-ws-security>
+ <wsp:Policy wsu:Id="X509EndpointPolicy">
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:jboss-ws-security xmlns:sp="mynamespace">
<sp:key-store-file>WEB-INF/wsse.keystore</sp:key-store-file>
<sp:key-store-password>jbossws</sp:key-store-password>
<sp:trust-store-file>WEB-INF/wsse.truststore</sp:trust-store-file>
<sp:trust-store-password>jbossws</sp:trust-store-password>
<sp:config>
- <sp:encrypt type="x509v3" alias="wsse"/>
+ <sp:encrypt sp:type="x509v3" sp:alias="wsse"/>
<sp:requires>
<sp:encryption/>
</sp:requires>
</sp:config>
- </sp:jboss-ws-security>
+ </sp:jboss-ws-security>
+ </wsp:All>
+ </wsp:ExactlyOne>
</wsp:Policy>
<binding name='HelloBinding' type='tns:Hello'>
<soap:binding style='rpc'
transport='http://schemas.xmlsoap.org/soap/http'/>