Author: keith
Date: Wed Jan 23 07:10:40 2008
New Revision: 12774
Log:
Implementing deleteUserServices
Modified:
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/userprofile/ManageUsers.java
Modified:
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
==============================================================================
---
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
(original)
+++
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
Wed Jan 23 07:10:40 2008
@@ -16,6 +16,7 @@
package org.wso2.mashup.admin.service;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.deployment.DeploymentEngine;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisOperation;
@@ -35,12 +36,16 @@
import org.wso2.wsas.persistence.dataobject.ServiceDO;
import org.wso2.wsas.persistence.dataobject.ServiceIdentifierDO;
import org.wso2.wsas.persistence.exception.ServiceNotFoundException;
+import org.wso2.utils.ServerConfiguration;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
+import java.util.ArrayList;
public class MashupAdminService {
@@ -338,6 +343,47 @@
return Boolean.valueOf(success);
}
+ public boolean deleteUserServices(String username) throws MashupFault {
+ boolean success;
+ ConfigurationContext context =
MessageContext.getCurrentMessageContext().getConfigurationContext();
+ JDBCRegistry registry =
+ (JDBCRegistry)
context.getAxisConfiguration().getParameterValue(
+ RegistryConstants.REGISTRY);
+ Map paramsMap = new HashMap(1);
+ paramsMap.put("1", username);
+ try {
+ Resource resultsCollection =
registry.executeQuery(MashupConstants.MY_MASHUPS_QUERY_PATH, paramsMap);
+ String[] resultPaths = (String[]) resultsCollection.getContent();
+ for (int j = 0; j < resultPaths.length; j++) {
+ String[] values = resultPaths[j].split("\\/");
+ String mashupName = values[values.length - 1];
+ if (mashupName.contains("?")) {
+ mashupName = mashupName.substring(0,
mashupName.indexOf("?"));
+ }
+ if (mashupName.contains(";")) {
+ mashupName = mashupName.substring(0,
mashupName.indexOf(";"));
+ }
+ deleteService(username + MashupConstants.SEPARATOR_CHAR +
mashupName);
+ }
+ ServerConfiguration serverCofig =
ServerConfiguration.getInstance();
+ String repoLocation =
+
serverCofig.getFirstProperty(ServerConfiguration.AXIS2_CONFIG_REPO_LOCATION);
+ File file = new File(new File(repoLocation, "scripts"), username);
+ deleteDir(file);
+ DeploymentEngine deploymentEngine =
+ (DeploymentEngine)
context.getAxisConfiguration().getConfigurator();
+ HashMap map = deploymentEngine.getDirectoryToExtensionMappingMap();
+ HashMap newMap = (HashMap) map.clone();
+ newMap.remove("scripts/" + username);
+ deploymentEngine.setDirectoryToExtensionMappingMap(newMap);
+ success = true;
+ } catch (RegistryException e) {
+ throw new MashupFault("Exception occured while deleting services
of user " + username + ". Reason : " +
+ e.getMessage(), e);
+ }
+ return success;
+ }
+
private static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/userprofile/ManageUsers.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/userprofile/ManageUsers.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/userprofile/ManageUsers.java
Wed Jan 23 07:10:40 2008
@@ -15,9 +15,18 @@
*/
package org.wso2.mashup.webapp.userprofile;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.rpc.client.RPCServiceClient;
+import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
import org.wso2.mashup.MashupConstants;
+import org.wso2.mashup.MashupFault;
import org.wso2.mashup.webapp.utils.RegistryUtils;
import org.wso2.registry.RegistryConstants;
import org.wso2.registry.secure.SecureRegistry;
@@ -25,8 +34,11 @@
import org.wso2.usermanager.UserManagerException;
import org.wso2.usermanager.UserStoreAdmin;
import org.wso2.usermanager.UserStoreReader;
+import org.wso2.wsas.ServerManager;
import javax.servlet.http.HttpServletRequest;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
import java.util.HashMap;
import java.util.Map;
@@ -94,7 +106,7 @@
* @param userName Identifier of user to be deleted.
* @return true if deletion succeeded.
*/
- public static boolean deleteUser(HttpServletRequest request, String
userName) {
+ public static boolean deleteUser(HttpServletRequest request, String
userName) throws MashupFault {
boolean deletionSuccess = false;
SecureRegistry registry =
(SecureRegistry)
request.getSession().getAttribute(MashupConstants.USER_REGISTRY);
@@ -104,7 +116,7 @@
if (isUserDeletable(realm, userName)) {
UserStoreAdmin userStoreAdmin = realm.getUserStoreAdmin();
userStoreAdmin.deleteUser(userName);
- deleteUserResources(registry, userName);
+ deleteUserResources(userName, request.getSession().getId());
deletionSuccess = true;
}
} catch (UserManagerException e) {
@@ -116,16 +128,37 @@
/**
* Deletes resources created/owned by the user.
*
- * @param registry Instance of the secure registry.
* @param userName name of user, who's resources must be deleted.
* @return true if the purge succeeded.
* todo: implement removal of services and all registry based resources.
*/
- private static boolean deleteUserResources(SecureRegistry registry, String
userName) {
- boolean purgeSuccess = true;
-
- // Delete services
-
+ private static boolean deleteUserResources(String userName, String
cookieString) throws MashupFault {
+ boolean purgeSuccess;
+ try {
+ ServerManager serverManager = ServerManager.getInstance();
+ ConfigurationContext context = serverManager.configContext;
+ RPCServiceClient client = new RPCServiceClient();
+ Options options = client.getOptions();
+ options.setAction("urn:deleteUserServices");
+ options.setTo(new EndpointReference("http://localhost:" +
serverManager.getHttpPort() +
+ context.getContextRoot() + context.getServicePath() +
+ "/MashupAdminService/deleteUserServices"));
+ options.setProperty(HTTPConstants.COOKIE_STRING, "JSESSIONID=" +
cookieString);
+ options.setManageSession(true);
+ client.setOptions(options);
+ QName opAddEntry = new
QName("http://service.admin.mashup.wso2.org/xsd", "deleteUserServices");
+
+ // parameters to the service ServiceName string, service file name,
+ // dataHandler of the bundled archive
+ Object[] opAddEntryArgs = new Object[] { userName };
+ OMElement omElement = client.invokeBlocking(opAddEntry,
opAddEntryArgs);
+ OMElement returnElement = omElement.getFirstChildWithName(new
QName(
+ "http://service.admin.mashup.wso2.org/xsd", "return"));
+ purgeSuccess =
Boolean.valueOf(returnElement.getText()).booleanValue();
+ } catch (AxisFault axisFault) {
+ throw new MashupFault("Exception occured while deleting services
of user " + userName + ". Reason : " +
+ axisFault.getMessage(), axisFault);
+ }
return purgeSuccess;
}
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev