Author: keith
Date: Wed Jan 16 07:20:30 2008
New Revision: 12353

Log:

We need to hide the wso2mashup-adminservice from the UI, but when we do this 
WSAS does not persist the service. On the other hand we want WSAS to persist 
the service cause we need to apply a security
configuration on it. Hence we add this service into the WSAS DB explicitly.



Modified:
   trunk/mashup/java/modules/admin/service/META-INF/services.xml
   trunk/mashup/java/modules/core/conf/server.xml
   trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
   
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java

Modified: trunk/mashup/java/modules/admin/service/META-INF/services.xml
==============================================================================
--- trunk/mashup/java/modules/admin/service/META-INF/services.xml       
(original)
+++ trunk/mashup/java/modules/admin/service/META-INF/services.xml       Wed Jan 
16 07:20:30 2008
@@ -14,7 +14,7 @@
   ~ limitations under the License.
   -->
 
-<serviceGroup name="wso2mashup-adminService">
+<serviceGroup name="wso2mashup-adminServices">
     <module ref="wso2mashup-admin"/>
     <service name="MashupLoginServiceUT" scope="transportsession">
         <Description>

Modified: trunk/mashup/java/modules/core/conf/server.xml
==============================================================================
--- trunk/mashup/java/modules/core/conf/server.xml      (original)
+++ trunk/mashup/java/modules/core/conf/server.xml      Wed Jan 16 07:20:30 2008
@@ -381,7 +381,7 @@
             <Name>wso2mashup-scraperService</Name>
             <Name>wso2mashup-coreservices-servicemetadatalister</Name>
             <Name>wso2mashup-coreservices-servicesharinghelper</Name>
-            <!--<Name>wso2mashup-adminServices</Name>-->
+            <Name>wso2mashup-adminServices</Name>
         </ServiceGroups>
         <Modules>
             <Name>wso2wsas-admin</Name>

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
Wed Jan 16 07:20:30 2008
@@ -98,7 +98,7 @@
 
     public static final String SELF_REGISTRATION_ENABLED = 
"self_registration_enabled";
 
-    public static final String MASHUP_ADMIN_SERVICEGROUP = 
"wso2mashup-adminService";
+    public static final String MASHUP_ADMIN_SERVICEGROUP = 
"wso2mashup-adminServices";
     public static final String MASHUP_LOGIN_SERVICEUT = "MashupLoginServiceUT";
     public static final String MASHUP_LOGIN_SERVICEIC = "MashupLoginServiceIC";
     public static final String USER_LOGGED_IN = "UserLoggedIn";

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java
==============================================================================
--- 
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java
   (original)
+++ 
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java
   Wed Jan 16 07:20:30 2008
@@ -18,6 +18,8 @@
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.deployment.DeploymentEngine;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.log4j.Logger;
 import org.wso2.mashup.MashupConstants;
@@ -30,13 +32,22 @@
 import org.wso2.utils.ServerException;
 import org.wso2.wsas.ServerInitializer;
 import org.wso2.wsas.admin.service.SecurityScenarioConfigAdmin;
+import org.wso2.wsas.persistence.PersistenceManager;
+import org.wso2.wsas.persistence.dataobject.KeyStoreDO;
+import org.wso2.wsas.persistence.dataobject.ServiceGroupDO;
+import org.wso2.wsas.persistence.dataobject.ServiceIdentifierDO;
+import org.wso2.wsas.persistence.dataobject.ServiceDO;
+import org.wso2.wsas.persistence.exception.ServiceGroupNotFoundException;
+import org.wso2.wsas.util.WsasUtils;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 
 public class MashupServerInitializer implements ServerInitializer {
 
     private static Logger log = 
Logger.getLogger(MashupServerInitializer.class);
+    PersistenceManager persistenceMgr = new PersistenceManager();
 
     public void init(ConfigurationContext configurationContext) throws 
AxisFault, ServerException {
         AxisConfiguration configuration = 
configurationContext.getAxisConfiguration();
@@ -66,9 +77,18 @@
                 deploymentEngine.setDirectoryToExtensionMappingMap(newMap);
             }
 
+            persistMashupAdminService(configuration);
+
             SecurityScenarioConfigAdmin admin = new 
SecurityScenarioConfigAdmin();
+
+            // We need the name of the KeyStore in order to give its details 
for the policy.
+            // Although there can be many keystores we use the default one
+            KeyStoreDO keyStore = new KeyStoreDO();
+            KeyStoreDO[] storeDOs = persistenceMgr.getKeyStores();
+            String keyStoreName = storeDOs[0].getKeyStoreName();
+
             
admin.assignUsersAndRolesAndKeyStores(MashupConstants.MASHUP_LOGIN_SERVICEUT, 
null, "scenario21",
-                    new String [] {"wso2is.jks"}, "wso2is.jks",
+                    new String [] {keyStoreName}, keyStoreName,
                                       new String[] { },
                                       new String[] { 
MashupConstants.MASHUP_USER_ROLE });
 
@@ -128,4 +148,84 @@
             // Exception jumps due to a Registry Bug
         }
     }
