diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany')
5 files changed, 245 insertions, 39 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProvider.java new file mode 100644 index 0000000000..12f3d81c98 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProvider.java @@ -0,0 +1,67 @@ +/*
+ * 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.
+ */
+
+package org.apache.tuscany.sca.binding.ws.axis2.policy.wspolicy;
+
+import java.util.logging.Logger;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.tuscany.sca.binding.ws.axis2.provider.Axis2BaseBindingProvider;
+import org.apache.tuscany.sca.host.http.SecurityContext;
+import org.apache.tuscany.sca.policy.PolicySubject;
+import org.apache.tuscany.sca.policy.security.http.ssl.HTTPSPolicy;
+import org.apache.tuscany.sca.policy.wspolicy.WSPolicy;
+import org.apache.tuscany.sca.provider.BasePolicyProvider;
+
+/**
+ * @version $Rev: 918583 $ $Date: 2010-03-03 17:16:15 +0000 (Wed, 03 Mar 2010) $
+ */
+public class WSPolicyProvider extends BasePolicyProvider<WSPolicy> {
+ private final Logger logger = Logger.getLogger(WSPolicyProvider.class.getName());
+
+ public WSPolicyProvider(PolicySubject subject) {
+ super(WSPolicy.class, subject);
+ }
+
+ public void configureBinding(Object context) {
+ ConfigurationContext configContext = ((Axis2BaseBindingProvider)context).getAxisConfigurationContext();
+
+ for ( Object policy : findPolicies() ) {
+ if ( policy instanceof WSPolicy ) {
+ WSPolicy wsPolicy = (WSPolicy)policy;
+ try {
+ configContext.getAxisConfiguration().applyPolicy(wsPolicy.getNeethiPolicy());
+ configContext.getAxisConfiguration().engageModule("rampart");
+
+ // TUSCANY-2824
+ // hack to make service side pick up rampart policies
+ // "rampartPolicy" comes from RampartMessageData.KEY_RAMPART_POLICY
+ // but I'm avoiding adding an explicit dependency just yet.
+ // There must be a proper way of getting rampart to recognize
+ // these policies
+ configContext.setProperty("rampartPolicy", wsPolicy.getNeethiPolicy());
+
+ } catch ( AxisFault e ) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProviderFactory.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProviderFactory.java new file mode 100644 index 0000000000..fc4879c0d9 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/policy/wspolicy/WSPolicyProviderFactory.java @@ -0,0 +1,57 @@ +/*
+ * 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.
+ */
+
+package org.apache.tuscany.sca.binding.ws.axis2.policy.wspolicy;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.policy.wspolicy.WSPolicy;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.PolicyProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev: 916317 $ $Date: 2010-02-25 15:16:44 +0000 (Thu, 25 Feb 2010) $
+ */
+public class WSPolicyProviderFactory implements PolicyProviderFactory<WSPolicy> {
+ private ExtensionPointRegistry registry;
+
+ public WSPolicyProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ this.registry = registry;
+ }
+
+ public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component) {
+ return null;
+ }
+
+ public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) {
+ return new WSPolicyProvider(endpointReference);
+ }
+
+ public PolicyProvider createServicePolicyProvider(Endpoint endpoint) {
+ return new WSPolicyProvider(endpoint);
+ }
+
+ public Class<WSPolicy> getModelType() {
+ return WSPolicy.class;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2EngineIntegration.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2EngineIntegration.java index 8fc5befc78..e25f5768e5 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2EngineIntegration.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2EngineIntegration.java @@ -19,7 +19,9 @@ package org.apache.tuscany.sca.binding.ws.axis2.provider; +import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; @@ -49,16 +51,24 @@ import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.client.Options; import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.axis2.deployment.DeploymentEngine; +import org.apache.axis2.deployment.DeploymentErrorMsgs; +import org.apache.axis2.deployment.DeploymentException; +import org.apache.axis2.deployment.ModuleBuilder; import org.apache.axis2.deployment.URLBasedAxisConfigurator; import org.apache.axis2.deployment.util.Utils; import org.apache.axis2.description.AxisEndpoint; +import org.apache.axis2.description.AxisModule; import org.apache.axis2.description.AxisOperation; import org.apache.axis2.description.AxisService; import org.apache.axis2.description.Parameter; +import org.apache.axis2.description.Version; import org.apache.axis2.description.WSDL11ToAxisServiceBuilder; import org.apache.axis2.description.WSDL2Constants; import org.apache.axis2.description.WSDLToAxisServiceBuilder; +import org.apache.axis2.engine.AxisConfiguration; import org.apache.axis2.engine.MessageReceiver; +import org.apache.axis2.i18n.Messages; import org.apache.tuscany.sca.assembly.AbstractContract; import org.apache.tuscany.sca.binding.ws.WebServiceBinding; import org.apache.tuscany.sca.common.xml.XMLDocumentHelper; @@ -135,21 +145,20 @@ public class Axis2EngineIntegration { try { axis2Config = AccessController.doPrivileged(new PrivilegedExceptionAction<Axis2Config>() { public Axis2Config run() throws AxisFault, MalformedURLException { - // collect together the classloaders that Axis2 requireds in order to load - // pluggable items such as the Tuscany MessageReceivers and the xerces + // collect together the classloaders that Axis2 requires in order to load + // pluggable items such as the Tuscany MessageReceivers and the Xerces // document builder. ClassLoader wsBindingCL = getClass().getClassLoader(); ClassLoader axis2CL = URLBasedAxisConfigurator.class.getClassLoader(); - ClassLoaderContext classLoaderContext = - new ClassLoaderContext(wsBindingCL, axis2CL); + ClassLoaderContext classLoaderContext = new ClassLoaderContext(wsBindingCL, axis2CL); - classLoaderContext = - new ClassLoaderContext(classLoaderContext.getClassLoader(), serviceDiscovery, - XMLInputFactory.class, DocumentBuilderFactory.class); + classLoaderContext = new ClassLoaderContext(classLoaderContext.getClassLoader(), + serviceDiscovery, + XMLInputFactory.class, + DocumentBuilderFactory.class); - URL axis2xmlURL = - wsBindingCL - .getResource("org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml"); + URL axis2xmlURL = wsBindingCL.getResource("org/apache/tuscany/sca/binding/ws/axis2/engine/conf/tuscany-axis2.xml"); + if (axis2xmlURL != null) { URL repositoryURL = new URL(axis2xmlURL, "../repository/"); Axis2Config config = new Axis2Config(); @@ -190,9 +199,73 @@ public class Axis2EngineIntegration { } catch (PrivilegedActionException e) { throw new ServiceRuntimeException(e.getException()); } - } + // Some code to programatically load an Axis2 module only if we need it + // currently hard coded to load rampart only. Needs generalization + public synchronized static void loadRampartModule(ConfigurationContext axis2ConfigContext) { + try { + final AxisConfiguration axisConfiguration = axis2ConfigContext.getAxisConfiguration(); + final URL rampartURL = new URL(axis2Config.repositoryURL.toString() + "modules/rampart-1.4.mar"); + + ClassLoader deploymentClassLoader = org.apache.axis2.deployment.util.Utils.createClassLoader( + new URL[]{rampartURL}, + axisConfiguration.getModuleClassLoader(), + true, + (File) axisConfiguration.getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR)); + + final AxisModule module = new AxisModule(); + module.setModuleClassLoader(deploymentClassLoader); + module.setParent(axisConfiguration); + + if (module.getName() == null) { + module.setName("rampart-1.4"); + module.setVersion(new Version("1.4")); + } + + populateModule(axis2ConfigContext, module, rampartURL); + module.setFileName(rampartURL); + + // Allow privileged access to read properties. Requires PropertiesPermission read in + // security policy. + try { + AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() { + public Object run() throws IOException { + DeploymentEngine.addNewModule(module, axisConfiguration); + return null; + } + }); + } catch (PrivilegedActionException e) { + throw (AxisFault)e.getException(); + } + + org.apache.axis2.util.Utils.calculateDefaultModuleVersion(axisConfiguration.getModules(), + axisConfiguration); + axisConfiguration.validateSystemPredefinedPhases(); + } catch (IOException e) { + throw new ServiceRuntimeException(e); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + private static void populateModule(ConfigurationContext axis2ConfigContext, AxisModule module, URL moduleUrl) throws DeploymentException { + try { + ClassLoader classLoader = module.getModuleClassLoader(); + InputStream moduleStream = classLoader.getResourceAsStream("META-INF/module.xml"); + if (moduleStream == null) { + moduleStream = classLoader.getResourceAsStream("meta-inf/module.xml"); + } + if (moduleStream == null) { + throw new DeploymentException(Messages.getMessage(DeploymentErrorMsgs.MODULE_XML_MISSING, moduleUrl.toString())); + } + ModuleBuilder moduleBuilder = new ModuleBuilder(moduleStream, module, axis2ConfigContext.getAxisConfiguration()); + moduleBuilder.populateModule(); + } catch (IOException e) { + throw new DeploymentException(e); + } + } + //========================================================= /** diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java index fb9bcb12f8..7b22dc443b 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ReferenceBindingProvider.java @@ -64,6 +64,7 @@ import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.InvocationChain; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.policy.PolicySubject; import org.apache.tuscany.sca.policy.util.PolicyHelper; import org.apache.tuscany.sca.provider.EndpointReferenceProvider; import org.apache.tuscany.sca.provider.PolicyProvider; @@ -108,17 +109,18 @@ public class Axis2ReferenceBindingProvider extends Axis2BaseBindingProvider impl contract.getInterface().resetDataBinding(OMElement.class.getName()); } - isSOAP11Required = PolicyHelper.isIntentRequired(wsBinding, Constants.SOAP11_INTENT); - isSOAP12Required = PolicyHelper.isIntentRequired(wsBinding, Constants.SOAP12_INTENT); + // TODO - why don't intents get aggregated to EPR correctly? + isSOAP11Required = PolicyHelper.isIntentRequired((PolicySubject)wsBinding, Constants.SOAP11_INTENT); + isSOAP12Required = PolicyHelper.isIntentRequired((PolicySubject)wsBinding, Constants.SOAP12_INTENT); - isMTOMRequired = PolicyHelper.isIntentRequired(wsBinding, Axis2BindingProviderFactory.MTOM_INTENT); + isMTOMRequired = PolicyHelper.isIntentRequired((PolicySubject)wsBinding, Axis2BindingProviderFactory.MTOM_INTENT); - // TODO - this is not correct as there may be other, custom, policies that - // require rampart. For example this is not going to pick up the case - // of external policy attachment - isRampartRequired = PolicyHelper.isIntentRequired(wsBinding, Constants.AUTHENTICATION_INTENT) || - PolicyHelper.isIntentRequired(wsBinding, Constants.CONFIDENTIALITY_INTENT) || - PolicyHelper.isIntentRequired(wsBinding, Constants.INTEGRITY_INTENT); + // if the endpoint contains any WS Policy expressions then we probably need rampart + // TODO - need to take into account Axis configuration policy also + QName wsPolicyQName = new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "Policy"); + if (PolicyHelper.getPolicies(endpointReference, wsPolicyQName).size() > 0){ + isRampartRequired = true; + } // Validate the configuration for provided policies @@ -167,6 +169,10 @@ public class Axis2ReferenceBindingProvider extends Axis2BaseBindingProvider impl // Apply the configuration from any other policies + if (isRampartRequired){ + Axis2EngineIntegration.loadRampartModule(configContext); + } + for (PolicyProvider pp : this.endpointReference.getPolicyProviders()) { pp.configureBinding(this); } diff --git a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java index 6e860752cf..00b3a113fb 100644 --- a/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-ws-runtime-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/provider/Axis2ServiceBindingProvider.java @@ -23,6 +23,7 @@ import java.net.URISyntaxException; import java.util.logging.Logger; import javax.wsdl.Port; +import javax.xml.namespace.QName; import org.apache.axiom.om.OMElement; import org.apache.axis2.AxisFault; @@ -35,6 +36,7 @@ import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.policy.PolicySubject; import org.apache.tuscany.sca.policy.util.PolicyHelper; import org.apache.tuscany.sca.provider.PolicyProvider; import org.apache.tuscany.sca.provider.ServiceBindingProvider; @@ -90,24 +92,18 @@ public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implem configContext.setContextRoot(servletHost.getContextPath()); // Determine the configuration from the bindings "mayProvides" intents - - isSOAP12Required = PolicyHelper.isIntentRequired(wsBinding, Constants.SOAP12_INTENT); - - isMTOMRequired = PolicyHelper.isIntentRequired(wsBinding, Axis2BindingProviderFactory.MTOM_INTENT); - - // this is not correct as there may be other, custom, policies that - // require rampart. For example this is not going to pick up the case - // of external policy attachment - isRampartRequired = PolicyHelper.isIntentRequired(wsBinding, Constants.AUTHENTICATION_INTENT) || - PolicyHelper.isIntentRequired(wsBinding, Constants.CONFIDENTIALITY_INTENT) || - PolicyHelper.isIntentRequired(wsBinding, Constants.INTEGRITY_INTENT); - - - // Apply the configuration from any other policies - - for (PolicyProvider pp : endpoint.getPolicyProviders()) { - pp.configureBinding(this); - } + // TODO - why don't intents get aggregated to EP correctly? + isSOAP12Required = PolicyHelper.isIntentRequired((PolicySubject)wsBinding, Constants.SOAP12_INTENT); + + isMTOMRequired = PolicyHelper.isIntentRequired((PolicySubject)wsBinding, Axis2BindingProviderFactory.MTOM_INTENT); + + // if the endpoint contains any WS Policy expressions then we probably need rampart + // TODO - need to take into account Axis configuration policy also + QName wsPolicyQName = new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "Policy"); + if (PolicyHelper.getPolicies(endpoint, wsPolicyQName).size() > 0){ + isRampartRequired = true; + } + // Update port addresses with runtime information // We can safely assume there is only one port here because you configure @@ -142,7 +138,7 @@ public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implem // Apply the configuration from the mayProvides intents if (isRampartRequired){ - // TODO - do we need to go back to configurator? + Axis2EngineIntegration.loadRampartModule(configContext); } if (isMTOMRequired) { @@ -152,6 +148,7 @@ public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implem if (isJMSRequired){ // TODO - do we need to go back to configurator? } + wsBinding.setURI(deployedURI); // Check the WSDL style as we only support some of them @@ -178,6 +175,12 @@ public class Axis2ServiceBindingProvider extends Axis2BaseBindingProvider implem public void start() { try { createAxisService(deployedURI, wsdlPort); + + // Apply the configuration from any other policies + + for (PolicyProvider pp : endpoint.getPolicyProviders()) { + pp.configureBinding(this); + } if (deployedURI.startsWith("http://") || deployedURI.startsWith("https://") || |