You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mi...@apache.org on 2009/04/09 02:45:16 UTC

svn commit: r763481 - in /ode/branches/APACHE_ODE_1.X: axis2/src/main/java/org/apache/ode/axis2/ axis2/src/main/java/org/apache/ode/axis2/hooks/ axis2/src/main/java/org/apache/ode/axis2/util/ utils/src/main/java/org/apache/ode/utils/

Author: midon
Date: Thu Apr  9 00:45:15 2009
New Revision: 763481

URL: http://svn.apache.org/viewvc?rev=763481&view=rev
Log:
apply SecurityPolicy only when needed & move AxisUtils

Added:
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/AxisUtils.java
Removed:
    ode/branches/APACHE_ODE_1.X/utils/src/main/java/org/apache/ode/utils/AxisUtils.java
Modified:
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java
    ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEAxisService.java

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java?rev=763481&r1=763480&r2=763481&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/SoapExternalService.java Thu Apr  9 00:45:15 2009
@@ -38,6 +38,7 @@
 import org.apache.neethi.Policy;
 import org.apache.neethi.PolicyEngine;
 import org.apache.ode.axis2.util.SoapMessageConverter;
+import org.apache.ode.axis2.util.AxisUtils;
 import org.apache.ode.bpel.epr.EndpointFactory;
 import org.apache.ode.bpel.epr.MutableEndpoint;
 import org.apache.ode.bpel.epr.WSAEndpoint;
@@ -50,10 +51,8 @@
 import org.apache.ode.bpel.iapi.Scheduler;
 import org.apache.ode.il.OMUtils;
 import org.apache.ode.utils.*;
-import org.apache.ode.utils.fs.FileUtils;
 import org.apache.ode.utils.uuid.UUID;
 import org.apache.ode.utils.wsdl.Messages;
-import org.apache.rampart.RampartMessageData;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 
@@ -267,7 +266,6 @@
         } catch (RuntimeException e) {
             throw AxisFault.makeFault(e.getCause() != null ? e.getCause() : e);
         }
-
         AxisService anonymousService = _axisServiceWatchDog.getObserver().get();
         ServiceClient client = _cachedClients.get();
         if (client == null || !client.getAxisService().getName().equals(anonymousService.getName())) {
@@ -275,10 +273,11 @@
             synchronized (_axisConfig) {
                 // if the service has changed, discard the client and create a new one
                 if (client != null) {
-                    if(__log.isDebugEnabled()) __log.debug("Clean up and discard ServiceClient");
+                    if (__log.isDebugEnabled()) __log.debug("Clean up and discard ServiceClient");
                     client.cleanup();
                 }
-                if(__log.isDebugEnabled()) __log.debug("Create a new ServiceClient for "+anonymousService.getName());
+                if (__log.isDebugEnabled())
+                    __log.debug("Create a new ServiceClient for " + anonymousService.getName());
                 client = new ServiceClient(_configContext, null);
                 client.setAxisService(anonymousService);
             }
@@ -287,34 +286,14 @@
 
         // apply the options to the service client
         client.setOptions(_axisOptionsWatchDog.getObserver().get());
-
-        applySecuritySettings(client);
-
         return client;
     }
-    private void applySecuritySettings(ServiceClient serviceClient) throws AxisFault {
-        Options options = serviceClient.getOptions();
-        if (options.getProperty(Properties.PROP_SECURITY_POLICY) != null) {
+
+    private void applySecurityPolicy(Options options) {
+        if (options!=null && options.getProperty(Properties.PROP_SECURITY_POLICY) != null) {
             String policy = (String) options.getProperty(Properties.PROP_SECURITY_POLICY);
-            URI policyUri = new File(policy).toURI();
-            if(__log.isDebugEnabled()) __log.debug("Applying security policy: "+policyUri);
-            try {
-                InputStream policyStream = policyUri.toURL().openStream();
-                try {
-                    Policy policyDoc = PolicyEngine.getPolicy(policyStream);
-                    options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, policyDoc);
-
-                    // make sure the proper modules are engaged
-                    if (!serviceClient.getAxisService().getAxisConfiguration().isEngaged("rampart")
-                            && !serviceClient.getAxisService().isEngaged("rampart")) {
-                        serviceClient.engageModule("rampart");
-                    }
-                } finally {
-                    policyStream.close();
-                }
-            } catch (IOException e) {
-                throw new IllegalArgumentException("Exception while parsing policy: " + policyUri, e);
-            }
+            AxisService service = _axisServiceWatchDog.getObserver().get();
+            AxisUtils.applySecurityPolicy(service, policy);
         }
     }
 
@@ -587,6 +566,8 @@
                 if (__log.isWarnEnabled()) __log.warn("Exception while configuring service: " + _serviceName, e);
                 throw new RuntimeException("Exception while configuring service: " + _serviceName, e);
             }
+            Options options = _axisOptionsWatchDog.getObserver().get();
+            applySecurityPolicy(options);
         }
     }
 
