[jbossws-commits] JBossWS SVN: r3102 - in branches/JBWS-856: jbossws-core/src/java/org/jboss/ws/metadata/builder and 3 other directories.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Wed May 16 04:32:29 EDT 2007


Author: palin
Date: 2007-05-16 04:32:28 -0400 (Wed, 16 May 2007)
New Revision: 3102

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/metadata/builder/MetaDataBuilder.java
   branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java
   branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
   branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSServerMetaDataBuilder.java
   branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
   branches/JBWS-856/jbossws-tests/build.xml
   branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/wssecuritypolicy/HelloJavaBean.java
   branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/wssecuritypolicy/SimpleEncryptTestCase.java
Log:
Partial commit:
- working on client side policy deployment
- refactoring of policy related methods in metadata builders


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-16 08:26:33 UTC (rev 3101)
+++ branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/AssertionDeployer.java	2007-05-16 08:32:28 UTC (rev 3102)
@@ -1,3 +1,24 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
 package org.jboss.ws.extensions.policy.deployer;
 
 import org.apache.ws.policy.PrimitiveAssertion;
@@ -4,7 +25,32 @@
 import org.jboss.ws.extensions.policy.deployer.exceptions.UnsupportedAssertion;
 import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
 
+/**
+ * Interface each policy domain should implement for policy deployment.
+ * 
+ * @author Stefano Maestri <mailto:stefano.maestri at javalinux.it> 
+ * @author Alessio Soldano <mailto:alessio.soldano at javalinux.it>
+ *
+ */
 public interface AssertionDeployer
 {
-   public void deploy(PrimitiveAssertion assertion, ExtensibleMetaData extMetaData) throws UnsupportedAssertion;
+   /**
+    * Server side deployment method; ExtensibleMetaData provided so
+    * that the implementor to let it plugs its own handlers. 
+    * 
+    * @param assertion
+    * @param extMetaData
+    * @throws UnsupportedAssertion
+    */
+   public void deployServerSide(PrimitiveAssertion assertion, ExtensibleMetaData extMetaData) throws UnsupportedAssertion;
+   
+   /**
+    * Client side deployment method; ExtensibleMetaData provided so
+    * that the implementor to let it plugs its own handlers.
+    * 
+    * @param assertion
+    * @param extMetaData
+    * @throws UnsupportedAssertion
+    */
+   public void deployClientSide(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-16 08:26:33 UTC (rev 3101)
+++ branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/PolicyDeployer.java	2007-05-16 08:32:28 UTC (rev 3102)
@@ -21,29 +21,20 @@
  */
 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;
 
 
@@ -63,8 +54,6 @@
    static {
       me = new PolicyDeployer();
       me.domainDeployerMap.put("http://www.jboss.com/ws-security/schema/jboss-ws-security_1_0.xsd",WSSecurityAssertionDeployer.class);
-      me.domainDeployerMap.put("mynamespace",WSSecurityAssertionDeployer.class);
-      
    }
    
    //hide constructor
@@ -86,7 +75,7 @@
       
    }
    
-   
+   @SuppressWarnings("unchecked")
    public Policy deployServerside(Policy policy, ExtensibleMetaData extMetaData) throws UnsupportedPolicy
    {
          
@@ -97,7 +86,7 @@
          policy.normalize();
       }
       
-//    in normal form we have just one wsp:ExactlyOne elemnet containg unbounded wsp:All (alternative)
+      //in normal form we have just one wsp:ExactlyOne element containg unbounded wsp:All (alternative)
       XorCompositeAssertion exactlyOne = (XorCompositeAssertion) policy.getTerms().get(0);
       log.debug("####"+ exactlyOne.getClass());
       log.debug("####"+  exactlyOne.getTerms());
@@ -129,11 +118,48 @@
       return policy;
    }
    
-   public void deployClientSide(Policy policy)
+   /**
+    * Policy deployer method for client side: delegates to the right domain deployer
+    * and fails if one or more policy assertions are not supported.
+    * 
+    * @param policy
+    * @param extMetaData
+    * @throws UnsupportedPolicy
+    */
+   @SuppressWarnings("unchecked")
+   public void deployClientSide(Policy policy, ExtensibleMetaData extMetaData) throws UnsupportedPolicy
    {
-      
+      if (! policy.isNormalized())
+      {
+         policy.normalize();
+      }
+      //in normal form we have just one wsp:ExactlyOne element containg unbounded wsp:All (alternative)
+      XorCompositeAssertion exactlyOne = (XorCompositeAssertion) policy.getTerms().get(0);
+      for (AndCompositeAssertion alternative: (List<AndCompositeAssertion>) exactlyOne.getTerms() )
+      {
+         for (Assertion assertion : (List<Assertion>) alternative.getTerms())
+         {
+            if (assertion instanceof PrimitiveAssertion)
+            {
+               try
+               {
+                  deployAssertionClientSide((PrimitiveAssertion) assertion, extMetaData);
+               }
+               catch (UnsupportedAssertion e)
+               {
+                  log.error("Unsupported assertion!");
+                  throw new UnsupportedPolicy();
+               }
+            } 
+            else if (assertion instanceof Policy) //inner policy to be verified
+            {
+               deployClientSide((Policy) assertion, extMetaData); 
+            }
+         }
+      }
    }
    
