You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2013/07/10 18:51:39 UTC
[04/45] fixing component version issues and adding currently
refactored components to the parent pom
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/internal/TenantMgtServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/internal/TenantMgtServiceComponent.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/internal/TenantMgtServiceComponent.java
deleted file mode 100644
index ae8411b..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/internal/TenantMgtServiceComponent.java
+++ /dev/null
@@ -1,261 +0,0 @@
-/*
-* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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.internal;
-
-import org.wso2.carbon.core.multitenancy.persistence.TenantPersistor;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
-import org.wso2.carbon.registry.core.service.RegistryService;
-import org.wso2.carbon.registry.core.session.UserRegistry;
-import org.wso2.carbon.stratos.common.TenantBillingService;
-import org.wso2.carbon.stratos.common.listeners.TenantMgtListener;
-import org.wso2.carbon.stratos.common.util.CommonUtil;
-import org.wso2.carbon.stratos.common.util.StratosConfiguration;
-import org.apache.stratos.tenant.mgt.internal.util.TenantMgtRampartUtil;
-import org.wso2.carbon.user.api.RealmConfiguration;
-import org.wso2.carbon.user.core.service.RealmService;
-import org.wso2.carbon.user.core.tenant.TenantManager;
-import org.wso2.carbon.utils.ConfigurationContextService;
-
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.engine.AxisConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.neethi.Policy;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-import org.osgi.service.component.ComponentContext;
-
-/**
- * @scr.component name="org.wso2.carbon.tenant.mgt" immediate="true"
- * @scr.reference name="registry.service"
- * interface="org.wso2.carbon.registry.core.service.RegistryService"
- * cardinality="1..1" policy="dynamic" bind="setRegistryService"
- * unbind="unsetRegistryService"
- * @scr.reference name="user.realmservice.default"
- * interface="org.wso2.carbon.user.core.service.RealmService"
- * cardinality="1..1" policy="dynamic" bind="setRealmService"
- * unbind="unsetRealmService"
- * @scr.reference name="configuration.context.service"
- * interface="org.wso2.carbon.utils.ConfigurationContextService"
- * cardinality="1..1" policy="dynamic"
- * bind="setConfigurationContextService"
- * unbind="unsetConfigurationContextService"
- * @scr.reference name="org.wso2.carbon.tenant.mgt.listener.service"
- * interface="org.wso2.carbon.stratos.common.listeners.TenantMgtListener"
- * cardinality="0..n" policy="dynamic"
- * bind="setTenantMgtListenerService"
- * unbind="unsetTenantMgtListenerService"
- * @scr.reference name="default.tenant.billing.service"
- * interface="org.wso2.carbon.stratos.common.TenantBillingService"
- * cardinality="0..1" policy="dynamic"
- * bind="setTenantBillingService"
- * unbind="unsetTenantBillingService"
- * @scr.reference name="default.tenant.persistor"
- * interface="org.wso2.carbon.core.multitenancy.persistence.TenantPersistor"
- * cardinality="1..1" policy="dynamic"
- * bind="setTenantPersistor"
- * unbind="unsetTenantPersistor"
- */
-public class TenantMgtServiceComponent {
- private static Log log = LogFactory.getLog(TenantMgtServiceComponent.class);
-
- private static final String GAPP_TENANT_REG_SERVICE_NAME = "GAppTenantRegistrationService";
-
- private static RealmService realmService;
- private static RegistryService registryService;
-
- private static ConfigurationContextService configurationContextService;
-
- private static List<TenantMgtListener> tenantMgtListeners = new ArrayList<TenantMgtListener>();
- private static TenantPersistor tenantPersistor = null;
- private static TenantBillingService billingService = null;
-
- protected void activate(ComponentContext context) {
- try {
-
- // Loading the stratos configurations from Stratos.xml
- if (CommonUtil.getStratosConfig() == null) {
- StratosConfiguration stratosConfig = CommonUtil.loadStratosConfiguration();
- CommonUtil.setStratosConfig(stratosConfig);
- }
-
- // Loading the EULA
- if (CommonUtil.getEula() == null) {
- String eula = CommonUtil.loadTermsOfUsage();
- CommonUtil.setEula(eula);
- }
-
- populateRampartConfig(configurationContextService.
- getServerConfigContext().getAxisConfiguration());
-
- log.debug("******* Tenant Config bundle is activated ******* ");
- } catch (Exception e) {
- log.error("******* Tenant Config bundle failed activating ****", e);
- }
- }
-
- protected void setTenantMgtListenerService(TenantMgtListener tenantMgtListener) {
- addTenantMgtListener(tenantMgtListener);
- }
-
- protected void unsetTenantMgtListenerService(TenantMgtListener tenantMgtListener) {
- removeTenantMgtListener(tenantMgtListener);
- }
-
- protected void deactivate(ComponentContext context) {
- log.debug("******* Governance Tenant Config bundle is deactivated ******* ");
- }
-
- protected void setRegistryService(RegistryService registryService) {
- TenantMgtServiceComponent.registryService = registryService;
- }
-
- protected void unsetRegistryService(RegistryService registryService) {
- setRegistryService(null);
- }
-
- protected void setRealmService(RealmService realmService) {
- TenantMgtServiceComponent.realmService = realmService;
- }
-
- protected void unsetRealmService(RealmService realmService) {
- setRealmService(null);
- }
-
- protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
- log.debug("Receiving ConfigurationContext Service");
- TenantMgtServiceComponent.configurationContextService = configurationContextService;
-
- }
-
- protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) {
- log.debug("Unsetting ConfigurationContext Service");
- setConfigurationContextService(null);
- }
-
- public static void addTenantMgtListener(TenantMgtListener tenantMgtListener) {
- tenantMgtListeners.add(tenantMgtListener);
- sortTenantMgtListeners();
- }
-
- public static void removeTenantMgtListener(TenantMgtListener tenantMgtListener) {
- tenantMgtListeners.remove(tenantMgtListener);
- sortTenantMgtListeners();
- }
-
- public static void sortTenantMgtListeners() {
- Collections.sort(tenantMgtListeners, new Comparator<TenantMgtListener>() {
- public int compare(TenantMgtListener o1, TenantMgtListener o2) {
- return o1.getListenerOrder() - o2.getListenerOrder();
- }
- });
- }
-
- public static List<TenantMgtListener> getTenantMgtListeners() {
- return tenantMgtListeners;
- }
-
- public static ConfigurationContextService getConfigurationContextService() {
- return configurationContextService;
- }
-
- public static ConfigurationContext getConfigurationContext() {
- if (configurationContextService.getServerConfigContext() == null) {
- return null;
- }
- return configurationContextService.getServerConfigContext();
- }
-
- public static RegistryService getRegistryService() {
- return registryService;
- }
-
-
- public static RealmService getRealmService() {
- return realmService;
- }
-
- public static TenantManager getTenantManager() {
- return realmService.getTenantManager();
- }
-
- public static RealmConfiguration getBootstrapRealmConfiguration() {
- return realmService.getBootstrapRealmConfiguration();
- }
-
- public static UserRegistry getGovernanceSystemRegistry(int tenantId) throws RegistryException {
- return registryService.getGovernanceSystemRegistry(tenantId);
- }
-
- public static UserRegistry getConfigSystemRegistry(int tenantId) throws RegistryException {
- return registryService.getConfigSystemRegistry(tenantId);
- }
-
- public static TenantPersistor getTenantPersistor() {
- return tenantPersistor;
- }
-
- protected void setTenantPersistor(TenantPersistor defaultTenantPersistor) {
- tenantPersistor = defaultTenantPersistor;
- }
-
- public void unsetTenantPersistor(TenantPersistor defaultTenantPersistor) {
- tenantPersistor = null;
- }
-
-
- /** Updates RelyingPartyService with Crypto information
- *
- * @param config AxisConfiguration
- * @throws Exception
- */
- private void populateRampartConfig(AxisConfiguration config) throws Exception {
- AxisService service;
- // Get the RelyingParty Service to update security policy with keystore information
- service = config.getService(GAPP_TENANT_REG_SERVICE_NAME);
- if (service == null) {
- String msg = GAPP_TENANT_REG_SERVICE_NAME + " is not available in the Configuration Context";
- log.error(msg);
- throw new Exception(msg);
- }
- // Create a Rampart Config with default crypto information
- Policy rampartConfig = TenantMgtRampartUtil.getDefaultRampartConfig();
- // Add the RampartConfig to service policy
- service.getPolicySubject().attachPolicy(rampartConfig);
-
- }
-
- protected void setTenantBillingService(TenantBillingService tenantBillingService) {
- billingService = tenantBillingService;
- }
-
- protected void unsetTenantBillingService(TenantBillingService tenantBilling) {
- setTenantBillingService(null);
- }
-
- public static TenantBillingService getBillingService() {
- return billingService;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/internal/util/TenantMgtRampartUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/internal/util/TenantMgtRampartUtil.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/internal/util/TenantMgtRampartUtil.java
deleted file mode 100644
index 7cc40c7..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/internal/util/TenantMgtRampartUtil.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package org.apache.stratos.tenant.mgt.internal.util;
-
-import java.util.Properties;
-
-import org.apache.stratos.tenant.mgt.services.InMemoryPasswordcallbackHandler;
-import org.apache.neethi.Policy;
-import org.apache.rampart.policy.model.CryptoConfig;
-import org.apache.rampart.policy.model.RampartConfig;
-import org.wso2.carbon.base.ServerConfiguration;
-
-public class TenantMgtRampartUtil {
-
- public static Policy getDefaultRampartConfig() {
- //Extract the primary keystore information from server configuration
- ServerConfiguration serverConfig = ServerConfiguration.getInstance();
- String keyStore = serverConfig.getFirstProperty("Security.KeyStore.Location");
- String keyStoreType = serverConfig.getFirstProperty("Security.KeyStore.Type");
- String keyStorePassword = serverConfig.getFirstProperty("Security.KeyStore.Password");
- String privateKeyAlias = serverConfig.getFirstProperty("Security.KeyStore.KeyAlias");
- String privateKeyPassword = serverConfig.getFirstProperty("Security.KeyStore.KeyPassword");
-
- //Populate Rampart Configuration
- RampartConfig rampartConfig = new RampartConfig();
- rampartConfig.setUser(privateKeyAlias);
- rampartConfig.setPwCbClass("org.wso2.carbon.tenant.mgt.services.InMemoryPasswordcallbackHandler");
-
- //Set the private key alias and private key password in the password callback handler
- InMemoryPasswordcallbackHandler.addUser(privateKeyAlias, privateKeyPassword);
-
- CryptoConfig sigCrypto = new CryptoConfig();
- Properties props = new Properties();
- sigCrypto.setProvider("org.apache.ws.security.components.crypto.Merlin");
- props.setProperty("org.apache.ws.security.crypto.merlin.keystore.type", keyStoreType);
- props.setProperty("org.apache.ws.security.crypto.merlin.file", keyStore);
- props.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", keyStorePassword);
- sigCrypto.setProp(props);
-
- rampartConfig.setSigCryptoConfig(sigCrypto);
- Policy policy = new Policy();
- policy.addAssertion(rampartConfig);
-
- return policy;
-
- }
-
-
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java
deleted file mode 100644
index 171f9a3..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
-* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java
deleted file mode 100644
index a213ee9..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
-* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java
deleted file mode 100644
index 369ea4c..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package org.apache.stratos.tenant.mgt.services;
-
-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.wso2.carbon.core.multitenancy.persistence.TenantPersistor;
-import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
-import org.wso2.carbon.stratos.common.exception.StratosException;
-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.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 = TenantMgtServiceComponent.getTenantPersistor();
-
- 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 (StratosException 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/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java
deleted file mode 100644
index fec72a1..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.apache.stratos.tenant.mgt.services;
-
-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/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java
deleted file mode 100644
index 65d7e8c..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java
+++ /dev/null
@@ -1,496 +0,0 @@
-/*
- * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
- *
- * Licensed 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.core.multitenancy.persistence.TenantPersistor;
-import org.wso2.carbon.registry.core.session.UserRegistry;
-import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
-import org.wso2.carbon.stratos.common.exception.StratosException;
-import org.wso2.carbon.stratos.common.util.ClaimsMgtUtil;
-import org.wso2.carbon.stratos.common.util.CommonUtil;
-import org.apache.stratos.tenant.mgt.beans.PaginatedTenantInfoBean;
-import org.wso2.carbon.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.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 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);
- 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.
- }
- Tenant tenant = TenantMgtUtil.initializeTenant(tenantInfoBean);
- TenantPersistor persistor = TenantMgtServiceComponent.getTenantPersistor();
- // not validating the domain ownership, since created by super tenant
- int tenantId = persistor.persistTenant(tenant, false, tenantInfoBean.getSuccessKey(),
- tenantInfoBean.getOriginatedService());
- tenantInfoBean.setTenantId(tenantId);
-
- TenantMgtUtil.addClaimsToUserStoreManager(tenant);
-
- //Notify tenant addition
- try {
- TenantMgtUtil.triggerAddTenant(tenantInfoBean);
- } catch (StratosException 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: " + 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());
- }
-
- /**
- * 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 (StratosException 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 (StratosException 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 (StratosException 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);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java
deleted file mode 100644
index d6243df..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
- *
- * WSO2 Inc. 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.wso2.carbon.core.multitenancy.persistence.TenantPersistor;
-import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
-import org.wso2.carbon.stratos.common.exception.StratosException;
-import org.wso2.carbon.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.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 = TenantMgtServiceComponent.getTenantPersistor();
- int tenantId = persistor.persistTenant(tenant, true, tenantInfoBean.getSuccessKey(),
- tenantInfoBean.getOriginatedService());
- tenantInfoBean.setTenantId(tenantId);
- TenantMgtUtil.addClaimsToUserStoreManager(tenant);
-
- //Notify tenant addition
- try {
- TenantMgtUtil.triggerAddTenant(tenantInfoBean);
- } catch (StratosException 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/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java
deleted file mode 100644
index 48ccdfb..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantMgtUtil.java
+++ /dev/null
@@ -1,443 +0,0 @@
-/*
- * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
- *
- * Licensed 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.wso2.carbon.stratos.common.beans.TenantInfoBean;
-import org.wso2.carbon.stratos.common.constants.StratosConstants;
-import org.wso2.carbon.stratos.common.exception.StratosException;
-import org.wso2.carbon.stratos.common.listeners.TenantMgtListener;
-import org.wso2.carbon.stratos.common.util.ClaimsMgtUtil;
-import org.wso2.carbon.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 StratosException, trigger failed
- */
- public static void triggerAddTenant(TenantInfoBean tenantInfo) throws StratosException {
- // initializeRegistry(tenantInfoBean.getTenantId());
- for (TenantMgtListener tenantMgtListener :
- TenantMgtServiceComponent.getTenantMgtListeners()) {
- tenantMgtListener.onTenantCreate(tenantInfo);
- }
- }
-
- /**
- * Triggers an update for the tenant for TenantMgtListener
- *
- * @param tenantInfoBean tenantInfoBean
- * @throws org.wso2.carbon.stratos.common.exception.StratosException, if update failed
- */
- public static void triggerUpdateTenant(
- TenantInfoBean tenantInfoBean) throws StratosException {
- for (TenantMgtListener tenantMgtListener :
- TenantMgtServiceComponent.getTenantMgtListeners()) {
- tenantMgtListener.onTenantUpdate(tenantInfoBean);
- }
- }
-
- public static void triggerTenantInitialActivation(
- TenantInfoBean tenantInfoBean) throws StratosException {
- for (TenantMgtListener tenantMgtListener :
- TenantMgtServiceComponent.getTenantMgtListeners()) {
- tenantMgtListener.onTenantInitialActivation(tenantInfoBean.getTenantId());
- }
- }
-
- public static void triggerTenantActivation(int tenantId) throws StratosException {
- for (TenantMgtListener tenantMgtListener :
- TenantMgtServiceComponent.getTenantMgtListeners()) {
- tenantMgtListener.onTenantActivation(tenantId);
- }
- }
-
- public static void triggerTenantDeactivation(int tenantId) throws StratosException {
- 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());
-
- // 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 (StratosException 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());
- }
-}