@@ -609,6 +590,8 @@
             // note: don't make this map an instance attribute, so we always get the latest version
             final Map<String, String> properties = _pconf.getEndpointProperties(endpointReference);
             Properties.Axis2.translate(properties, object);
+
+            applySecurityPolicy(object);
         }
     }
 

Modified: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEAxisService.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEAxisService.java?rev=763481&r1=763480&r2=763481&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEAxisService.java (original)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/hooks/ODEAxisService.java Thu Apr  9 00:45:15 2009
@@ -47,8 +47,8 @@
 import org.apache.ode.axis2.OdeFault;
 import org.apache.ode.axis2.util.Axis2UriResolver;
 import org.apache.ode.axis2.util.Axis2WSDLLocator;
+import org.apache.ode.axis2.util.AxisUtils;
 import org.apache.ode.bpel.iapi.ProcessConf;
-import org.apache.ode.utils.AxisUtils;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.w3c.dom.Element;

Added: ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/AxisUtils.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/AxisUtils.java?rev=763481&view=auto
==============================================================================
--- ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/AxisUtils.java (added)
+++ ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/util/AxisUtils.java Thu Apr  9 00:45:15 2009
@@ -0,0 +1,103 @@
+package org.apache.ode.axis2.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.deployment.ServiceBuilder;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisModule;
+import org.apache.axis2.description.PolicyInclude;
+import org.apache.axis2.description.AxisDescription;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.neethi.PolicyEngine;
+import org.apache.neethi.Policy;
+import org.apache.rampart.RampartMessageData;
+
+import javax.xml.stream.XMLStreamException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.File;
+import java.net.URL;
+import java.net.URI;
+
+/**
+ *
+ */
+public class AxisUtils {
+
+    private static final Log log = LogFactory.getLog(AxisUtils.class);
+
+    public static void configureService(AxisService axisService, URL service_file) throws IOException, XMLStreamException, AxisFault {
+        configureService(new ConfigurationContext(axisService.getAxisConfiguration()), axisService, service_file);
+    }
+
+    /**
+     * Configure a service instance woth the specified service.xml document.
+     * If modules are mentioned in the document, <code>this</code> method will make sure they are properly engaged and engage them if necessary.
+     * The modules have to be available in the module repository otherwise an AxisFault will be thrown.
+     *
+     * @param axisService  the service to configure
+     * @param service_file the service.xm document to configure the service with
+     * @throws IOException
+     * @throws XMLStreamException
+     * @throws org.apache.axis2.AxisFault if a module listed in the service.xml is not available in the module repository
+     */
+    public static void configureService(ConfigurationContext configCtx, AxisService axisService, URL service_file) throws IOException, XMLStreamException, AxisFault {
+        InputStream ais = service_file.openStream();
+        log.debug("Looking for Axis2 service configuration file: " + service_file);
+        if (ais != null) {
+            log.debug("Configuring service " + axisService.getName() + " using: " + service_file);
+            try {
+                if (configCtx == null)
+                    configCtx = new ConfigurationContext(axisService.getAxisConfiguration());
+                ServiceBuilder builder = new ServiceBuilder(ais, configCtx, axisService);
+                builder.populateService(builder.buildOM());
+            } finally {
+                ais.close();
+            }
+            // the service builder only updates the module list but do not engage them
+            // modules have to be engaged manually,
+            for (int i = 0; i < axisService.getModules().size(); i++) {
+                String moduleRef = (String) axisService.getModules().get(i);
+                AxisModule module = axisService.getAxisConfiguration().getModule(moduleRef);
+                if (module != null) {
+                    axisService.engageModule(module);
+                } else {
+                    throw new AxisFault("Unable to engage module: " + moduleRef);
+                }
+            }
+        }
+    }
+
+    public static void applySecurityPolicy(AxisService service, String policy_file) {
+        URI policyUri = new File(policy_file).toURI();
+        if (log.isDebugEnabled()) log.debug("Applying security policy: " + policyUri);
+        try {
+            InputStream policyStream = policyUri.toURL().openStream();
+            try {
+                Policy policyDoc = PolicyEngine.getPolicy(policyStream);
+                service.getPolicyInclude().addPolicyElement(PolicyInclude.AXIS_SERVICE_POLICY, policyDoc);
+                // make sure the proper modules are engaged, if they are available
+                engageModules(service, "rampart", "rahas");
+            } finally {
+                policyStream.close();
+            }
+        } catch (IOException e) {
+            throw new IllegalArgumentException("Exception while parsing policy: " + policyUri, e);
+        }
+    }
+
+    public static void engageModules(AxisDescription description, String... modules) throws AxisFault {
+        for (String m : modules) {
+            if (description.getAxisConfiguration().getModule(m) != null) {
+                if (!description.getAxisConfiguration().isEngaged(m) && !description.isEngaged(m)) {
+                    description.engageModule(description.getAxisConfiguration().getModule(m));
+                }
+            } else {
+                if (log.isDebugEnabled()) log.debug("Module " + m + " is not available.");
+            }
+        }
+    }
+}