+   @SuppressWarnings("unchecked")
    private void deployAlternativeServerSide(AndCompositeAssertion alternative, ExtensibleMetaData extMetaData) throws UnsupportedAlternative
    {
       for (Assertion assertion : (List<Assertion>) alternative.getTerms())
@@ -175,9 +201,14 @@
    private void deployAssertionServerSide(PrimitiveAssertion assertion, ExtensibleMetaData extMetaData) throws UnsupportedAssertion 
    {
       AssertionDeployer deployer = getDomainDeployerInstance(assertion.getName().getNamespaceURI());
-      deployer.deploy(assertion,extMetaData);
+      deployer.deployServerSide(assertion,extMetaData);
    }   
-  
+   
+   private void deployAssertionClientSide(PrimitiveAssertion assertion, ExtensibleMetaData extMetaData) throws UnsupportedAssertion 
+   {
+      AssertionDeployer deployer = getDomainDeployerInstance(assertion.getName().getNamespaceURI());
+      deployer.deployClientSide(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-16 08:26:33 UTC (rev 3101)
+++ branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/deployer/WSSecurityAssertionDeployer.java	2007-05-16 08:32:28 UTC (rev 3102)
@@ -1,29 +1,28 @@
 package org.jboss.ws.extensions.policy.deployer;
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.StringReader;
-import java.io.StringWriter;
 
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.XMLStreamWriter;
-
 import org.apache.ws.policy.PrimitiveAssertion;
 import org.jboss.logging.Logger;
-import org.jboss.ws.extensions.policy.PolicyAssertion;
+import org.jboss.ws.WSException;
+import org.jboss.ws.core.StubExt;
 import org.jboss.ws.extensions.policy.deployer.exceptions.UnsupportedAssertion;
 import org.jboss.ws.extensions.policy.deployer.util.PrimitiveAssertionWriter;
+import org.jboss.ws.integration.UnifiedVirtualFile;
 import org.jboss.ws.metadata.umdm.EndpointMetaData;
 import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
+import org.jboss.ws.metadata.umdm.ServiceMetaData;
 import org.jboss.ws.metadata.wsse.WSSecurityConfigFactory;
 import org.jboss.ws.metadata.wsse.WSSecurityConfiguration;
 import org.jboss.ws.metadata.wsse.WSSecurityOMFactory;
-import org.jboss.xb.binding.JBossXBException;
 
 public class WSSecurityAssertionDeployer implements AssertionDeployer
 {
    private final static Logger log = Logger.getLogger(PolicyDeployer.class);
    
-   public void deploy(PrimitiveAssertion assertion, ExtensibleMetaData extMetaData) throws UnsupportedAssertion
+   public void deployServerSide(PrimitiveAssertion assertion, ExtensibleMetaData extMetaData) throws UnsupportedAssertion
    {
       ByteArrayOutputStream stream = new ByteArrayOutputStream();
       if (extMetaData instanceof EndpointMetaData)
@@ -52,12 +51,37 @@
             e.printStackTrace();
             throw new UnsupportedAssertion();
          }
-         
-         
       }
-
    }
    
-   
+   public void deployClientSide(PrimitiveAssertion assertion, ExtensibleMetaData extMetaData) throws UnsupportedAssertion
+   {
+      if (extMetaData instanceof EndpointMetaData)
+      {
+         ByteArrayOutputStream stream = new ByteArrayOutputStream();
+         EndpointMetaData epMetaData = (EndpointMetaData) extMetaData;
+         ServiceMetaData serviceMetaData = epMetaData.getServiceMetaData();
+         if (serviceMetaData.getSecurityConfiguration() == null)
+         {
+            try
+            {
+               PrimitiveAssertionWriter.newInstance().writePrimitiveAssertion(assertion, stream);
+               StringReader reader = new StringReader(stream.toString());
+               
+               WSSecurityConfiguration securityConfiguration = WSSecurityOMFactory.newInstance().parse(reader);
+               serviceMetaData.setSecurityConfiguration(securityConfiguration);
+               
+               epMetaData.setConfigName("Standard WSSecurity Client");
+               epMetaData.initEndpointConfig();
+            }
+            catch (Exception e)
+            {
+               e.printStackTrace();
+               throw new UnsupportedAssertion();
+            }
+         }
+      }
+      
+   }
 
 }

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-16 08:26:33 UTC (rev 3101)
+++ branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/MetaDataBuilder.java	2007-05-16 08:32:28 UTC (rev 3102)
@@ -23,9 +23,7 @@
 
 // $Id$
 
-import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -45,11 +43,6 @@
 import javax.xml.namespace.QName;
 import javax.xml.ws.addressing.AddressingProperties;
 
-import org.apache.ws.policy.Policy;
-import org.apache.ws.policy.PolicyReference;
-import org.apache.ws.policy.util.DOMPolicyReader;
-import org.apache.ws.policy.util.PolicyFactory;
-import org.apache.ws.policy.util.PolicyRegistry;
 import org.jboss.logging.Logger;
 import org.jboss.ws.Constants;
 import org.jboss.ws.WSException;
@@ -64,11 +57,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.PolicyScopeLevel;
-import org.jboss.ws.extensions.policy.annotation.PolicyAttachment;
-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;
 import org.jboss.ws.metadata.j2ee.UnifiedApplicationMetaData;
 import org.jboss.ws.metadata.j2ee.UnifiedBeanMetaData;
 import org.jboss.ws.metadata.j2ee.UnifiedEjbPortComponentMetaData;
@@ -78,14 +66,12 @@
 import org.jboss.ws.metadata.j2ee.UnifiedWebSecurityMetaData.UnifiedWebResourceCollection;
 import org.jboss.ws.metadata.umdm.ClientEndpointMetaData;
 import org.jboss.ws.metadata.umdm.EndpointMetaData;
-import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
 import org.jboss.ws.metadata.umdm.OperationMetaData;
 import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
 import org.jboss.ws.metadata.wsdl.WSDLBinding;
 import org.jboss.ws.metadata.wsdl.WSDLBindingOperation;
 import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
 import org.jboss.ws.metadata.wsdl.WSDLEndpoint;
-import org.jboss.ws.metadata.wsdl.WSDLExtensibilityElement;
 import org.jboss.ws.metadata.wsdl.WSDLInterface;
 import org.jboss.ws.metadata.wsdl.WSDLInterfaceOperation;
 import org.jboss.ws.metadata.wsdl.WSDLInterfaceOperationOutput;
@@ -472,139 +458,7 @@
       }
    }
 