+
+    private void persistMashupAdminService(AxisConfiguration configuration) {
+        // We need to add this service group to the WSAS database explicitly 
here cause
+        // 1. we need this service hidden
+        // 2. We need to apply a policy on this service
+        // WSAS does not persist hidden services
+        AxisServiceGroup axisServiceGroup = 
configuration.getServiceGroup(MashupConstants.MASHUP_ADMIN_SERVICEGROUP);
+
+        ServiceGroupDO sgDO =
+                
persistenceMgr.getServiceGroup(axisServiceGroup.getServiceGroupName());
+        if (sgDO == null) {
+            addServiceGroup(axisServiceGroup);
+        } else {
+
+            // Check whether the artifact has been updated, if so we need to 
purge all
+            // database entries and treat this as a new service group addition
+            if (!sgDO.getServiceArtifactUpdateTime().
+                    equals(WsasUtils.lastUpdatedTime(axisServiceGroup))) {
+
+                log.warn("The service artifact of the " +
+                        axisServiceGroup.getServiceGroupName() +
+                        " service group has changed. Removing all database 
entries and " +
+                        "handling this as a new service addition.");
+                deleteServiceGroup(axisServiceGroup);
+                addServiceGroup(axisServiceGroup);
+            } else {
+                try {
+                    persistenceMgr.handleExistingServiceGroupInit(sgDO, 
axisServiceGroup);
+                } catch (Exception e) {
+                    String msg = "Could not handle initialization of existing 
service group [" +
+                            axisServiceGroup.getServiceGroupName() + "]";
+                    log.error(msg, e);
+                }
+            }
+        }
+
+        Iterator services = axisServiceGroup.getServices();
+        while (services.hasNext()) {
+            AxisService axisService = (AxisService) services.next();
+            String serviceName = axisService.getName();
+            String serviceVersion = ServiceIdentifierDO.EMPTY_SERVICE_VERSION;
+            ServiceDO serviceDO = persistenceMgr.getService(serviceName, 
serviceVersion);
+
+            if (serviceDO == null) {  // is this a new serviceDO? If so, 
register it in the DB
+                try {
+                    persistenceMgr.handleNewServiceAddition(axisService);
+                } catch (Exception e) {
+                    String msg = "Could not handle initialization of new 
service [" +
+                            axisService.getName() + "]";
+                    log.error(msg, e);
+                }
+            } else {  // The serviceDO is already registered in the DB
+                try {
+                    persistenceMgr.handleExistingServiceInit(serviceDO, 
axisService, configuration);
+                } catch (Exception e) {
+                    String msg = "Could not handle initialization of existing 
service [" +
+                            axisService.getName() + "]";
+                    log.error(msg, e);
+                }
+            }
+        }
+    }
+
+    private void addServiceGroup(AxisServiceGroup axisServiceGroup) {
+        try {
+            persistenceMgr.handleNewServiceGroupAddition(axisServiceGroup);
+        } catch (Exception e) {
+            String msg = "Could not handle initialization of new service group 
[" +
+                         axisServiceGroup.getServiceGroupName() + "]";
+            log.error(msg, e);
+        }
+    }
+
+    private void deleteServiceGroup(AxisServiceGroup axisServiceGroup) {
+        try {
+            persistenceMgr.deleteServiceGroup(axisServiceGroup);
+        } catch (ServiceGroupNotFoundException e) {
+            log.error("Service group not found", e);
+        }
+    }
 }

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to