http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java
 
b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java
deleted file mode 100644
index 2ab0e8c..0000000
--- 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.stratos.tenant.mgt.realm;
-
-import java.util.Map;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.util.UUIDGenerator;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.um.ws.api.WSRealm;
-import org.wso2.carbon.um.ws.api.WSRemoteUserMgtConstants;
-import org.wso2.carbon.user.api.RealmConfiguration;
-import org.wso2.carbon.user.api.TenantMgtConfiguration;
-import org.wso2.carbon.user.core.UserStoreException;
-import org.wso2.carbon.user.core.config.RealmConfigXMLProcessor;
-import 
org.wso2.carbon.user.core.config.multitenancy.MultiTenantRealmConfigBuilder;
-import org.wso2.carbon.user.core.jdbc.JDBCRealmConstants;
-import org.wso2.carbon.user.core.tenant.Tenant;
-
-/**
- * This class is no more used by cloud manager or elsewhere.
- * Hence deprecated and will be removed eventually.
- */
-@Deprecated
-public class CloudWSRealmConfigBuilder implements 
MultiTenantRealmConfigBuilder {
-
-    private static final Log log = 
LogFactory.getLog(CloudWSRealmConfigBuilder.class);
-
-
-    /**
-     * This method is called on server startup by DefaultRealmService by 
non-Idaas cloud services
-     * 
-     * This is not called on ws.api startup.
-     */
-    public RealmConfiguration getRealmConfigForTenantToCreateRealm(
-            RealmConfiguration bootStrapConfig, RealmConfiguration 
persistedConfig, int tenantId)
-            throws UserStoreException {
-        RealmConfiguration realmConfig;
-        try {
-            if 
(persistedConfig.getRealmClassName().equals(WSRealm.class.getName())) {
-                realmConfig = persistedConfig;
-            } else {
-                realmConfig = bootStrapConfig.cloneRealmConfiguration();
-                realmConfig.setTenantId(tenantId);
-            }
-            if (log.isDebugEnabled()) {
-                OMElement omElement = 
RealmConfigXMLProcessor.serialize(realmConfig);
-                log.debug("Creating realm from **** " + omElement.toString());
-            }
-        } catch (Exception e) {
-            String msg = e.getMessage();
-            log.error(msg, e);
-            throw new UserStoreException(msg);
-        }
-        return realmConfig;
-    }
-
-    public RealmConfiguration 
getRealmConfigForTenantToCreateRealmOnTenantCreation(
-            RealmConfiguration bootStrapConfig, RealmConfiguration 
persistedConfig, int tenantId)
-            throws UserStoreException{
-        RealmConfiguration realmConfig;
-        try {
-            realmConfig = bootStrapConfig.cloneRealmConfiguration();
-            realmConfig.setRealmClassName("org.wso2.carbon.um.ws.api.WSRealm");
-            
-            realmConfig.setAdminPassword(UUIDGenerator.getUUID());
-            Map<String, String> realmProps = realmConfig.getRealmProperties();
-            realmProps.remove(JDBCRealmConstants.URL);
-            realmProps.remove(JDBCRealmConstants.DRIVER_NAME);
-            realmProps.remove(JDBCRealmConstants.USER_NAME);
-            realmProps.remove(JDBCRealmConstants.PASSWORD);
-            
-            realmConfig.setTenantId(tenantId);
-
-            if (log.isDebugEnabled()) {
-                OMElement omElement = 
RealmConfigXMLProcessor.serialize(realmConfig);
-                log.debug("Creating realm from (On tenant creation)**** " + 
omElement.toString());
-            }
-
-        } catch (Exception e) {
-            String msg = e.getMessage();
-            log.error(msg, e);
-            throw new UserStoreException(msg);
-        }
-        return realmConfig;
-    }
-
-
-    public RealmConfiguration 
getRealmConfigForTenantToPersist(RealmConfiguration bootStrapConfig,
-                                                               
TenantMgtConfiguration tenantMgtConfig,
-                                                               Tenant 
tenantInfo, int tenantId)
-            throws UserStoreException {
-        RealmConfiguration realmConfig;
-        try {
-            realmConfig = bootStrapConfig.cloneRealmConfiguration();
-            realmConfig.setAdminUserName(tenantInfo.getAdminName());
-            realmConfig.setAdminPassword(UUIDGenerator.getUUID());
-            Map<String, String> realmProps = realmConfig.getRealmProperties();
-            realmProps.remove(JDBCRealmConstants.URL);
-            realmProps.remove(JDBCRealmConstants.DRIVER_NAME);
-            realmProps.remove(JDBCRealmConstants.USER_NAME);
-            realmProps.remove(JDBCRealmConstants.PASSWORD);
-            realmProps.remove(WSRemoteUserMgtConstants.SERVER_URL);
-            realmProps.remove(WSRemoteUserMgtConstants.USER_NAME);
-            realmProps.remove(WSRemoteUserMgtConstants.PASSWORD);
-            
realmProps.remove(WSRemoteUserMgtConstants.SINGLE_USER_AUTHENTICATION);
-            realmProps.put("MultiTenantRealmConfigBuilder", 
IdaasWSRealmConfigBuilder.class.getName());
-            realmConfig.setTenantId(tenantId);
-            if (log.isDebugEnabled()) {
-                OMElement omElement = 
RealmConfigXMLProcessor.serialize(realmConfig);
-                log.debug("Saving RealmConfiguration **** " + 
omElement.toString());
-            }
-
-        } catch (Exception e) {
-            String msg = e.getMessage();
-            log.error(msg, e);
-            throw new UserStoreException(msg);
-        }
-        return realmConfig;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java
 
b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java
deleted file mode 100644
index 09a1f49..0000000
--- 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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.stratos.tenant.mgt.realm;
-
-import java.util.Map;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.user.api.RealmConfiguration;
-import org.wso2.carbon.user.api.TenantMgtConfiguration;
-import org.wso2.carbon.user.core.UserStoreException;
-import org.wso2.carbon.user.core.config.RealmConfigXMLProcessor;
-import 
org.wso2.carbon.user.core.config.multitenancy.MultiTenantRealmConfigBuilder;
-import org.wso2.carbon.user.core.jdbc.JDBCRealmConstants;
-import org.wso2.carbon.user.core.tenant.Tenant;
-
-public class IdaasWSRealmConfigBuilder implements 
MultiTenantRealmConfigBuilder {
-    
-    private static final Log log = 
LogFactory.getLog(CloudWSRealmConfigBuilder.class);
-
-    /**
-     * This method is called, on server startup by DefaultRealmService by 
Idaas only
-     * 
-     * This is not called on ws.api startup or by any non-Idaas servers
-     */
-    public RealmConfiguration getRealmConfigForTenantToCreateRealm(
-            RealmConfiguration bootStrapConfig, RealmConfiguration 
persistedConfig, int tenantId)
-            throws UserStoreException {
-        RealmConfiguration realmConfig;
-        try {
-                realmConfig = persistedConfig;
-               // now this is Idaas
-                Map<String, String> realmProps = 
realmConfig.getRealmProperties();
-                Map<String, String> bootStrapProps = 
bootStrapConfig.getRealmProperties();
-                realmProps.put(JDBCRealmConstants.URL, 
bootStrapProps.get(JDBCRealmConstants.URL));
-                realmProps.put(JDBCRealmConstants.DRIVER_NAME, 
bootStrapProps.get(
-                        JDBCRealmConstants.DRIVER_NAME));
-                realmProps.put(JDBCRealmConstants.USER_NAME, 
bootStrapProps.get(
-                        JDBCRealmConstants.USER_NAME));
-                realmProps.put(JDBCRealmConstants.PASSWORD, bootStrapProps.get(
-                        JDBCRealmConstants.PASSWORD));
-                realmConfig.setTenantId(tenantId);
-
-                if(log.isDebugEnabled()) {
-                    OMElement omElement = 
RealmConfigXMLProcessor.serialize(realmConfig);
-                    log.debug("Creating realm from **** " + 
omElement.toString());
-                }
-                
-        } catch (Exception e) {
-            String msg = e.getMessage();
-            log.error(msg, e);
-            throw new UserStoreException(msg);
-        }
-        return realmConfig;
-    }
-    
-    public RealmConfiguration 
getRealmConfigForTenantToCreateRealmOnTenantCreation(
-            RealmConfiguration bootStrapConfig, RealmConfiguration 
persistedConfig, int tenantId)
-            throws UserStoreException{
-        //never called
-        return null;
-    }
-
-    public RealmConfiguration 
getRealmConfigForTenantToPersist(RealmConfiguration bootStrapConfig,
-                                                               
TenantMgtConfiguration tenantMgtConfig,
-                                                               Tenant 
tenantInfo, int tenantId)
-            throws UserStoreException {
-        //never called
-        return null;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java
 
b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java
deleted file mode 100644
index 4555a89..0000000
--- 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java
+++ /dev/null
@@ -1,141 +0,0 @@
-package org.apache.stratos.tenant.mgt.services;
-/*
- *
- * 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.
- *
-*/
-
-
-import org.apache.stratos.tenant.mgt.exception.TenantManagementException;
-import org.apache.stratos.tenant.mgt.internal.TenantMgtServiceComponent;
-import org.apache.stratos.tenant.mgt.util.TenantMgtUtil;
-import org.apache.stratos.common.beans.TenantInfoBean;
-import org.apache.stratos.common.exception.ApacheStratosException;
-import org.wso2.carbon.user.api.RealmConfiguration;
-import org.wso2.carbon.user.api.TenantMgtConfiguration;
-import org.wso2.carbon.user.api.UserStoreException;
-import org.wso2.carbon.user.core.UserCoreConstants;
-import 
org.wso2.carbon.user.core.config.multitenancy.MultiTenantRealmConfigBuilder;
-import org.wso2.carbon.user.core.tenant.Tenant;
-import org.wso2.carbon.user.core.tenant.TenantManager;
-import org.apache.stratos.tenant.mgt.core.TenantPersistor;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.ws.security.util.UUIDGenerator;
-
-public class GAppTenantRegistrationService {
-       
-    private static final String GOOGLE_APPS_IDP_NAME = "GoogleApps";
-    
-    private static final Log log = 
LogFactory.getLog(GAppTenantRegistrationService.class);
-    
-    
-    public boolean isRegisteredAsGoogleAppDomain(String domain) throws 
TenantManagementException {
-
-        TenantManager tenantManager = 
-            TenantMgtServiceComponent.getRealmService().getTenantManager();
-        try {
-            int tenantId = tenantManager.getTenantId(domain);
-
-            if (tenantId == -1) {
-                return false;
-            }
-
-            Tenant tenant = (Tenant) tenantManager.getTenant(tenantId);
-            RealmConfiguration realmConfig = tenant.getRealmConfig();
-            String value = realmConfig.getUserStoreProperties().get(
-                            
UserCoreConstants.RealmConfig.PROPERTY_EXTERNAL_IDP);
-
-            if (value == null) {
-                throw new TenantManagementException(
-                        "This domain has been already registered as a 
non-Google App domain");
-            }
-
-            if (value.equals(GOOGLE_APPS_IDP_NAME)) {
-                return true;
-            }
-            
-            throw new TenantManagementException(
-                    "This domain has been already registered with a different 
External IdP");
-        } catch (UserStoreException e) {
-            log.error(e.getMessage(), e);
-            throw new TenantManagementException("System error occured while 
connecting user store");
-        }
-    }
-    
-    public boolean registerGoogleAppsTenant(
-                                TenantInfoBean tenantInfoBean)throws 
TenantManagementException {
-        try {
-            int tenantId = -1;
-            Tenant tenant = TenantMgtUtil.initializeTenant(tenantInfoBean);
-            TenantPersistor tenantPersistor = new TenantPersistor();
-
-            MultiTenantRealmConfigBuilder builder =
-                    
TenantMgtServiceComponent.getRealmService().getMultiTenantRealmConfigBuilder();
-            TenantMgtConfiguration tenantMgtConfiguration =
-                    
TenantMgtServiceComponent.getRealmService().getTenantMgtConfiguration();
-            RealmConfiguration bootStrapRealmConfig =
-                    
TenantMgtServiceComponent.getRealmService().getBootstrapRealmConfiguration();
-            RealmConfiguration realmConfigToPersist =
-                    
builder.getRealmConfigForTenantToPersist(bootStrapRealmConfig,
-                            tenantMgtConfiguration, tenant, -1);
-            realmConfigToPersist.getUserStoreProperties().put(
-                    UserCoreConstants.RealmConfig.PROPERTY_EXTERNAL_IDP, 
GOOGLE_APPS_IDP_NAME);
-            tenant.setRealmConfig(realmConfigToPersist);
-            tenant.setAdminPassword(UUIDGenerator.getUUID());
-
-            tenantId = tenantPersistor.persistTenant(tenant);
-            tenantInfoBean.setTenantId(tenantId);
-
-            TenantMgtUtil.addClaimsToUserStoreManager(tenant);
-
-            // Notify tenant addition
-            try {
-                TenantMgtUtil.triggerAddTenant(tenantInfoBean);
-            } catch (ApacheStratosException e) {
-                String msg = "Error in notifying tenant addition.";
-                log.error(msg, e);
-                throw new Exception(msg, e);
-            }
-
-            // adding the subscription entry
-            try {
-                if (TenantMgtServiceComponent.getBillingService() != null) {
-                    tenantInfoBean.setTenantId(tenantId); // required for the 
following method
-                    
TenantMgtServiceComponent.getBillingService().addUsagePlan(tenant,
-                            tenantInfoBean.getUsagePlan());
-                    if (log.isDebugEnabled()) {
-                        log.debug("Subscription added successfully for the 
tenant: " +
-                                  tenantInfoBean.getTenantDomain());
-                    }
-                }
-            } catch (Exception e) {
-                log.error("Error occurred while adding the subscription for 
tenant: " +
-                          tenantInfoBean.getTenantDomain() + " " + 
e.getMessage(), e);
-            }
-
-            
TenantMgtServiceComponent.getRealmService().getTenantManager().activateTenant(tenantId);
-            return true;
-        } catch (Exception e) {
-            log.error("Error creating tenant for GooogleApp market place 
implementation", e);
-            throw new TenantManagementException(
-                    "Error creating tenant for GooogleApp market place 
implementation", e);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java
 
b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java
deleted file mode 100644
index d4140f8..0000000
--- 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.apache.stratos.tenant.mgt.services;
-/*
- *
- * 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.
- *
-*/
-
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.UnsupportedCallbackException;
-
-import org.apache.ws.security.WSPasswordCallback;
-
-public class InMemoryPasswordcallbackHandler  implements CallbackHandler {
-
-    private static Map<String, String> keystorePassword = new HashMap<String, 
String>();
-
-    public void handle(Callback[] callbacks)
-            throws IOException, UnsupportedCallbackException {
-
-        for (int i = 0; i < callbacks.length; i++) {
-
-            if (callbacks[i] instanceof WSPasswordCallback) {
-                WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
-                String id = pc.getIdentifier();
-                if (keystorePassword.get(id) != null) {
-                    pc.setPassword(keystorePassword.get(id));
-                } else {
-                    throw new UnsupportedCallbackException(callbacks[i], "no 
password found for " + id);
-                }
-            }
-
-        }
-    }
-
-    public static void addUser(String username, String password) {
-        keystorePassword.put(username, password);
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java
 
b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java
deleted file mode 100644
index 0b3290a..0000000
--- 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java
+++ /dev/null
@@ -1,552 +0,0 @@
-/*
- * 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.stratos.tenant.mgt.services;
-
-import org.wso2.carbon.core.AbstractAdmin;
-import org.wso2.carbon.registry.core.session.UserRegistry;
-import org.apache.stratos.common.beans.TenantInfoBean;
-import org.apache.stratos.common.exception.ApacheStratosException;
-import org.apache.stratos.common.util.ClaimsMgtUtil;
-import org.apache.stratos.common.util.CommonUtil;
-import org.apache.stratos.tenant.mgt.beans.PaginatedTenantInfoBean;
-import 
org.apache.stratos.tenant.mgt.core.internal.TenantMgtCoreServiceComponent;
-import org.apache.stratos.tenant.mgt.internal.TenantMgtServiceComponent;
-import org.apache.stratos.tenant.mgt.util.TenantMgtUtil;
-import org.wso2.carbon.user.core.UserRealm;
-import org.wso2.carbon.user.core.UserStoreException;
-import org.wso2.carbon.user.core.UserStoreManager;
-import org.wso2.carbon.user.core.tenant.Tenant;
-import org.wso2.carbon.user.core.tenant.TenantManager;
-import org.wso2.carbon.utils.DataPaginator;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-import org.apache.stratos.tenant.mgt.core.TenantPersistor;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * This is the admin Web service which is used for managing tenants
- */
-public class TenantMgtAdminService extends AbstractAdmin {
-    private static final Log log = 
LogFactory.getLog(TenantMgtAdminService.class);
-
-    /**
-     * super admin adds a tenant
-     *
-     * @param tenantInfoBean tenant info bean
-     * @return UUID
-     * @throws Exception if error in adding new tenant.
-     */
-    public String addTenant(TenantInfoBean tenantInfoBean) throws Exception {
-        try {
-            CommonUtil.validateEmail(tenantInfoBean.getEmail());
-        } catch (Exception e) {
-            String msg = "Invalid email is provided.";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-        String tenantDomain = tenantInfoBean.getTenantDomain();
-        TenantMgtUtil.validateDomain(tenantDomain);
-        checkIsSuperTenantInvoking();
-        Tenant tenant = TenantMgtUtil.initializeTenant(tenantInfoBean);
-        TenantPersistor persistor = new TenantPersistor();
-        // not validating the domain ownership, since created by super tenant
-        int tenantId = persistor.persistTenant(tenant, false, 
tenantInfoBean.getSuccessKey(),
-                                tenantInfoBean.getOriginatedService(),false);
-        tenantInfoBean.setTenantId(tenantId);
-        
-        TenantMgtUtil.addClaimsToUserStoreManager(tenant);
-        
-        notifyTenantAddition(tenantInfoBean);
-        //adding the subscription entry
-        /*try {
-            if (TenantMgtServiceComponent.getBillingService() != null) {
-                TenantMgtServiceComponent.getBillingService().
-                        addUsagePlan(tenant, tenantInfoBean.getUsagePlan());
-                if (log.isDebugEnabled()) {
-                    log.debug("Subscription added successfully for the tenant: 
" +
-                            tenantInfoBean.getTenantDomain());
-                }
-            }
-        } catch (Exception e) {
-            String msg = "Error occurred while adding the subscription for 
tenant: " + tenantDomain;
-            log.error(msg, e);
-        }*/
-
-        // For the super tenant tenant creation, tenants are always activated 
as they are created.
-        TenantMgtUtil.activateTenantInitially(tenantInfoBean, tenantId);
-
-        return TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
-    }
-
-
-
-    private void notifyTenantAddition(TenantInfoBean tenantInfoBean) throws 
Exception {
-        //Notify tenant addition
-        try {
-            TenantMgtUtil.triggerAddTenant(tenantInfoBean);
-        } catch (ApacheStratosException e) {
-            String msg = "Error in notifying tenant addition.";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-    }
-
-    private void checkIsSuperTenantInvoking() throws Exception {
-        UserRegistry userRegistry = (UserRegistry) getGovernanceRegistry();
-        if (userRegistry == null) {
-            log.error("Security Alert! User registry is null. A user is trying 
create a tenant "
-                    + " without an authenticated session.");
-            throw new Exception("Invalid data."); // obscure error message.
-        }
-
-        if (userRegistry.getTenantId() != 
MultitenantConstants.SUPER_TENANT_ID) {
-            log.error("Security Alert! Non super tenant trying to create a 
tenant.");
-            throw new Exception("Invalid data."); // obscure error message.
-        }
-    }
-
-    /**
-     * Super admin add tenant.This method will be used whenever the user store 
is shared between two deployment.
-     * This method will persist tenant not in user store level but will do 
other post tenant creation actions.
-     *
-     * @param tenantInfoBean
-     * @return
-     * @throws Exception
-     */
-    public String addSkeletonTenant(TenantInfoBean tenantInfoBean) throws 
Exception {
-        int tenantId;
-        checkIsSuperTenantInvoking();
-        try {
-            
tenantId=TenantMgtServiceComponent.getTenantManager().getTenantId(tenantInfoBean.getTenantDomain());
-        } catch (org.wso2.carbon.user.api.UserStoreException e) {
-            String msg = "Error in getting tenant id";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-        if(tenantId<0){
-            String msg = "Tenant is not added in user store 
"+tenantInfoBean.getTenantDomain();
-            log.error(msg);
-            throw new Exception(msg);
-        }
-        Tenant tenant = TenantMgtUtil.initializeTenant(tenantInfoBean);
-        tenant.setId(tenantId);
-        TenantPersistor persistor = new TenantPersistor();
-        // not validating the domain ownership, since created by super tenant
-        persistor.persistTenant(tenant, false, tenantInfoBean.getSuccessKey(),
-                tenantInfoBean.getOriginatedService(), true);
-        tenantInfoBean.setTenantId(tenantId);
-        notifyTenantAddition(tenantInfoBean);
-        return TenantMgtUtil.prepareStringToShowThemeMgtPage(tenantId);
-    }
-
-
-
-    /**
-     * Get the list of the tenants
-     *
-     * @return List<TenantInfoBean>
-     * @throws Exception UserStorException
-     */
-    private List<TenantInfoBean> getAllTenants() throws Exception {
-        TenantManager tenantManager = 
TenantMgtServiceComponent.getTenantManager();
-        Tenant[] tenants;
-        try {
-            tenants = (Tenant[]) tenantManager.getAllTenants();
-        } catch (UserStoreException e) {
-            String msg = "Error in retrieving the tenant information.";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        List<TenantInfoBean> tenantList = new ArrayList<TenantInfoBean>();
-        for (Tenant tenant : tenants) {
-            TenantInfoBean bean = 
TenantMgtUtil.getTenantInfoBeanfromTenant(tenant.getId(), tenant);
-            tenantList.add(bean);
-        }
-        return tenantList;
-    }
-    
-    /**
-     * Get the list of the tenants
-     *
-     * @return List<TenantInfoBean>
-     * @throws Exception UserStorException
-     */
-    private List<TenantInfoBean> searchPartialTenantsDomains(String domain) 
throws Exception {
-        TenantManager tenantManager = 
TenantMgtServiceComponent.getTenantManager();
-        Tenant[] tenants;
-        try {
-               domain = domain.trim();
-            tenants = (Tenant[]) 
tenantManager.getAllTenantsForTenantDomainStr(domain);
-        } catch (UserStoreException e) {
-            String msg = "Error in retrieving the tenant information.";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        List<TenantInfoBean> tenantList = new ArrayList<TenantInfoBean>();
-        for (Tenant tenant : tenants) {
-            TenantInfoBean bean = 
TenantMgtUtil.getTenantInfoBeanfromTenant(tenant.getId(), tenant);
-            tenantList.add(bean);
-        }
-        return tenantList;
-    }
-
-    /**
-     * Retrieve all the tenants
-     *
-     * @return tenantInfoBean[]
-     * @throws Exception if failed to get Tenant Manager
-     */
-    public TenantInfoBean[] retrieveTenants() throws Exception {
-        List<TenantInfoBean> tenantList = getAllTenants();
-        return tenantList.toArray(new TenantInfoBean[tenantList.size()]);
-    }
-    
-    /**
-     * Retrieve all the tenants which matches the partial search domain
-     *
-     * @return tenantInfoBean[]
-     * @throws Exception if failed to get Tenant Manager
-     */
-    public TenantInfoBean[] retrievePartialSearchTenants(String domain) throws 
Exception {
-        List<TenantInfoBean> tenantList = searchPartialTenantsDomains(domain);
-        return tenantList.toArray(new TenantInfoBean[tenantList.size()]);
-    }
-
-    /**
-     * Method to retrieve all the partial search domain tenants paginated
-     *
-     * @param pageNumber Number of the page.
-     * @return PaginatedTenantInfoBean
-     * @throws Exception if failed to getTenantManager;
-     */
-    public PaginatedTenantInfoBean 
retrievePaginatedPartialSearchTenants(String domain,int pageNumber) throws 
Exception {
-        List<TenantInfoBean> tenantList = searchPartialTenantsDomains(domain);
-
-        // Pagination
-        PaginatedTenantInfoBean paginatedTenantInfoBean = new 
PaginatedTenantInfoBean();
-        DataPaginator.doPaging(pageNumber, tenantList, 
paginatedTenantInfoBean);
-        return paginatedTenantInfoBean;
-    }
-    
-    /**
-     * Method to retrieve all the tenants paginated
-     *
-     * @param pageNumber Number of the page.
-     * @return PaginatedTenantInfoBean
-     * @throws Exception if failed to getTenantManager;
-     */
-    public PaginatedTenantInfoBean retrievePaginatedTenants(int pageNumber) 
throws Exception {
-        List<TenantInfoBean> tenantList = getAllTenants();
-
-        // Pagination
-        PaginatedTenantInfoBean paginatedTenantInfoBean = new 
PaginatedTenantInfoBean();
-        DataPaginator.doPaging(pageNumber, tenantList, 
paginatedTenantInfoBean);
-        return paginatedTenantInfoBean;
-    }
-
-    /**
-     * Get a specific tenant
-     *
-     * @param tenantDomain tenant domain
-     * @return tenantInfoBean
-     * @throws Exception UserStoreException
-     */
-    public TenantInfoBean getTenant(String tenantDomain) throws Exception {
-        TenantManager tenantManager = 
TenantMgtServiceComponent.getTenantManager();
-
-        int tenantId;
-        try {
-            tenantId = tenantManager.getTenantId(tenantDomain);
-        } catch (UserStoreException e) {
-            String msg = "Error in retrieving the tenant id for the tenant 
domain: " +
-                         tenantDomain + ".";
-            log.error(msg);
-            throw new Exception(msg, e);
-        }
-        Tenant tenant;
-        try {
-            tenant = (Tenant) tenantManager.getTenant(tenantId);
-        } catch (UserStoreException e) {
-            String msg = "Error in retrieving the tenant from the tenant 
manager.";
-            log.error(msg);
-            throw new Exception(msg, e);
-        }
-
-        TenantInfoBean bean = TenantMgtUtil.initializeTenantInfoBean(tenantId, 
tenant);
-
-        // retrieve first and last names from the UserStoreManager
-        bean.setFirstname(ClaimsMgtUtil.getFirstNamefromUserStoreManager(
-                TenantMgtServiceComponent.getRealmService(), tenantId));
-        bean.setLastname(ClaimsMgtUtil.getLastNamefromUserStoreManager(
-                TenantMgtServiceComponent.getRealmService(), tenantId));
-
-        //getting the subscription plan
-        String activePlan = "";
-        if(TenantMgtServiceComponent.getBillingService() != null){
-            activePlan = TenantMgtServiceComponent.getBillingService().
-                    getActiveUsagePlan(tenantDomain);
-        }
-
-        if(activePlan != null && activePlan.trim().length() > 0){
-            bean.setUsagePlan(activePlan);
-        }else{
-            bean.setUsagePlan("");
-        }
-
-        return bean;
-    }
-
-    /**
-     * Updates a given tenant
-     *
-     * @param tenantInfoBean tenant information
-     * @throws Exception UserStoreException
-     */
-    public void updateTenant(TenantInfoBean tenantInfoBean) throws Exception {
-        TenantManager tenantManager = 
TenantMgtServiceComponent.getTenantManager();
-        UserStoreManager userStoreManager;
-
-        // filling the non-set admin and admin password first
-        UserRegistry configSystemRegistry = 
TenantMgtServiceComponent.getConfigSystemRegistry(
-                tenantInfoBean.getTenantId());
-
-        String tenantDomain = tenantInfoBean.getTenantDomain();
-
-        int tenantId;
-        try {
-            tenantId = tenantManager.getTenantId(tenantDomain);
-        } catch (UserStoreException e) {
-            String msg = "Error in retrieving the tenant id for the tenant 
domain: " + tenantDomain
-                         + ".";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        Tenant tenant;
-        try {
-            tenant = (Tenant) tenantManager.getTenant(tenantId);
-        } catch (UserStoreException e) {
-            String msg = "Error in retrieving the tenant id for the tenant 
domain: " +
-                         tenantDomain + ".";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        // filling the first and last name values
-        if (tenantInfoBean.getFirstname() != null &&
-            !tenantInfoBean.getFirstname().trim().equals("")) {
-            try {
-                CommonUtil.validateName(tenantInfoBean.getFirstname(), "First 
Name");
-            } catch (Exception e) {
-                String msg = "Invalid first name is provided.";
-                log.error(msg, e);
-                throw new Exception(msg, e);
-            }
-        }
-        if (tenantInfoBean.getLastname() != null &&
-            !tenantInfoBean.getLastname().trim().equals("")) {
-            try {
-                CommonUtil.validateName(tenantInfoBean.getLastname(), "Last 
Name");
-            } catch (Exception e) {
-                String msg = "Invalid last name is provided.";
-                log.error(msg, e);
-                throw new Exception(msg, e);
-            }
-        }
-
-        tenant.setAdminFirstName(tenantInfoBean.getFirstname());
-        tenant.setAdminLastName(tenantInfoBean.getLastname());
-        TenantMgtUtil.addClaimsToUserStoreManager(tenant);
-
-        // filling the email value
-        if (tenantInfoBean.getEmail() != null && 
!tenantInfoBean.getEmail().equals("")) {
-            // validate the email
-            try {
-                CommonUtil.validateEmail(tenantInfoBean.getEmail());
-            } catch (Exception e) {
-                String msg = "Invalid email is provided.";
-                log.error(msg, e);
-                throw new Exception(msg, e);
-            }
-            tenant.setEmail(tenantInfoBean.getEmail());
-        }
-
-        UserRealm userRealm = configSystemRegistry.getUserRealm();
-        try {
-            userStoreManager = userRealm.getUserStoreManager();
-        } catch (UserStoreException e) {
-            String msg = "Error in getting the user store manager for tenant, 
tenant domain: " +
-                         tenantDomain + ".";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        boolean updatePassword = false;
-        if (tenantInfoBean.getAdminPassword() != null
-            && !tenantInfoBean.getAdminPassword().equals("")) {
-            updatePassword = true;
-        }
-        if (!userStoreManager.isReadOnly() && updatePassword) {
-            // now we will update the tenant admin with the admin given
-            // password.
-            try {
-                
userStoreManager.updateCredentialByAdmin(tenantInfoBean.getAdmin(),
-                                                         
tenantInfoBean.getAdminPassword());
-            } catch (UserStoreException e) {
-                String msg = "Error in changing the tenant admin password, 
tenant domain: " +
-                             tenantInfoBean.getTenantDomain() + ". " + 
e.getMessage() + " for: " +
-                             tenantInfoBean.getAdmin();
-                log.error(msg, e);
-                throw new Exception(msg, e);
-            }
-        } else {
-            //Password should be empty since no password update done
-            tenantInfoBean.setAdminPassword("");
-        }
-
-        try {
-            tenantManager.updateTenant(tenant);
-        } catch (UserStoreException e) {
-            String msg = "Error in updating the tenant for tenant domain: " + 
tenantDomain + ".";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-        
-        //Notify tenant update to all listeners
-        try {
-            TenantMgtUtil.triggerUpdateTenant(tenantInfoBean);
-        } catch (ApacheStratosException e) {
-            String msg = "Error in notifying tenant update.";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        //updating the usage plan
-        /*try{
-            if(TenantMgtServiceComponent.getBillingService() != null){
-                TenantMgtServiceComponent.getBillingService().
-                        updateUsagePlan(tenantInfoBean.getTenantDomain(), 
tenantInfoBean.getUsagePlan());
-            }
-        }catch(Exception e){
-            String msg = "Error when updating the usage plan: " + 
e.getMessage();
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }*/
-    }
-
-    /**
-     * Activate a deactivated tenant, by the super tenant.
-     *
-     * @param tenantDomain tenant domain
-     * @throws Exception UserStoreException.
-     */
-    public void activateTenant(String tenantDomain) throws Exception {
-        TenantManager tenantManager = 
TenantMgtServiceComponent.getTenantManager();
-        int tenantId;
-        try {
-            tenantId = tenantManager.getTenantId(tenantDomain);
-        } catch (UserStoreException e) {
-            String msg = "Error in retrieving the tenant id for the tenant 
domain: " + tenantDomain
-                         + ".";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        TenantMgtUtil.activateTenant(tenantDomain, tenantManager, tenantId);
-
-        //Notify tenant activation all listeners
-        try {
-            TenantMgtUtil.triggerTenantActivation(tenantId);
-        } catch (ApacheStratosException e) {
-            String msg = "Error in notifying tenant activate.";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-    }
-
-    /**
-     * Deactivate the given tenant
-     *
-     * @param tenantDomain tenant domain
-     * @throws Exception UserStoreException
-     */
-    public void deactivateTenant(String tenantDomain) throws Exception {
-        TenantManager tenantManager = 
TenantMgtServiceComponent.getTenantManager();
-        int tenantId;
-        try {
-            tenantId = tenantManager.getTenantId(tenantDomain);
-        } catch (UserStoreException e) {
-            String msg =
-                    "Error in retrieving the tenant id for the tenant domain: 
" +
-                    tenantDomain + ".";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        TenantMgtUtil.deactivateTenant(tenantDomain, tenantManager, tenantId);
-
-        //Notify tenant deactivation all listeners
-        try {
-            TenantMgtUtil.triggerTenantDeactivation(tenantId);
-        } catch (ApacheStratosException e) {
-            String msg = "Error in notifying tenant deactivate.";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-    }
-
-    /**
-     * Delete a specific tenant
-     *
-     * @param tenantDomain The domain name of the tennat that needs to be 
deleted
-     */
-    public void deleteTenant(String tenantDomain) throws Exception {
-        TenantManager tenantManager = 
TenantMgtCoreServiceComponent.getTenantManager();
-        int tenantId = tenantManager.getTenantId(tenantDomain);
-        try {
-            
TenantMgtServiceComponent.getBillingService().deleteBillingData(tenantId);
-            TenantMgtUtil.deleteTenantRegistryData(tenantId);
-            TenantMgtUtil.deleteTenantUMData(tenantId);
-            tenantManager.deleteTenant(tenantId);
-            log.info("Deleted tenant with domain: " + tenantDomain + " and 
tenant id: " + tenantId + 
-                     " from the system.");
-        } catch (Exception e) {
-            String msg = "Error deleting tenant with domain: " + tenantDomain 
+ " and tenant id: " +
-                    tenantId + ".";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        //Notify tenant delete to all listeners
-        try {
-            TenantMgtUtil.triggerDeleteTenant(tenantId);
-        } catch (ApacheStratosException e) {
-            String msg = "Error in notifying tenant delete";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java
 
b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java
deleted file mode 100644
index 46d1233..0000000
--- 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * 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.stratos.tenant.mgt.services;
-
-import org.wso2.carbon.captcha.mgt.beans.CaptchaInfoBean;
-import org.wso2.carbon.captcha.mgt.constants.CaptchaMgtConstants;
-import org.wso2.carbon.captcha.mgt.util.CaptchaUtil;
-import org.apache.stratos.common.beans.TenantInfoBean;
-import org.apache.stratos.common.exception.ApacheStratosException;
-import org.apache.stratos.common.util.CommonUtil;
-import org.apache.stratos.tenant.mgt.internal.TenantMgtServiceComponent;
-import org.apache.stratos.tenant.mgt.util.TenantMgtUtil;
-import org.wso2.carbon.user.core.tenant.Tenant;
-import org.wso2.carbon.user.core.tenant.TenantManager;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-import org.apache.stratos.tenant.mgt.core.TenantPersistor;
-
-import org.apache.axis2.AxisFault;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-
-/**
- * TenantSelfRegistration - This is the Web service that will be called when
- * tenants register themselves
- */
-public class TenantSelfRegistrationService {
-    private static final Log log = 
LogFactory.getLog(TenantSelfRegistrationService.class);
-
-    /**
-     * Registers a tenant - Tenant Self Registration
-     *
-     * @param tenantInfoBean  - tenantInformation
-     * @param captchaInfoBean - captchaInformation
-     * @return String UUID
-     * @throws Exception if the tenant registration fails.
-     */
-    public String registerTenant(TenantInfoBean tenantInfoBean, 
CaptchaInfoBean captchaInfoBean)
-            throws Exception {
-        // validate the email
-        try {
-            CommonUtil.validateEmail(tenantInfoBean.getEmail());
-        } catch (Exception e) {
-            String msg = "Invalid email is provided.";
-            log.error(msg, e);
-            throw new AxisFault(msg);
-        }
-        // validate the domain
-        String domainName = tenantInfoBean.getTenantDomain();
-        try {
-            TenantMgtUtil.validateDomain(domainName);
-        } catch (Exception e) {
-            String msg = "Domain Validation Failed.";
-            log.error(msg, e);
-            throw new AxisFault(msg);
-        }
-        // validate the first/last names
-        String firstname = tenantInfoBean.getFirstname();
-        String lastname = tenantInfoBean.getLastname();
-        try {
-            CommonUtil.validateName(firstname, "First Name");
-            CommonUtil.validateName(lastname, "Last Name");
-        } catch (Exception e) {
-            String msg = "First/Last Name Validation Failed.";
-            log.error(msg, e);
-            throw new AxisFault(msg);
-        } // now validate the captcha
-        try {
-            CaptchaUtil.validateCaptcha(captchaInfoBean);
-            if (log.isDebugEnabled()) {
-                log.debug("Captcha Successfully Validated.");
-            }
-        } catch (Exception e) {
-            String msg = CaptchaMgtConstants.CAPTCHA_ERROR_MSG;
-            log.error(msg, e);
-            throw new AxisFault(msg);
-        } finally {
-            try {
-                CaptchaUtil.cleanCaptcha(captchaInfoBean.getSecretKey());
-            } catch (Exception e) {
-                String msg = "Error in cleaning captcha. ";
-                log.error(msg, e);
-                // not throwing the exception in finally more up.
-            }
-        }
-        // persists the tenant.
-        Tenant tenant = TenantMgtUtil.initializeTenant(tenantInfoBean);
-        TenantPersistor persistor = new TenantPersistor();
-        int tenantId = persistor.persistTenant(tenant, true, 
tenantInfoBean.getSuccessKey(), 
-                tenantInfoBean.getOriginatedService(),false);
-        tenantInfoBean.setTenantId(tenantId);
-        TenantMgtUtil.addClaimsToUserStoreManager(tenant);
-        
-        //Notify tenant addition
-        try {
-            TenantMgtUtil.triggerAddTenant(tenantInfoBean);
-        } catch (ApacheStratosException e) {
-            String msg = "Error in notifying tenant addition.";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        //adding the subscription entry
-        try {
-            if (TenantMgtServiceComponent.getBillingService() != null) {
-                
TenantMgtServiceComponent.getBillingService().addUsagePlan(tenant,
-                        tenantInfoBean.getUsagePlan());
-                if (log.isDebugEnabled()) {
-                    log.debug("Subscription added successfully for the tenant: 
" +
-                              tenantInfoBean.getTenantDomain());
-                }
-            }
-        } catch (Exception e) {
-            String msg = "Error occurred while adding the subscription for 
tenant: " + domainName;
-            log.error(msg, e);
-        }
-
-        // If Email Validation is made optional, tenant will be activated now.
-        if (CommonUtil.isTenantManagementEmailsDisabled() ||
-                !CommonUtil.isEmailValidationMandatory()) {
-            TenantMgtUtil.activateTenantInitially(tenantInfoBean, tenantId);
-        }
-        return TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
-    }
-
-    /**
-     * Check if the selected domain is available to register
-     *
-     * @param domainName domain name
-     * @return true, if the domain is available to register
-     * @throws Exception, if unable to get the tenant manager, or get the 
tenant id
-     *                    from manager.
-     */
-    public boolean checkDomainAvailability(String domainName) throws Exception 
{
-        TenantManager tenantManager = 
TenantMgtServiceComponent.getTenantManager();
-        int tenantId = tenantManager.getTenantId(domainName);
-        if (log.isDebugEnabled()) {
-            log.debug("Tenant Domain is available to register.");
-        }
-        return tenantId < 0; // no tenant exists with the same tenant domain
-    }
-
-    // use a boolean instead of string.
-
-    /**
-     * Validates or Suggests a domain.
-     *
-     * @param domain     tenant domain
-     * @param successKey success key
-     * @return domain name
-     * @throws Exception if exception in validating or suggesting the tenant 
domain.
-     */
-    public String validateOrSuggestDomain(String domain, String successKey) 
throws Exception {
-        if (successKey != null && !successKey.equals("")) {
-            if (CommonUtil.validateDomainFromSuccessKey(
-                    TenantMgtServiceComponent.getGovernanceSystemRegistry(
-                            MultitenantConstants.SUPER_TENANT_ID), domain, 
successKey)) {
-                return domain;
-            }
-        }
-        // otherwise domain is not correct
-
-        return "null";
-    }
-
-    /**
-     * Generates a random Captcha
-     *
-     * @return captchaInfoBean
-     * @throws Exception, if exception in cleaning old captchas or generating 
new
-     *                    captcha image.
-     */
-    public CaptchaInfoBean generateRandomCaptcha() throws Exception {
-        // we will clean the old captchas asynchronously
-        CaptchaUtil.cleanOldCaptchas();
-        return CaptchaUtil.generateCaptchaImage();
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java
 
b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java
deleted file mode 100644
index 46d236a..0000000
--- 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java
+++ /dev/null
@@ -1,457 +0,0 @@
-/*
- * 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.stratos.tenant.mgt.util;
-
-import org.apache.stratos.tenant.mgt.internal.TenantMgtServiceComponent;
-import org.apache.commons.dbcp.BasicDataSource;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.registry.core.RegistryConstants;
-import org.wso2.carbon.registry.core.Resource;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
-import org.wso2.carbon.registry.core.jdbc.dataaccess.JDBCDataAccessManager;
-import org.wso2.carbon.registry.core.session.UserRegistry;
-import org.wso2.carbon.registry.core.utils.UUIDGenerator;
-import org.apache.stratos.common.beans.TenantInfoBean;
-import org.apache.stratos.common.constants.StratosConstants;
-import org.apache.stratos.common.exception.ApacheStratosException;
-import org.apache.stratos.common.listeners.TenantMgtListener;
-import org.apache.stratos.common.util.ClaimsMgtUtil;
-import org.apache.stratos.common.util.CommonUtil;
-import org.wso2.carbon.user.api.RealmConfiguration;
-import org.wso2.carbon.user.api.TenantMgtConfiguration;
-import org.wso2.carbon.user.core.UserCoreConstants;
-import org.wso2.carbon.user.core.UserRealm;
-import org.wso2.carbon.user.core.UserStoreException;
-import org.wso2.carbon.user.core.UserStoreManager;
-import 
org.wso2.carbon.user.core.config.multitenancy.MultiTenantRealmConfigBuilder;
-import org.wso2.carbon.user.core.jdbc.JDBCRealmConstants;
-import org.wso2.carbon.user.core.tenant.Tenant;
-import org.wso2.carbon.user.core.tenant.TenantManager;
-import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Utility methods for tenant management.
- */
-public class TenantMgtUtil {
-
-    private static final Log log = LogFactory.getLog(TenantMgtUtil.class);
-    private static final String ILLEGAL_CHARACTERS_FOR_TENANT_DOMAIN = 
".*[^a-zA-Z0-9\\._\\-].*";
-
-    /**
-     * Prepares string to show theme management page.
-     *
-     * @param tenantId - tenant id
-     * @return UUID
-     * @throws RegistryException, if failed.
-     */
-    public static String prepareStringToShowThemeMgtPage(int tenantId) throws 
RegistryException {
-        // first we generate a UUID
-        UserRegistry systemRegistry =
-                
TenantMgtServiceComponent.getRegistryService().getGovernanceSystemRegistry();
-        String uuid = UUIDGenerator.generateUUID();
-        // store it in the registry.
-        Resource resource = systemRegistry.newResource();
-        String tenantIdStr = Integer.toString(tenantId);
-        resource.setProperty(MultitenantConstants.TENANT_ID, tenantIdStr);
-        String uuidPath = StratosConstants.TENANT_CREATION_THEME_PAGE_TOKEN
-                          + RegistryConstants.PATH_SEPARATOR + uuid;
-        systemRegistry.put(uuidPath, resource);
-
-        // restrict access
-        CommonUtil.denyAnonAuthorization(uuidPath, 
systemRegistry.getUserRealm());
-        return uuid;
-    }
-
-    /**
-     * Triggers adding the tenant for TenantMgtListener
-     *
-     * @param tenantInfo tenant
-     * @throws org.apache.stratos.common.exception.ApacheStratosException, 
trigger failed
-     */
-    public static void triggerAddTenant(TenantInfoBean tenantInfo) throws 
ApacheStratosException {
-        // initializeRegistry(tenantInfoBean.getTenantId());
-        for (TenantMgtListener tenantMgtListener :
-                TenantMgtServiceComponent.getTenantMgtListeners()) {
-            tenantMgtListener.onTenantCreate(tenantInfo);
-        }
-    }
-
-    /**
-     * Triggers an update for the tenant for TenantMgtListener
-     *
-     * @param tenantInfoBean tenantInfoBean
-     * @throws org.apache.stratos.common.exception.ApacheStratosException, if 
update failed
-     */
-    public static void triggerUpdateTenant(
-            TenantInfoBean tenantInfoBean) throws ApacheStratosException {
-        for (TenantMgtListener tenantMgtListener :
-                TenantMgtServiceComponent.getTenantMgtListeners()) {
-            tenantMgtListener.onTenantUpdate(tenantInfoBean);
-        }
-    }
-
-    public static void triggerDeleteTenant(int tenantId) throws 
ApacheStratosException {
-        for (TenantMgtListener tenantMgtListener :
-                TenantMgtServiceComponent.getTenantMgtListeners()) {
-            tenantMgtListener.onTenantDelete(tenantId);
-        }
-    }
-    
-    public static void triggerTenantInitialActivation(
-                                  TenantInfoBean tenantInfoBean) throws 
ApacheStratosException {
-        for (TenantMgtListener tenantMgtListener :
-                TenantMgtServiceComponent.getTenantMgtListeners()) {
-            
tenantMgtListener.onTenantInitialActivation(tenantInfoBean.getTenantId());
-        }
-    }
-    
-    public static void triggerTenantActivation(int tenantId) throws 
ApacheStratosException {
-        for (TenantMgtListener tenantMgtListener : 
-                TenantMgtServiceComponent.getTenantMgtListeners()) {
-            tenantMgtListener.onTenantActivation(tenantId);
-        }
-    }
-    
-    public static void triggerTenantDeactivation(int tenantId) throws 
ApacheStratosException {
-        for (TenantMgtListener tenantMgtListener : 
-                TenantMgtServiceComponent.getTenantMgtListeners()) {
-            tenantMgtListener.onTenantDeactivation(tenantId);
-        }
-    }
-
-    /**
-     * Validate the tenant domain
-     *
-     * @param domainName tenant domain
-     * @throws Exception , if invalid tenant domain name is given
-     */
-    public static void validateDomain(String domainName) throws Exception {
-        if (domainName == null || domainName.equals("")) {
-            String msg = "Provided domain name is empty.";
-            log.error(msg);
-            throw new Exception(msg);
-        }
-        // ensures the .ext for the public clouds.
-        if (CommonUtil.isPublicCloudSetup()) {
-            int lastIndexOfDot = domainName.lastIndexOf(".");
-            if (lastIndexOfDot <= 0) {
-                String msg = "You should have an extension to your domain.";
-                log.error(msg);
-                throw new Exception(msg);
-            }
-        }
-        int indexOfDot = domainName.indexOf(".");
-        if (indexOfDot == 0) {
-            // can't start a domain starting with ".";
-            String msg = "Invalid domain, starting with '.'";
-            log.error(msg);
-            throw new Exception(msg);
-        }
-        // check the tenant domain contains any illegal characters
-        if (domainName.matches(ILLEGAL_CHARACTERS_FOR_TENANT_DOMAIN)) {
-            String msg = "The tenant domain ' " + domainName +
-                         " ' contains one or more illegal characters. the 
valid characters are " +
-                         "letters, numbers, '.', '-' and '_'";
-            log.error(msg);
-            throw new Exception(msg);
-        }
-    }
-
-    /**
-     * gets the UserStoreManager for a tenant
-     *
-     * @param tenant   - a tenant
-     * @param tenantId - tenant Id. To avoid the sequences where 
tenant.getId() may
-     *                 produce the super tenant's tenant Id.
-     * @return UserStoreManager
-     * @throws Exception UserStoreException
-     */
-    public static UserStoreManager getUserStoreManager(Tenant tenant, int 
tenantId)
-            throws Exception {
-        // get the system registry for the tenant
-        RealmConfiguration realmConfig = 
TenantMgtServiceComponent.getBootstrapRealmConfiguration();
-        TenantMgtConfiguration tenantMgtConfiguration =
-                
TenantMgtServiceComponent.getRealmService().getTenantMgtConfiguration();
-        UserRealm userRealm;
-        try {
-            MultiTenantRealmConfigBuilder builder = 
TenantMgtServiceComponent.getRealmService().
-                    getMultiTenantRealmConfigBuilder();
-            RealmConfiguration realmConfigToPersist = builder.
-                    getRealmConfigForTenantToPersist(realmConfig, 
tenantMgtConfiguration,
-                                                             tenant, tenantId);
-            RealmConfiguration realmConfigToCreate =
-                    
builder.getRealmConfigForTenantToCreateRealmOnTenantCreation(
-                            realmConfig, realmConfigToPersist, tenantId);
-            userRealm = TenantMgtServiceComponent.getRealmService().
-                    getUserRealm(realmConfigToCreate);
-        } catch (UserStoreException e) {
-            String msg = "Error in creating Realm for tenant, tenant domain: " 
+ tenant.getDomain();
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        UserStoreManager userStoreManager;
-        try {
-            userStoreManager = userRealm.getUserStoreManager();
-
-            return userStoreManager;
-        } catch (UserStoreException e) {
-            String msg = "Error in getting the userstore/authorization manager 
for tenant: " +
-                         tenant.getDomain();
-            log.error(msg);
-            throw new Exception(msg, e);
-        }
-    }
-
-    /**
-     * initializes tenant from the user input (tenant info bean)
-     *
-     * @param tenantInfoBean input
-     * @return tenant
-     */
-    public static Tenant initializeTenant(TenantInfoBean tenantInfoBean) {
-        Tenant tenant = new Tenant();
-        tenant.setDomain(tenantInfoBean.getTenantDomain());
-        tenant.setEmail(tenantInfoBean.getEmail());
-        tenant.setAdminName(tenantInfoBean.getAdmin());
-
-        // set tenantId given in tenantInfoBean, if it is set,
-        // underline tenant manager will try to create the tenant with given 
tenant Id.
-        tenant.setId(tenantInfoBean.getTenantId());
-
-        // we are duplicating the params stored in the claims here as well; 
they
-        // are in Tenant class
-        // to make it work with LDAP; but they do not make it to the databases.
-        tenant.setAdminFirstName(tenantInfoBean.getFirstname());
-        tenant.setAdminLastName(tenantInfoBean.getLastname());
-
-        tenant.setAdminPassword(tenantInfoBean.getAdminPassword());
-
-        // sets created date.
-        Calendar createdDateCal = tenantInfoBean.getCreatedDate();
-        long createdDate;
-        if (createdDateCal != null) {
-            createdDate = createdDateCal.getTimeInMillis();
-        } else {
-            createdDate = System.currentTimeMillis();
-        }
-        tenant.setCreatedDate(new Date(createdDate));
-
-        if (log.isDebugEnabled()) {
-            log.debug("Tenant object Initialized from the TenantInfoBean");
-        }
-        return tenant;
-    }
-
-    /**
-     * Initializes a tenantInfoBean object for a given tenant.
-     *
-     * @param tenantId tenant id.
-     * @param tenant   a tenant.
-     * @return tenantInfoBean
-     * @throws Exception , exception in getting the adminUserName from tenantId
-     */
-    public static TenantInfoBean initializeTenantInfoBean(
-            int tenantId, Tenant tenant) throws Exception {
-        TenantInfoBean bean = getTenantInfoBeanfromTenant(tenantId, tenant);
-        if (tenant != null) {
-            bean.setAdmin(ClaimsMgtUtil.getAdminUserNameFromTenantId(
-                    TenantMgtServiceComponent.getRealmService(), tenantId));
-        }
-        return bean;
-    }
-
-    /**
-     * initializes a TenantInfoBean object from the tenant
-     * @param tenantId, tenant id
-     * @param tenant, tenant
-     * @return TenantInfoBean.
-     */
-    public static TenantInfoBean getTenantInfoBeanfromTenant(int tenantId, 
Tenant tenant) {
-        TenantInfoBean bean = new TenantInfoBean();
-        if (tenant != null) {
-            bean.setTenantId(tenantId);
-            bean.setTenantDomain(tenant.getDomain());
-            bean.setEmail(tenant.getEmail());
-
-            /*gets the created date*/
-            Calendar createdDate = Calendar.getInstance();
-            createdDate.setTimeInMillis(tenant.getCreatedDate().getTime());
-            bean.setCreatedDate(createdDate);
-
-            bean.setActive(tenant.isActive());
-            if(log.isDebugEnabled()) {
-                log.debug("The TenantInfoBean object has been created from the 
tenant.");
-            }
-        } else {
-            if(log.isDebugEnabled()) {
-                log.debug("The tenant is null.");
-            }
-        }
-        return bean;
-    }
-
-    /**
-     * Adds claims to UserStoreManager
-     *
-     * @param tenant a tenant
-     * @throws Exception if error in adding claims to the user.
-     */
-    public static void addClaimsToUserStoreManager(Tenant tenant) throws 
Exception {
-        try {
-            Map<String, String> claimsMap = new HashMap<String, String>();
-
-            claimsMap.put(UserCoreConstants.ClaimTypeURIs.GIVEN_NAME, 
tenant.getAdminFirstName());
-            claimsMap.put(UserCoreConstants.ClaimTypeURIs.SURNAME, 
tenant.getAdminLastName());
-
-            // can be extended to store other user information.
-            UserStoreManager userStoreManager =
-                    (UserStoreManager) 
TenantMgtServiceComponent.getRealmService().
-                            
getTenantUserRealm(tenant.getId()).getUserStoreManager();
-            userStoreManager.setUserClaimValues(tenant.getAdminName(), 
claimsMap,
-                                                
UserCoreConstants.DEFAULT_PROFILE);
-
-        } catch (Exception e) {
-            String msg = "Error in adding claims to the user.";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-    }
-
-    /**
-     * Activate a tenant during the time of the tenant creation.
-     *
-     * @param tenantInfoBean tenant information
-     * @param tenantId tenant Id
-     * @throws Exception UserStoreException.
-     */
-    public static void activateTenantInitially(TenantInfoBean tenantInfoBean,
-                                               int tenantId) throws Exception {
-        TenantManager tenantManager = 
TenantMgtServiceComponent.getTenantManager();
-        String tenantDomain = tenantInfoBean.getTenantDomain();
-
-        TenantMgtUtil.activateTenant(tenantDomain, tenantManager, tenantId);
-        if (log.isDebugEnabled()) {
-            log.debug("Activated the tenant " + tenantDomain + " at the time 
of tenant creation");
-        }
-
-        //Notify tenant activation
-        try {
-            TenantMgtUtil.triggerTenantInitialActivation(tenantInfoBean);
-        } catch (ApacheStratosException e) {
-            String msg = "Error in notifying tenant initial activation.";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-    }
-
-    /**
-     * Activate the given tenant, either at the time of tenant creation, or 
later by super admin.
-     *
-     * @param tenantDomain tenant domain
-     * @param tenantManager TenantManager object
-     * @param tenantId tenant Id
-     * @throws Exception UserStoreException.
-     */
-    public static void activateTenant(String tenantDomain, TenantManager 
tenantManager,
-                                      int tenantId) throws Exception {
-        try {
-            tenantManager.activateTenant(tenantId);
-        } catch (UserStoreException e) {
-            String msg = "Error in activating the tenant for tenant domain: " 
+ tenantDomain + ".";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        //activating the subscription
-        /*try {
-            if (TenantMgtServiceComponent.getBillingService() != null) {
-                
TenantMgtServiceComponent.getBillingService().activateUsagePlan(tenantDomain);
-            }
-        } catch (Exception e) {
-            String msg = "Error while activating subscription for domain: " + 
tenantDomain + ".";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }*/
-    }
-
-    /**
-     * Deactivate the given tenant, by super admin.
-     *
-     * @param tenantDomain tenant domain
-     * @param tenantManager TenantManager object
-     * @param tenantId tenant Id
-     * @throws Exception UserStoreException.
-     */
-    public static void deactivateTenant(String tenantDomain, TenantManager 
tenantManager,
-                                        int tenantId) throws Exception {
-        try {
-            tenantManager.deactivateTenant(tenantId);
-        } catch (UserStoreException e) {
-            String msg = "Error in deactivating tenant for tenant domain: " + 
tenantDomain + ".";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }
-
-        //deactivating the subscription
-        /*try {
-            if (TenantMgtServiceComponent.getBillingService() != null) {
-                
TenantMgtServiceComponent.getBillingService().deactivateActiveUsagePlan(tenantDomain);
-            }
-        } catch (Exception e) {
-            String msg = "Error while deactivating subscription for domain: " 
+ tenantDomain + ".";
-            log.error(msg, e);
-            throw new Exception(msg, e);
-        }*/
-    }
-
-    public static void deleteTenantRegistryData(int tenantId) throws Exception 
{
-        // delete data from mounted config registry database
-        JDBCDataAccessManager configMgr = (JDBCDataAccessManager) 
TenantMgtServiceComponent.getRegistryService().
-                
getConfigUserRegistry().getRegistryContext().getDataAccessManager();
-        TenantRegistryDataDeletionUtil.deleteTenantRegistryData(tenantId, 
configMgr.getDataSource().getConnection());
-
-        // delete data from mounted governance registry database
-        JDBCDataAccessManager govMgr = (JDBCDataAccessManager) 
TenantMgtServiceComponent.getRegistryService().
-                
getGovernanceUserRegistry().getRegistryContext().getDataAccessManager();
-        TenantRegistryDataDeletionUtil.deleteTenantRegistryData(tenantId, 
govMgr.getDataSource().getConnection());
-
-    }
-
-    public static void deleteTenantUMData(int tenantId) throws Exception {
-        RealmConfiguration realmConfig = 
TenantMgtServiceComponent.getRealmService().
-                getBootstrapRealmConfiguration();
-        BasicDataSource dataSource = new BasicDataSource();
-        
dataSource.setDriverClassName(realmConfig.getRealmProperty(JDBCRealmConstants.DRIVER_NAME));
-        
dataSource.setUrl(realmConfig.getRealmProperty(JDBCRealmConstants.URL));
-        
dataSource.setUsername(realmConfig.getRealmProperty(JDBCRealmConstants.USER_NAME));
-        
dataSource.setPassword(realmConfig.getRealmProperty(JDBCRealmConstants.PASSWORD));
-        
dataSource.setMaxActive(Integer.parseInt(realmConfig.getRealmProperty(JDBCRealmConstants.MAX_ACTIVE)));
-        
dataSource.setMinIdle(Integer.parseInt(realmConfig.getRealmProperty(JDBCRealmConstants.MIN_IDLE)));
-        
dataSource.setMaxWait(Integer.parseInt(realmConfig.getRealmProperty(JDBCRealmConstants.MAX_WAIT)));
-
-        TenantUMDataDeletionUtil.deleteTenantUMData(tenantId, 
dataSource.getConnection());
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantRegistryDataDeletionUtil.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantRegistryDataDeletionUtil.java
 
b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantRegistryDataDeletionUtil.java
deleted file mode 100644
index ec9fec8..0000000
--- 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantRegistryDataDeletionUtil.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.stratos.tenant.mgt.util;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-public class TenantRegistryDataDeletionUtil {
-    public static final Log log = 
LogFactory.getLog(TenantRegistryDataDeletionUtil.class);
-    
-    /**
-     * Delete all tenant information related to tenant stored in REG tables
-     * @param tenantId id of tenant whose data should be deleted
-     * @param conn database connection object
-     * @throws SQLException thrown if an error occurs while executing the 
queries 
-     */
-    public static void deleteTenantRegistryData(int tenantId, Connection conn) 
throws Exception {
-        try {
-            conn.setAutoCommit(false);
-            String deleteClusterLockSql = "DELETE FROM REG_CLUSTER_LOCK WHERE 
REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteClusterLockSql, tenantId);
-
-            String deleteLogSql = "DELETE FROM REG_LOG WHERE REG_TENANT_ID = 
?";
-            executeDeleteQuery(conn, deleteLogSql, tenantId);
-
-            String deleteAssociationSql = "DELETE FROM REG_ASSOCIATION WHERE 
REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteAssociationSql, tenantId);
-
-            String deleteSnapshotSql = "DELETE FROM REG_SNAPSHOT WHERE 
REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteSnapshotSql, tenantId);
-
-            String deleteResourceCommentSql = "DELETE FROM 
REG_RESOURCE_COMMENT WHERE REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteResourceCommentSql, tenantId);
-
-            String deleteCommentSql = "DELETE FROM REG_COMMENT WHERE 
REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteCommentSql, tenantId);
-
-            String deleteResourceRatingSql = "DELETE FROM REG_RESOURCE_RATING 
WHERE REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteResourceRatingSql, tenantId);
-
-            String deleteRatingSql = "DELETE FROM REG_RATING WHERE 
REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteRatingSql, tenantId);
-
-            String deleteResourceTagSql = "DELETE FROM REG_RESOURCE_TAG WHERE 
REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteResourceTagSql, tenantId);
-
-            String deleteTagSql = "DELETE FROM REG_TAG WHERE REG_TENANT_ID = 
?";
-            executeDeleteQuery(conn, deleteTagSql, tenantId);
-
-            String deleteResourcePropertySql = "DELETE FROM 
REG_RESOURCE_PROPERTY WHERE REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteResourcePropertySql, tenantId);
-
-            String deletePropertySql = "DELETE FROM REG_PROPERTY WHERE 
REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deletePropertySql, tenantId);
-
-            String deleteResourceHistorySql = "DELETE FROM 
REG_RESOURCE_HISTORY WHERE REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteResourceHistorySql, tenantId);
-
-            String deleteContentHistorySql = "DELETE FROM REG_CONTENT_HISTORY 
WHERE REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteContentHistorySql, tenantId);
-
-            String deleteResourceSql = "DELETE FROM REG_RESOURCE WHERE 
REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteResourceSql, tenantId);
-
-            String deleteContentSql = "DELETE FROM REG_CONTENT WHERE 
REG_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteContentSql, tenantId);
-
-            String deletePathSql = "DELETE FROM REG_PATH WHERE REG_TENANT_ID = 
?";
-            executeDeleteQuery(conn, deletePathSql, tenantId);
-
-            conn.commit();
-        } catch (SQLException e) {
-            conn.rollback();
-            String errorMsg = "An error occurred while deleting registry data 
for tenant: " + tenantId;
-            log.error(errorMsg, e);
-            throw new Exception(errorMsg, e);
-        } finally {
-            conn.close();
-        }
-    }
-
-    private static void executeDeleteQuery(Connection conn, String query, int 
tenantId)
-            throws Exception {
-        PreparedStatement ps = null;
-        try {
-            ps = conn.prepareStatement(query);
-            ps.setInt(1, tenantId);
-            ps.executeUpdate();
-        } catch (SQLException e) {
-            String errMsg = "Error executing query " + query + " for tenant: " 
+ tenantId;
-            log.error(errMsg, e);
-            throw new Exception(errMsg, e);
-        } finally {
-            if (ps != null) {
-                ps.close();
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantUMDataDeletionUtil.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantUMDataDeletionUtil.java
 
b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantUMDataDeletionUtil.java
deleted file mode 100644
index 8b495b4..0000000
--- 
a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/util/TenantUMDataDeletionUtil.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.stratos.tenant.mgt.util;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-public class TenantUMDataDeletionUtil {
-    public static final Log log = 
LogFactory.getLog(TenantUMDataDeletionUtil.class);
-
-    /**
-     * Delete all tenant information related to tenant stored in UM tables
-     * @param tenantId id of tenant whose data should be deleted
-     * @param conn database connection object
-     * @throws SQLException thrown if an error occurs while executing the 
queries
-     */
-    public static void deleteTenantUMData(int tenantId, Connection conn) 
throws Exception {
-        try {
-            conn.setAutoCommit(false);
-            String deleteUserPermissionSql = "DELETE FROM UM_USER_PERMISSION 
WHERE UM_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteUserPermissionSql, tenantId);
-
-            String deleteRolePermissionSql = "DELETE FROM UM_ROLE_PERMISSION 
WHERE UM_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteRolePermissionSql, tenantId);
-
-            String deletePermissionSql = "DELETE FROM UM_PERMISSION WHERE 
UM_TENANT_ID = ?";
-            executeDeleteQuery(conn, deletePermissionSql, tenantId);
-
-            String deleteClaimBehaviourSql = "DELETE FROM UM_CLAIM_BEHAVIOR 
WHERE UM_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteClaimBehaviourSql, tenantId);
-
-            String deleteProfileConfigSql = "DELETE FROM UM_PROFILE_CONFIG 
WHERE UM_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteProfileConfigSql, tenantId);
-
-            String deleteClaimSql = "DELETE FROM UM_CLAIM WHERE UM_TENANT_ID = 
?";
-            executeDeleteQuery(conn, deleteClaimSql, tenantId);
-
-            String deleteDialectSql = "DELETE FROM UM_DIALECT WHERE 
UM_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteDialectSql, tenantId);
-
-            String deleteUserAttributeSql = "DELETE FROM UM_USER_ATTRIBUTE 
WHERE UM_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteUserAttributeSql, tenantId);
-
-            String deleteHybridUserRoleSql = "DELETE FROM UM_HYBRID_USER_ROLE 
WHERE UM_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteHybridUserRoleSql, tenantId);
-
-            String deleteHybridRoleSql = "DELETE FROM UM_HYBRID_ROLE WHERE 
UM_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteHybridRoleSql, tenantId);
-
-            String deleteHybridRememberMeSql = "DELETE FROM 
UM_HYBRID_REMEMBER_ME WHERE UM_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteHybridRememberMeSql, tenantId);
-
-            String deleteUserRoleSql = "DELETE FROM UM_USER_ROLE WHERE 
UM_TENANT_ID = ?";
-            executeDeleteQuery(conn, deleteUserRoleSql, tenantId);
-
-            String deleteRoleSql = "DELETE FROM UM_ROLE WHERE UM_TENANT_ID = 
?";
-            executeDeleteQuery(conn, deleteRoleSql, tenantId);
-
-            String deleteUserSql = "DELETE FROM UM_USER WHERE UM_TENANT_ID = 
?";
-            executeDeleteQuery(conn, deleteUserSql, tenantId);
-
-            String deleteTenantSql = "DELETE FROM UM_TENANT WHERE UM_ID = ?";
-            executeDeleteQuery(conn, deleteTenantSql, tenantId);
-
-            conn.commit();
-        } catch (Exception e) {
-            conn.rollback();
-            String errorMsg = "An error occurred while deleting registry data 
for tenant: " + tenantId;
-            log.error(errorMsg, e);
-            throw new Exception(errorMsg, e);
-        } finally {
-            conn.close();
-        }
-    }
-
-    private static void executeDeleteQuery(Connection conn, String query, int 
tenantId)
-            throws Exception {
-        PreparedStatement ps = null;
-        try {
-            ps = conn.prepareStatement(query);
-            ps.setInt(1, tenantId);
-            ps.executeUpdate();
-        } catch (SQLException e) {
-            String errMsg = "Error executing query " + query + " for tenant: " 
+ tenantId;
-            log.error(errMsg, e);
-            throw new Exception(errMsg, e);
-        } finally {
-            if (ps != null) {
-                ps.close();
-            }
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.tenant.mgt/src/main/resources/META-INF/component.xml
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.tenant.mgt/src/main/resources/META-INF/component.xml
 
b/components/org.apache.stratos.tenant.mgt/src/main/resources/META-INF/component.xml
deleted file mode 100644
index 8f2c708..0000000
--- 
a/components/org.apache.stratos.tenant.mgt/src/main/resources/META-INF/component.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 
-  #  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.
-  -->
-<component xmlns="http://products.wso2.org/carbon";>
-    <ManagementPermissions>
-        <ManagementPermission>
-            <DisplayName>Manage</DisplayName>
-            <ResourceId>/permission/protected/manage</ResourceId>
-        </ManagementPermission>
-        <ManagementPermission>
-            <DisplayName>Monitor</DisplayName>
-            <ResourceId>/permission/protected/manage/monitor</ResourceId>
-        </ManagementPermission>
-        <ManagementPermission>
-            <DisplayName>Tenants</DisplayName>
-            
<ResourceId>/permission/protected/manage/monitor/tenants</ResourceId>
-        </ManagementPermission>
-        <ManagementPermission>
-            <DisplayName>Modify</DisplayName>
-            <ResourceId>/permission/protected/manage/modify</ResourceId>
-        </ManagementPermission>
-        <ManagementPermission>
-            <DisplayName>Tenants</DisplayName>
-            
<ResourceId>/permission/protected/manage/modify/tenants</ResourceId>
-        </ManagementPermission>
-   </ManagementPermissions>
-</component>

Reply via email to