-   protected void processPolicyAnnotation(EndpointMetaData epMetaData, Class<?> sepClass, UnifiedDeploymentInfo udi)
-   {
-      for (org.jboss.ws.extensions.policy.annotation.Policy policy : sepClass.getAnnotation(PolicyAttachment.class).value())
-      {
-         Policy normPolicy;
-         InputStream is = null;
-         try
-         {
-            DOMPolicyReader reader = (DOMPolicyReader) PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER);
-            is = udi.getMetaDataFileURL(policy.policyFileLocation()).openStream();
-            Policy unnormalizedPolicy = reader.readPolicy(is);
-            normPolicy = (Policy)unnormalizedPolicy.normalize();
-            log.info("++++++++++++++ Deploying Annotated Policy="+policy.policyFileLocation());
-            deployPolicy(normPolicy, policy.scope(), epMetaData);
-         }
-         catch (Exception e)
-         {
-            e.printStackTrace();
-         } finally
-         {
-            try 
-            {
-               is.close();
-            } catch (Exception e) {}
-         }
-         
-      }
-      
-      
-   }
    
-   protected void processPolicyMetaDataExtension(EndpointMetaData epMetaData, WSDLDefinitions wsdlDefinitions)
-   {
-      //Collect all policies defined in our wsdl definitions
-      DOMPolicyReader reader = (DOMPolicyReader) PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER);
-      PolicyRegistry localPolicyRegistry = new PolicyRegistry();
-      for (WSDLExtensibilityElement policyElement : wsdlDefinitions.getExtensibilityElements(Constants.WSDL_ELEMENT_POLICY))
-      {
-         Policy policy = reader.readPolicy(policyElement.getElement());
-         localPolicyRegistry.register(policy.getPolicyURI(), policy);
-      }
-      
-      //Port scope
-      WSDLService wsdlService = wsdlDefinitions.getService(epMetaData.getServiceMetaData().getServiceName());
-      if (wsdlService != null)
-      {
-         WSDLEndpoint wsdlEndpoint = wsdlService.getEndpoint(epMetaData.getPortName());
-         if (wsdlEndpoint != null)
-         {
-            List<WSDLExtensibilityElement> portPolicyRefList = wsdlEndpoint.getExtensibilityElements(Constants.WSDL_ELEMENT_POLICYREFERENCE);
-            deployPolicies(portPolicyRefList, PolicyScopeLevel.WSDL_PORT, localPolicyRegistry, epMetaData);
-         }
-         else
-         {
-            log.warn("Cannot get port '"+epMetaData.getPortName()+"' from the given wsdl definitions! Eventual policies attached to this port won't be considered.");
-         }
-      }
-      else
-      {
-         log.warn("Cannot get service '"+epMetaData.getServiceMetaData().getServiceName()+"' from the given wsdl definitions!  Eventual policies attached to this service won't be considered.");
-      }
-      
-      //Binding scope
-      WSDLBinding wsdlBinding = wsdlDefinitions.getBindingByInterfaceName(epMetaData.getPortTypeName());
-      if (wsdlBinding != null)
-      {
-         List<WSDLExtensibilityElement> bindingPolicyRefList = wsdlBinding.getExtensibilityElements(Constants.WSDL_ELEMENT_POLICYREFERENCE);
-         deployPolicies(bindingPolicyRefList, PolicyScopeLevel.WSDL_BINDING, localPolicyRegistry, epMetaData);
-      }
-      else
-      {
-         log.warn("Cannot get binding for portType '"+epMetaData.getPortTypeName()+"' from the given wsdl definitions!  Eventual policies attached to this binding won't be considered.");
-      }
-      
-      //PortType scope
-      WSDLInterface wsdlInterface = wsdlDefinitions.getInterface(epMetaData.getPortTypeName());
-      if (wsdlInterface != null)
-      {
-         List<WSDLExtensibilityElement> portTypePolicyRefList = wsdlInterface.getExtensibilityElements(Constants.WSDL_PROPERTY_POLICYURIS);
-         deployPolicies(portTypePolicyRefList, PolicyScopeLevel.WSDL_PORT_TYPE, localPolicyRegistry, epMetaData);
-      }
-      else
-      {
-         log.warn("Cannot get portType '"+epMetaData.getPortTypeName()+"' from the given wsdl definitions! Eventual policies attached to this portType won't be considered.");
-      }
-   }
-   
-   private void deployPolicies(List<WSDLExtensibilityElement> policyReferences, PolicyScopeLevel scope, PolicyRegistry localPolicies, ExtensibleMetaData extMetaData)
-   {
-      if (policyReferences != null && policyReferences.size() != 0 && extMetaData instanceof ServerEndpointMetaData) 
-      {
-         DOMPolicyReader reader = (DOMPolicyReader) PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER); 
-         for (WSDLExtensibilityElement element : policyReferences)
-         {
-            PolicyReference policyRef = reader.readPolicyReference(element.getElement());
-            Policy normPolicy;
-            try
-            {
-               normPolicy = (Policy)policyRef.normalize(localPolicies);
-            }
-            catch (RuntimeException e)
-            {
-               //TODO!!! not a local policy: get the policy definition and create the policy
-               normPolicy = null;
-            }
-            deployPolicy(normPolicy, scope, extMetaData);
-         }
-      }
-   }
-   
-   private void deployPolicy(Policy policy, PolicyScopeLevel scope, ExtensibleMetaData extMetaData)
-   {
-      PolicyMetaExtension ext = (PolicyMetaExtension)extMetaData.getExtension(Constants.URI_WS_POLICY);
-      if (ext == null)
-      {
-         ext = new PolicyMetaExtension(Constants.URI_WS_POLICY);
-         extMetaData.addExtension(ext);
-      }
-      try
-      {
-         Policy deployedPolicy = PolicyDeployer.getInstance().deployServerside(policy, extMetaData);
-         ext.addPolicy(scope,deployedPolicy);
-      }
-      catch (UnsupportedPolicy e)
-      {
-         if (log.isDebugEnabled()) 
-         {
-            log.debug("Policy Not supported:" + policy.getPolicyURI());
-         }
-      }
-   }
-   
-   
    protected void processEndpointMetaDataExtensions(EndpointMetaData epMetaData, WSDLDefinitions wsdlDefinitions)
    {
       for (WSDLInterface wsdlInterface : wsdlDefinitions.getInterfaces())

Modified: branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java
===================================================================
--- branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java	2007-05-16 08:26:33 UTC (rev 3101)
+++ branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSClientMetaDataBuilder.java	2007-05-16 08:32:28 UTC (rev 3102)
@@ -31,14 +31,20 @@
 import javax.xml.namespace.QName;
 import javax.xml.ws.BindingType;
 
+import org.apache.ws.policy.Policy;
 import org.jboss.ws.Constants;
 import org.jboss.ws.WSException;
 import org.jboss.ws.core.jaxrpc.Style;
 import org.jboss.ws.core.jaxws.client.ServiceObjectFactoryJAXWS;
+import org.jboss.ws.extensions.policy.PolicyScopeLevel;
+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;
 import org.jboss.ws.integration.ResourceLoaderAdapter;
 import org.jboss.ws.integration.UnifiedVirtualFile;
 import org.jboss.ws.metadata.umdm.ClientEndpointMetaData;
 import org.jboss.ws.metadata.umdm.EndpointMetaData;
+import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
 import org.jboss.ws.metadata.umdm.OperationMetaData;
 import org.jboss.ws.metadata.umdm.ServiceMetaData;
 import org.jboss.ws.metadata.umdm.UnifiedMetaData;
@@ -83,7 +89,13 @@
          WSDLDefinitions wsdlDefinitions = serviceMetaData.getWsdlDefinitions();
 
          buildMetaDataInternal(serviceMetaData, wsdlDefinitions);
-
+         
+         // Setup policies for each endpoint
+         for (EndpointMetaData epMetaData : serviceMetaData.getEndpoints())
+         {
+            processPolicyMetaDataExtension(epMetaData, wsdlDefinitions);
+         }
+         
          // Read the WSDL and initialize the schema model
          // This should only be needed for debuging purposes of the UMDM
          JBossXSModel schemaModel = WSDLUtils.getSchemaModel(wsdlDefinitions.getWsdlTypes());
@@ -293,4 +305,27 @@
 
       if(log.isDebugEnabled()) log.debug("END: rebuildMetaData\n" + epMetaData.getServiceMetaData());
    }
+   
+   
+   protected void deployPolicy(Policy policy, PolicyScopeLevel scope, ExtensibleMetaData extMetaData)
+   {
+      PolicyMetaExtension ext = (PolicyMetaExtension)extMetaData.getExtension(Constants.URI_WS_POLICY);
+      if (ext == null)
+      {
+         ext = new PolicyMetaExtension(Constants.URI_WS_POLICY);
+         extMetaData.addExtension(ext);
+      }
+      try
+      {
+         PolicyDeployer.getInstance().deployClientSide(policy, extMetaData);
+         ext.addPolicy(scope, policy);
+      }
+      catch (UnsupportedPolicy e)
+      {
+         if (log.isDebugEnabled()) 
+         {
+            log.debug("Policy Not supported:" + policy.getPolicyURI());
+         }
+      }
+   }
 }

Modified: branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java
===================================================================
--- branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java	2007-05-16 08:26:33 UTC (rev 3101)
+++ branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSMetaDataBuilder.java	2007-05-16 08:32:28 UTC (rev 3102)
@@ -55,6 +55,11 @@
 import javax.xml.ws.addressing.Action;
 import javax.xml.ws.addressing.AddressingProperties;
 
+import org.apache.ws.policy.Policy;
+import org.apache.ws.policy.PolicyReference;
+import org.apache.ws.policy.util.DOMPolicyReader;
+import org.apache.ws.policy.util.PolicyFactory;
+import org.apache.ws.policy.util.PolicyRegistry;
 import org.jboss.logging.Logger;
 import org.jboss.ws.Constants;
 import org.jboss.ws.WSException;
@@ -62,11 +67,14 @@
 import org.jboss.ws.core.jaxrpc.Use;
 import org.jboss.ws.core.jaxws.DynamicWrapperGenerator;
 import org.jboss.ws.core.jaxws.WrapperGenerator;
+import org.jboss.ws.core.server.UnifiedDeploymentInfo;
 import org.jboss.ws.core.utils.HolderUtils;
 import org.jboss.ws.core.utils.JBossWSEntityResolver;
 import org.jboss.ws.core.utils.JavaUtils;
 import org.jboss.ws.extensions.addressing.AddressingPropertiesImpl;
 import org.jboss.ws.extensions.addressing.metadata.AddressingOpMetaExt;
+import org.jboss.ws.extensions.policy.PolicyScopeLevel;
+import org.jboss.ws.extensions.policy.annotation.PolicyAttachment;
 import org.jboss.ws.metadata.acessor.JAXBAccessor;
 import org.jboss.ws.metadata.builder.MetaDataBuilder;
 import org.jboss.ws.metadata.j2ee.serviceref.HandlerChainsObjectFactory;
@@ -74,9 +82,11 @@
 import org.jboss.ws.metadata.j2ee.serviceref.UnifiedHandlerChainsMetaData;
 import org.jboss.ws.metadata.j2ee.serviceref.UnifiedHandlerMetaData;
 import org.jboss.ws.metadata.umdm.EndpointMetaData;
+import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
 import org.jboss.ws.metadata.umdm.FaultMetaData;
 import org.jboss.ws.metadata.umdm.OperationMetaData;
 import org.jboss.ws.metadata.umdm.ParameterMetaData;
+import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
 import org.jboss.ws.metadata.umdm.TypeMappingMetaData;
 import org.jboss.ws.metadata.umdm.TypesMetaData;
 import org.jboss.ws.metadata.umdm.WrappedParameter;
@@ -85,7 +95,11 @@
 import org.jboss.ws.metadata.wsdl.WSDLBindingMessageReference;
 import org.jboss.ws.metadata.wsdl.WSDLBindingOperation;
 import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
+import org.jboss.ws.metadata.wsdl.WSDLEndpoint;
+import org.jboss.ws.metadata.wsdl.WSDLExtensibilityElement;
+import org.jboss.ws.metadata.wsdl.WSDLInterface;
 import org.jboss.ws.metadata.wsdl.WSDLMIMEPart;
+import org.jboss.ws.metadata.wsdl.WSDLService;
 import org.jboss.xb.binding.ObjectModelFactory;
 import org.jboss.xb.binding.Unmarshaller;
 import org.jboss.xb.binding.UnmarshallerFactory;
@@ -100,7 +114,7 @@
  * @author Thomas.Diesler at jboss.com
  */
 @SuppressWarnings("deprecation")
-public class JAXWSMetaDataBuilder extends MetaDataBuilder
+public abstract class JAXWSMetaDataBuilder extends MetaDataBuilder
 {
 
    protected static final Logger log = Logger.getLogger(JAXWSWebServiceMetaDataBuilder.class);
@@ -958,4 +972,130 @@
    {
       this.wrapperGenerator = wrapperGenerator;
    }
+   
+   
+   protected void processPolicyAnnotation(EndpointMetaData epMetaData, Class<?> sepClass, UnifiedDeploymentInfo udi)
+   {
+      for (org.jboss.ws.extensions.policy.annotation.Policy policy : sepClass.getAnnotation(PolicyAttachment.class).value())
+      {
+         InputStream is = null;
+         try
+         {
+            DOMPolicyReader reader = (DOMPolicyReader) PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER);
+            is = udi.getMetaDataFileURL(policy.policyFileLocation()).openStream();
+            Policy unnormalizedPolicy = reader.readPolicy(is);
+            Policy normPolicy = (Policy)unnormalizedPolicy.normalize();
+            log.info("Deploying Annotated Policy = "+policy.policyFileLocation());
+            PolicyScopeLevel scope = policy.scope();
+            if (PolicyScopeLevel.WSDL_PORT.equals(scope) || PolicyScopeLevel.WSDL_PORT_TYPE.equals(scope) ||
+                  PolicyScopeLevel.WSDL_BINDING.equals(scope))
+            {
+               deployPolicy(normPolicy, scope, epMetaData);
+            }
+            else
+            {
+               throw new WSException("Policy scope "+scope+" not supported yet!");
+            }
+         }
+         catch (Exception e)
+         {
+            e.printStackTrace();
+         } finally
+         {
+            try 
+            {
+               is.close();
+            } catch (Exception e) {}
+         }
+      }
+   }
+   
+   protected void processPolicyMetaDataExtension(EndpointMetaData epMetaData, WSDLDefinitions wsdlDefinitions)
+   {
+      //Collect all policies defined in our wsdl definitions
+      DOMPolicyReader reader = (DOMPolicyReader) PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER);
+      PolicyRegistry localPolicyRegistry = new PolicyRegistry();
+      for (WSDLExtensibilityElement policyElement : wsdlDefinitions.getExtensibilityElements(Constants.WSDL_ELEMENT_POLICY))
+      {
+         Policy policy = reader.readPolicy(policyElement.getElement());
+         localPolicyRegistry.register(policy.getPolicyURI(), policy);
+      }
+      //Port scope
+      WSDLService wsdlService = wsdlDefinitions.getService(epMetaData.getServiceMetaData().getServiceName());
+      if (wsdlService != null)
+      {
+         WSDLEndpoint wsdlEndpoint = wsdlService.getEndpoint(epMetaData.getPortName());
+         if (wsdlEndpoint != null)
+         {
+            List<WSDLExtensibilityElement> portPolicyRefList = wsdlEndpoint.getExtensibilityElements(Constants.WSDL_ELEMENT_POLICYREFERENCE);
+            deployPolicies(portPolicyRefList, PolicyScopeLevel.WSDL_PORT, localPolicyRegistry, epMetaData);
+         }
+         else
+         {
+            log.warn("Cannot get port '"+epMetaData.getPortName()+"' from the given wsdl definitions! Eventual policies attached to this port won't be considered.");
+         }
+      }
+      else
+      {
+         log.warn("Cannot get service '"+epMetaData.getServiceMetaData().getServiceName()+"' from the given wsdl definitions!  Eventual policies attached to this service won't be considered.");
+      }
+      
+      //Binding scope
+      WSDLBinding wsdlBinding = wsdlDefinitions.getBindingByInterfaceName(epMetaData.getPortTypeName());
+      if (wsdlBinding != null)
+      {
+         List<WSDLExtensibilityElement> bindingPolicyRefList = wsdlBinding.getExtensibilityElements(Constants.WSDL_ELEMENT_POLICYREFERENCE);
+         deployPolicies(bindingPolicyRefList, PolicyScopeLevel.WSDL_BINDING, localPolicyRegistry, epMetaData);
+      }
+      else
+      {
+         log.warn("Cannot get binding for portType '"+epMetaData.getPortTypeName()+"' from the given wsdl definitions!  Eventual policies attached to this binding won't be considered.");
+      }
+      
+      //PortType scope
+      WSDLInterface wsdlInterface = wsdlDefinitions.getInterface(epMetaData.getPortTypeName());
+      if (wsdlInterface != null)
+      {
+         List<WSDLExtensibilityElement> portTypePolicyRefList = wsdlInterface.getExtensibilityElements(Constants.WSDL_PROPERTY_POLICYURIS);
+         deployPolicies(portTypePolicyRefList, PolicyScopeLevel.WSDL_PORT_TYPE, localPolicyRegistry, epMetaData);
+      }
+      else
+      {
+         log.warn("Cannot get portType '"+epMetaData.getPortTypeName()+"' from the given wsdl definitions! Eventual policies attached to this portType won't be considered.");
+      }
+   }
+   
+   private void deployPolicies(List<WSDLExtensibilityElement> policyReferences, PolicyScopeLevel scope, PolicyRegistry localPolicies, ExtensibleMetaData extMetaData)
+   {
+      if (policyReferences != null && policyReferences.size() != 0 && extMetaData instanceof ServerEndpointMetaData) 
+      {
+         DOMPolicyReader reader = (DOMPolicyReader) PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER); 
+         for (WSDLExtensibilityElement element : policyReferences)
+         {
+            PolicyReference policyRef = reader.readPolicyReference(element.getElement());
+            Policy normPolicy;
+            try
+            {
+               normPolicy = (Policy)policyRef.normalize(localPolicies);
+            }
+            catch (RuntimeException e)
+            {
+               //TODO!!! not a local policy: get the policy definition and create the policy
+               normPolicy = null;
+            }
+            deployPolicy(normPolicy, scope, extMetaData);
+         }
+      }
+   }
+   
+   /**
+    * Implementors should add PolicyMetaDataExt to the provided ExtensibleMetaData according
+    * to the specified policy and policy scope.
+    * 
+    * @param policy
+    * @param scope
+    * @param extMetaData
+    */
+   protected abstract void deployPolicy(Policy policy, PolicyScopeLevel scope, ExtensibleMetaData extMetaData);
+   
 }

Modified: branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSServerMetaDataBuilder.java
===================================================================
--- branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSServerMetaDataBuilder.java	2007-05-16 08:26:33 UTC (rev 3101)
+++ branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSServerMetaDataBuilder.java	2007-05-16 08:32:28 UTC (rev 3102)
@@ -26,10 +26,17 @@
 import javax.jws.WebService;
 import javax.xml.ws.WebServiceProvider;
 
+import org.apache.ws.policy.Policy;
+import org.jboss.ws.Constants;
 import org.jboss.ws.annotation.EndpointConfig;
 import org.jboss.ws.annotation.WebContext;
 import org.jboss.ws.core.server.UnifiedDeploymentInfo;
 import org.jboss.ws.core.server.UnifiedDeploymentInfo.DeploymentType;
+import org.jboss.ws.extensions.policy.PolicyScopeLevel;
+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;
+import org.jboss.ws.metadata.umdm.ExtensibleMetaData;
 import org.jboss.ws.metadata.umdm.ServerEndpointMetaData;
 import org.jboss.ws.metadata.umdm.UnifiedMetaData;
 
@@ -153,4 +160,26 @@
          sepMetaData.setVirtualHosts(virtualHosts);
       }
    }
+   
+   protected void deployPolicy(Policy policy, PolicyScopeLevel scope, ExtensibleMetaData extMetaData)
+   {
+      PolicyMetaExtension ext = (PolicyMetaExtension)extMetaData.getExtension(Constants.URI_WS_POLICY);
+      if (ext == null)
+      {
+         ext = new PolicyMetaExtension(Constants.URI_WS_POLICY);
+         extMetaData.addExtension(ext);
+      }
+      try
+      {
+         Policy deployedPolicy = PolicyDeployer.getInstance().deployServerside(policy, extMetaData);
+         ext.addPolicy(scope,deployedPolicy);
+      }
+      catch (UnsupportedPolicy e)
+      {
+         if (log.isDebugEnabled()) 
+         {
+            log.debug("Policy Not supported:" + policy.getPolicyURI());
+         }
+      }
+   }
 }

Modified: branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
===================================================================
--- branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java	2007-05-16 08:26:33 UTC (rev 3101)
+++ branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java	2007-05-16 08:32:28 UTC (rev 3102)
@@ -160,10 +160,9 @@
          else if (seiClass.isAnnotationPresent(HandlerChain.class))
             processHandlerChain(sepMetaData, seiClass);
 
-//       Process an optional @PolicyAttachment annotation
+         //Process an optional @PolicyAttachment annotation
          if (sepClass.isAnnotationPresent(PolicyAttachment.class))
             processPolicyAnnotation(sepMetaData, sepClass, udi);
-
          
          // process webservices.xml contributions
          processWSDDContribution(sepMetaData);
@@ -341,9 +340,21 @@
       if (anPolicy!=null)
       {
          String policyLocation = anPolicy.wsdlFragmentLocation();
+         System.out.println("Policy Location: ###"+policyLocation+"###");
          if (policyLocation==null || policyLocation.length()==0)
             throw new WSException("Missing wsdlFragmentLocation for @Policy on " + sepClass.getName());
          result.policyLocation = udi.getMetaDataFileURL(policyLocation);
+//         if (result.policyLocation==null) {
+//            try
+//            {
+//               result.policyLocation = new File(policyLocation).toURL();
+//            }
+//            catch (Exception e)
+//            {
+//               e.printStackTrace();
+//            }
+//         }
+         System.out.println("Policy Location: ###"+result.policyLocation+"###");
       }
 
       return result;

Modified: branches/JBWS-856/jbossws-tests/build.xml
===================================================================
--- branches/JBWS-856/jbossws-tests/build.xml	2007-05-16 08:26:33 UTC (rev 3101)
+++ branches/JBWS-856/jbossws-tests/build.xml	2007-05-16 08:32:28 UTC (rev 3102)
@@ -352,6 +352,7 @@
       <classpath refid="core.classpath"/>
       <classpath refid="jbossws.classpath"/>
       <classpath location="${thirdparty.dir}/concurrent.jar"/>
+      <classpath location="${thirdparty.dir}/commons-logging.jar"/>
       <classpath location="${tests.output.dir}/classes"/>
     </taskdef>    
     

Modified: branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/wssecuritypolicy/HelloJavaBean.java
===================================================================
--- branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/wssecuritypolicy/HelloJavaBean.java	2007-05-16 08:26:33 UTC (rev 3101)
+++ branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/wssecuritypolicy/HelloJavaBean.java	2007-05-16 08:32:28 UTC (rev 3102)
@@ -31,7 +31,8 @@
 import org.jboss.ws.annotation.PolicyWsdlFragment;
 
 @WebService(name = "Hello", targetNamespace = "http://org.jboss.ws/samples/wssecuritypolicy")
- at PolicyWsdlFragment(wsdlFragmentLocation="WEB-INF/PolicyAttachmentFragment.wsdl")
+//@PolicyWsdlFragment(wsdlFragmentLocation="WEB-INF/PolicyAttachmentFragment.wsdl")
+ at PolicyWsdlFragment(wsdlFragmentLocation="/dati/jbws_JBWS-856/jbossws-tests/output/resources/jaxws/samples/wssecuritypolicy/WEB-INF/PolicyAttachmentFragment.wsdl")
 @SOAPBinding(style = SOAPBinding.Style.RPC)
 public class HelloJavaBean
 {

Modified: branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/wssecuritypolicy/SimpleEncryptTestCase.java
===================================================================
--- branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/wssecuritypolicy/SimpleEncryptTestCase.java	2007-05-16 08:26:33 UTC (rev 3101)
+++ branches/JBWS-856/jbossws-tests/src/java/org/jboss/test/ws/jaxws/samples/wssecuritypolicy/SimpleEncryptTestCase.java	2007-05-16 08:32:28 UTC (rev 3102)
@@ -69,14 +69,14 @@
    private Hello getPort() throws Exception
    {
       URL wsdlURL = new File("wsprovide/resources/jaxws/samples/wssecuritypolicy/HelloService.wsdl").toURL();
-      URL securityURL = new File("resources/jaxws/samples/wssecuritypolicy/simple-encrypt/META-INF/jboss-wsse-client.xml").toURL();
+      //URL securityURL = new File("resources/jaxws/samples/wssecuritypolicy/simple-encrypt/META-INF/jboss-wsse-client.xml").toURL();
       QName serviceName = new QName("http://org.jboss.ws/samples/wssecuritypolicy", "HelloService");
 
       Service service = Service.create(wsdlURL, serviceName);
-      ((ServiceExt)service).setSecurityConfig(securityURL.toExternalForm());
+      //((ServiceExt)service).setSecurityConfig(securityURL.toExternalForm());
       
       Hello port = (Hello)service.getPort(Hello.class);
-      ((StubExt)port).setConfigName("Standard WSSecurity Client");
+      //((StubExt)port).setConfigName("Standard WSSecurity Client");
 
       Map<String, Object> reqContext = ((BindingProvider)port).getRequestContext();
       reqContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://" + getServerHost() + ":8080/jaxws-samples-wssecuritypolicy-encrypt");




More information about the jbossws-commits mailing list