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/08 19:33:35 UTC
[7/7] git commit: Tenat-mgt refactoring
Tenat-mgt refactoring
Signed-off-by: Isuru <is...@wso2.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/8c3796dc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/8c3796dc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/8c3796dc
Branch: refs/heads/master
Commit: 8c3796dcffa0b646280097bc3a60f32bced35fc4
Parents: c1fffa7
Author: manula <manula@manula-ThinkPad-T530.(none)>
Authored: Mon Jul 8 17:05:50 2013 +0530
Committer: Isuru <is...@wso2.com>
Committed: Mon Jul 8 23:02:59 2013 +0530
----------------------------------------------------------------------
.../2.1.0/pom.xml | 82 +++
.../tenant/mgt/core/DefaultTenantPersistor.java | 340 +++++++++++++
.../internal/TenantMgtCoreServiceComponent.java | 129 +++++
.../tenant/mgt/core/util/TenantCoreUtil.java | 76 +++
.../2.1.0/pom.xml | 103 ++++
.../mgt/email/sender/internal/DataHolder.java | 104 ++++
.../TenantMgtEmailSenderServiceComponent.java | 105 ++++
.../sender/listener/EmailSenderListener.java | 70 +++
.../sender/util/TenantMgtEmailSenderUtil.java | 482 ++++++++++++++++++
.../2.1.0/pom.xml | 122 +++++
.../ui/clients/PackageInfoServiceClient.java | 79 +++
.../mgt/ui/clients/TenantServiceClient.java | 120 +++++
.../tenant/mgt/ui/utils/TenantMgtUtil.java | 217 ++++++++
.../src/main/resources/META-INF/component.xml | 61 +++
.../tenant/mgt/ui/i18n/JSResources.properties | 4 +
.../tenant/mgt/ui/i18n/Resources.properties | 56 +++
.../activate_tenant_ajaxprocessor.jsp | 57 +++
.../resources/web/tenant-mgt/add_tenant.jsp | 386 +++++++++++++++
.../check_domain_availability_ajaxprocessor.jsp | 19 +
.../resources/web/tenant-mgt/css/tenant.css | 62 +++
.../web/tenant-mgt/docs/aboutUsagePlans.html | 104 ++++
.../web/tenant-mgt/docs/images/add-org.png | Bin 0 -> 49926 bytes
.../web/tenant-mgt/docs/images/add-tenant.png | Bin 0 -> 28704 bytes
.../web/tenant-mgt/docs/images/view-tenants.png | Bin 0 -> 11896 bytes
.../web/tenant-mgt/docs/userguide.html | 56 +++
.../get_package_info_ajaxprocessor.jsp | 39 ++
.../web/tenant-mgt/images/multi_tenancy.png | Bin 0 -> 768 bytes
.../web/tenant-mgt/images/services.gif | Bin 0 -> 604 bytes
.../web/tenant-mgt/images/services1.gif | Bin 0 -> 608 bytes
.../web/tenant-mgt/js/tenant_config.js | 218 ++++++++
.../web/tenant-mgt/js/theme_resource_util.js | 0
.../tenant-mgt/submit_tenant_ajaxprocessor.jsp | 84 ++++
.../resources/web/tenant-mgt/view_tenants.jsp | 236 +++++++++
.../org.apache.stratos.tenant.mgt/2.1.0/pom.xml | 125 +++++
.../mgt/beans/PaginatedTenantInfoBean.java | 52 ++
.../exception/TenantManagementException.java | 33 ++
.../mgt/internal/TenantMgtServiceComponent.java | 261 ++++++++++
.../mgt/internal/util/TenantMgtRampartUtil.java | 48 ++
.../mgt/realm/CloudWSRealmConfigBuilder.java | 138 ++++++
.../mgt/realm/IdaasWSRealmConfigBuilder.java | 87 ++++
.../services/GAppTenantRegistrationService.java | 120 +++++
.../InMemoryPasswordcallbackHandler.java | 38 ++
.../mgt/services/TenantMgtAdminService.java | 496 +++++++++++++++++++
.../services/TenantSelfRegistrationService.java | 193 ++++++++
.../stratos/tenant/mgt/util/TenantMgtUtil.java | 443 +++++++++++++++++
.../util/TenantRegistryDataDeletionUtil.java | 119 +++++
.../mgt/util/TenantUMDataDeletionUtil.java | 112 +++++
.../src/main/resources/META-INF/component.xml | 41 ++
.../src/main/resources/META-INF/services.xml | 155 ++++++
.../2.1.0/pom.xml | 123 +++++
.../ui/clients/PackageInfoServiceClient.java | 77 +++
.../clients/TenantSelfRegistrationClient.java | 107 ++++
.../register/ui/utils/TenantConfigUtil.java | 248 ++++++++++
.../src/main/resources/META-INF/component.xml | 70 +++
.../register/ui/i18n/JSResources.properties | 6 +
.../register/ui/i18n/Resources.properties | 62 +++
.../web/tenant-register/css/tenant-register.css | 78 +++
.../tenant-register/docs/aboutUsagePlans.html | 104 ++++
.../web/tenant-register/docs/images/add-org.png | Bin 0 -> 62035 bytes
.../web/tenant-register/docs/userguide.html | 104 ++++
.../domain_availability_ajaxprocessor.jsp | 50 ++
.../get_package_info_ajaxprocessor.jsp | 39 ++
.../web/tenant-register/images/ajax-loader.gif | Bin 0 -> 673 bytes
.../web/tenant-register/images/body-bg.gif | Bin 0 -> 419 bytes
.../web/tenant-register/images/button-back.gif | Bin 0 -> 819 bytes
.../images/content-back-left.jpg | Bin 0 -> 2240 bytes
.../web/tenant-register/images/content-back.jpg | Bin 0 -> 852 bytes
.../images/create-org-button.gif | Bin 0 -> 2576 bytes
.../tenant-register/images/feature-01-icon.gif | Bin 0 -> 2825 bytes
.../tenant-register/images/feature-02-icon.gif | Bin 0 -> 3361 bytes
.../tenant-register/images/feature-03-icon.gif | Bin 0 -> 3285 bytes
.../web/tenant-register/images/features-bg.gif | Bin 0 -> 4449 bytes
.../web/tenant-register/images/footer.jpg | Bin 0 -> 836 bytes
.../web/tenant-register/images/forum.gif | Bin 0 -> 1977 bytes
.../web/tenant-register/images/header.jpg | Bin 0 -> 5837 bytes
.../web/tenant-register/images/help.gif | Bin 0 -> 1229 bytes
.../web/tenant-register/images/images.gif | Bin 0 -> 1067 bytes
.../tenant-register/images/issue-tracker.gif | Bin 0 -> 1821 bytes
.../web/tenant-register/images/logo.jpg | Bin 0 -> 7171 bytes
.../web/tenant-register/images/mailing-list.gif | Bin 0 -> 2064 bytes
.../web/tenant-register/images/page-back.jpg | Bin 0 -> 871 bytes
.../web/tenant-register/images/people.gif | Bin 0 -> 22151 bytes
.../web/tenant-register/images/services.gif | Bin 0 -> 604 bytes
.../tenant-register/images/signup-new-org.gif | Bin 0 -> 356 bytes
.../web/tenant-register/images/thememgt.gif | Bin 0 -> 1030 bytes
.../web/tenant-register/images/user-guide.gif | Bin 0 -> 2161 bytes
.../init_payment_ajaxprocessor.jsp | 101 ++++
.../web/tenant-register/js/register_config.js | 147 ++++++
.../web/tenant-register/js/select_domain.js | 75 +++
.../web/tenant-register/select_domain.jsp | 389 +++++++++++++++
.../web/tenant-register/select_usage_plan.jsp | 279 +++++++++++
.../submit_tenant_ajaxprocessor.jsp | 66 +++
.../web/tenant-register/success_register.jsp | 77 +++
.../2.1.1/pom.xml | 132 +++++
.../ui/clients/PackageInfoServiceClient.java | 77 +++
.../clients/TenantSelfRegistrationClient.java | 107 ++++
.../register/ui/utils/TenantConfigUtil.java | 248 ++++++++++
.../src/main/resources/META-INF/component.xml | 70 +++
.../register/ui/i18n/JSResources.properties | 6 +
.../register/ui/i18n/Resources.properties | 62 +++
.../web/tenant-register/css/tenant-register.css | 78 +++
.../tenant-register/docs/aboutUsagePlans.html | 104 ++++
.../web/tenant-register/docs/images/add-org.png | Bin 0 -> 62035 bytes
.../web/tenant-register/docs/userguide.html | 104 ++++
.../domain_availability_ajaxprocessor.jsp | 50 ++
.../get_package_info_ajaxprocessor.jsp | 39 ++
.../web/tenant-register/images/ajax-loader.gif | Bin 0 -> 673 bytes
.../web/tenant-register/images/body-bg.gif | Bin 0 -> 419 bytes
.../web/tenant-register/images/button-back.gif | Bin 0 -> 819 bytes
.../images/content-back-left.jpg | Bin 0 -> 2240 bytes
.../web/tenant-register/images/content-back.jpg | Bin 0 -> 852 bytes
.../images/create-org-button.gif | Bin 0 -> 2576 bytes
.../tenant-register/images/feature-01-icon.gif | Bin 0 -> 2825 bytes
.../tenant-register/images/feature-02-icon.gif | Bin 0 -> 3361 bytes
.../tenant-register/images/feature-03-icon.gif | Bin 0 -> 3285 bytes
.../web/tenant-register/images/features-bg.gif | Bin 0 -> 4449 bytes
.../web/tenant-register/images/footer.jpg | Bin 0 -> 836 bytes
.../web/tenant-register/images/forum.gif | Bin 0 -> 1977 bytes
.../web/tenant-register/images/header.jpg | Bin 0 -> 5837 bytes
.../web/tenant-register/images/help.gif | Bin 0 -> 1229 bytes
.../web/tenant-register/images/images.gif | Bin 0 -> 1067 bytes
.../tenant-register/images/issue-tracker.gif | Bin 0 -> 1821 bytes
.../web/tenant-register/images/logo.jpg | Bin 0 -> 7171 bytes
.../web/tenant-register/images/mailing-list.gif | Bin 0 -> 2064 bytes
.../web/tenant-register/images/page-back.jpg | Bin 0 -> 871 bytes
.../web/tenant-register/images/people.gif | Bin 0 -> 22151 bytes
.../web/tenant-register/images/services.gif | Bin 0 -> 604 bytes
.../tenant-register/images/signup-new-org.gif | Bin 0 -> 356 bytes
.../web/tenant-register/images/thememgt.gif | Bin 0 -> 1030 bytes
.../web/tenant-register/images/user-guide.gif | Bin 0 -> 2161 bytes
.../init_payment_ajaxprocessor.jsp | 101 ++++
.../web/tenant-register/js/register_config.js | 147 ++++++
.../web/tenant-register/js/select_domain.js | 75 +++
.../web/tenant-register/select_domain.jsp | 389 +++++++++++++++
.../web/tenant-register/select_usage_plan.jsp | 279 +++++++++++
.../submit_tenant_ajaxprocessor.jsp | 66 +++
.../web/tenant-register/success_register.jsp | 77 +++
137 files changed, 10285 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.core/2.1.0/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.core/2.1.0/pom.xml b/components/org.apache.stratos.tenant.mgt.core/2.1.0/pom.xml
new file mode 100644
index 0000000..b91a887
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.core/2.1.0/pom.xml
@@ -0,0 +1,82 @@
+<!--
+# 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>stratos-components-parent</artifactId>
+ <version>2.0.0</version>
+<relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.stratos.tenant.mgt.core</artifactId>
+ <version>2.1.0</version>
+ <packaging>bundle</packaging>
+ <name>Apache Stratos - Tenant Managment Core</name>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Name>${project.artifactId}</Bundle-Name>
+ <Private-Package>
+ org.apache.stratos.tenant.mgt.core.internal.*;-split-package:=merge-last,
+ </Private-Package>
+ <Import-Package>
+ org.apache.stratos.common.*,
+ org.wso2.carbon.registry.core.*,
+ !javax.xml.namespace,
+ javax.xml.namespace; version=0.0.0,
+ javax.servlet;version="${imp.pkg.version.javax.servlet}",
+ javax.servlet.http;version="${imp.pkg.version.javax.servlet}",
+ org.apache.axiom.*; version="${axiom.osgi.version.range}",
+ *;resolution:=optional
+ </Import-Package>
+ <Export-Package>
+ org.apache.stratos.tenant.mgt.core.*,
+ </Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.core</artifactId>
+ <version>4.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.stratos.common</artifactId>
+ <version>2.1.0</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/DefaultTenantPersistor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/DefaultTenantPersistor.java b/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/DefaultTenantPersistor.java
new file mode 100644
index 0000000..583d9de
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/DefaultTenantPersistor.java
@@ -0,0 +1,340 @@
+/*
+ * Copyright (c) 2010, 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.core;
+
+import org.apache.stratos.tenant.mgt.core.internal.TenantMgtCoreServiceComponent;
+import org.wso2.carbon.CarbonConstants;
+import org.wso2.carbon.core.multitenancy.persistence.TenantPersistor;
+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.session.UserRegistry;
+import org.wso2.carbon.stratos.common.config.CloudServiceConfigParser;
+import org.wso2.carbon.stratos.common.config.CloudServicesDescConfig;
+import org.wso2.carbon.stratos.common.constants.StratosConstants;
+import org.wso2.carbon.stratos.common.util.CloudServicesUtil;
+import org.wso2.carbon.stratos.common.util.CommonUtil;
+import org.apache.stratos.tenant.mgt.core.util.TenantCoreUtil;
+import org.wso2.carbon.user.api.RealmConfiguration;
+import org.wso2.carbon.user.api.TenantMgtConfiguration;
+import org.wso2.carbon.user.core.AuthorizationManager;
+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.service.RealmService;
+import org.wso2.carbon.user.core.tenant.Tenant;
+import org.wso2.carbon.user.core.tenant.TenantManager;
+import org.wso2.carbon.user.mgt.UserMgtConstants;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * TenantPersistenceManager - Methods related to persisting the tenant.
+ */
+public class DefaultTenantPersistor implements TenantPersistor {
+
+ private static final Log log = LogFactory.getLog(DefaultTenantPersistor.class);
+ private static final String ILLEGAL_CHARACTERS_FOR_PATH = ".*[~!#$;%^*()+={}\\[\\]\\|\\\\<>].*";
+
+ private static CloudServicesDescConfig cloudServicesDesc = null;
+
+
+ /**
+ * Persists the given tenant
+ * @param tenant - tenant to be persisted
+ * @param checkDomainValidation - true, if domain is validated.
+ * @param successKey - successKey
+ * @param originatedService - The Service that the tenant registration was originated.
+ * @return tenant Id - the tenant id
+ * @throws Exception, if persisting tenant failed.
+ */
+ public int persistTenant(Tenant tenant, boolean checkDomainValidation, String successKey,
+ String originatedService) throws Exception {
+ int tenantId;
+ validateAdminUserName(tenant);
+ String tenantDomain = tenant.getDomain();
+
+ boolean isDomainAvailable = CommonUtil.isDomainNameAvailable(tenantDomain);
+ if (!isDomainAvailable) {
+ throw new Exception("Domain is not available to register");
+ }
+
+ RealmService realmService = TenantMgtCoreServiceComponent.getRealmService();
+ RealmConfiguration realmConfig = realmService.getBootstrapRealmConfiguration();
+ TenantMgtConfiguration tenantMgtConfiguration = realmService.getTenantMgtConfiguration();
+ MultiTenantRealmConfigBuilder builder = TenantMgtCoreServiceComponent.
+ getRealmService().getMultiTenantRealmConfigBuilder();
+ RealmConfiguration realmConfigToPersist =
+ builder.getRealmConfigForTenantToPersist(realmConfig, tenantMgtConfiguration,
+ tenant, -1);
+ tenant.setRealmConfig(realmConfigToPersist);
+ tenantId = addTenant(tenant);
+ tenant.setId(tenantId);
+
+ if (checkDomainValidation) {
+ if (successKey != null) {
+ if (CommonUtil.validateDomainFromSuccessKey(TenantMgtCoreServiceComponent.
+ getGovernanceSystemRegistry(MultitenantConstants.SUPER_TENANT_ID),
+ tenant.getDomain(), successKey)) {
+ storeDomainValidationFlagToRegistry(tenant);
+ } else {
+ String msg = "Failed to validate domain";
+ throw new Exception(msg);
+ }
+ }
+ } else {
+ storeDomainValidationFlagToRegistry(tenant);
+ }
+
+ try {
+ doPostTenantCreationActions(tenant, originatedService);
+ } catch (Exception e) {
+ String msg = "Error performing post tenant creation actions";
+ throw new Exception(msg, e);
+ }
+
+ return tenantId;
+ }
+
+ private void doPostTenantCreationActions(Tenant tenant,
+ String originatedService) throws Exception {
+ RealmService realmService = TenantMgtCoreServiceComponent.getRealmService();
+ UserRealm userRealm;
+ try {
+ userRealm = (UserRealm) realmService.getTenantUserRealm(tenant.getId());
+ } catch (UserStoreException e) {
+ String msg = "Error in creating Realm for tenant: " + tenant.getDomain();
+ throw new Exception(msg, e);
+ }
+
+ updateTenantAdminPassword(userRealm, tenant);
+ TenantMgtCoreServiceComponent.getRegistryLoader().loadTenantRegistry(tenant.getId());
+ copyUIPermissions(tenant.getId());
+
+ TenantCoreUtil.setOriginatedService(tenant.getId(), originatedService);
+ setActivationFlags(tenant.getId(), originatedService);
+
+ TenantCoreUtil.initializeRegistry(tenant.getId());
+
+ }
+
+ /**
+ * Store the domain validation flag in the registry if the domain has been
+ * validated.
+ *
+ * @param tenant - the tenant
+ * @throws RegistryException, if storing the domain validation flag failed.
+ */
+ private void storeDomainValidationFlagToRegistry(Tenant tenant) throws RegistryException {
+
+ try {
+ String domainValidationPath = StratosConstants.TENANT_DOMAIN_VERIFICATION_FLAG_PATH +
+ RegistryConstants.PATH_SEPARATOR + tenant.getId();
+ UserRegistry superTenantRegistry = TenantMgtCoreServiceComponent.
+ getGovernanceSystemRegistry(MultitenantConstants.SUPER_TENANT_ID);
+ Resource validationFlagR = superTenantRegistry.newResource();
+ validationFlagR.setProperty(tenant.getDomain(), "true");
+ superTenantRegistry.put(domainValidationPath, validationFlagR);
+
+ } catch (RegistryException e) {
+ String msg = "Error in storing the domain validation flag to the registry";
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Domain Validation Flag is stored to the registry.");
+ }
+ }
+
+ /**
+ * Adds a tenant to the tenant manager
+ *
+ * @param tenant - the tenant
+ * @return tenantId - the tenant id
+ * @throws Exception - UserStoreException
+ */
+ private int addTenant(Tenant tenant) throws Exception {
+ int tenantId;
+ TenantManager tenantManager = TenantMgtCoreServiceComponent.getTenantManager();
+ try {
+ tenantId = tenantManager.addTenant(tenant);
+ if (log.isDebugEnabled()) {
+ log.debug("Tenant is successfully added: " + tenant.getDomain());
+ }
+ } catch (UserStoreException e) {
+ String msg = "Error in adding tenant with domain: " + tenant.getDomain();
+ log.error(msg, e);
+ throw new Exception(msg, e);
+ }
+ return tenantId;
+ }
+
+ /**
+ * Sets the password for the tenant
+ *
+ * @param tenant - the tenant
+ * @param userRealm - user realm
+ * @throws Exception - UserStoreException
+ */
+ private void updateTenantAdminPassword(UserRealm userRealm, Tenant tenant) throws Exception {
+ try {
+ UserStoreManager userStoreManager = userRealm.getUserStoreManager();
+ if (!userStoreManager.isReadOnly()) {
+ userStoreManager.updateCredentialByAdmin(tenant.getAdminName(),
+ tenant.getAdminPassword());
+ if (log.isDebugEnabled()) {
+ log.debug("Successfully set the password for the tenant.");
+ }
+ }
+ } catch (UserStoreException e) {
+ String msg = "Error in changing the tenant admin password for tenant domain: " +
+ tenant.getDomain() + ".";
+ log.error(msg, e);
+ throw new Exception(msg, e);
+ }
+ }
+
+ /**
+ * Authorize the role
+ *
+ * @param tenantId - tenant id
+ * @throws Exception - UserStoreException
+ */
+ private void copyUIPermissions(int tenantId) throws Exception {
+ try {
+ UserRealm realm = (UserRealm) TenantMgtCoreServiceComponent.
+ getRealmService().getTenantUserRealm(tenantId);
+ String adminRole = realm.getRealmConfiguration().getAdminRoleName();
+ AuthorizationManager authMan = realm.getAuthorizationManager();
+ // Authorize the admin role, if not authorized yet.
+ if (!authMan.isRoleAuthorized(adminRole,
+ CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION,
+ UserMgtConstants.EXECUTE_ACTION)) {
+ authMan.authorizeRole(adminRole, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION,
+ UserMgtConstants.EXECUTE_ACTION);
+ }
+ } catch (UserStoreException e) {
+ String msg = "Error in authorizing the admin role.";
+ log.error(msg, e);
+ throw new Exception(msg, e);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Role has successfully been authorized.");
+ }
+ }
+
+ private void setActivationFlags(int tenantId, String originalService) throws Exception {
+
+ boolean useDefaultConfig = true;
+ try {
+
+ if(cloudServicesDesc == null ) {
+ cloudServicesDesc = CloudServiceConfigParser.loadCloudServicesConfiguration();
+ }
+
+ if (originalService != null &&
+ !originalService.equals(StratosConstants.CLOUD_MANAGER_SERVICE) ) {
+ CloudServicesUtil.activateOriginalAndCompulsoryServices(cloudServicesDesc,
+ originalService, tenantId);
+ useDefaultConfig = false;
+ }
+
+ if (useDefaultConfig) {
+ CloudServicesUtil.activateAllServices(cloudServicesDesc, tenantId);
+ }
+ } catch (Exception e) {
+ log.error("Error registering the originated service", e);
+ throw e;
+ }
+
+ }
+
+ /**
+ * Validates that the chosen AdminUserName is valid.
+ *
+ * @param tenant
+ * tenant information
+ * @throws Exception
+ * UserStoreException
+ */
+ private void validateAdminUserName(Tenant tenant) throws Exception {
+ UserRealm superTenantUserRealm =
+ TenantMgtCoreServiceComponent.getRealmService().
+ getBootstrapRealm();
+ RealmConfiguration realmConfig = TenantMgtCoreServiceComponent.
+ getBootstrapRealmConfiguration();
+ String uniqueAcrossTenants = realmConfig.getUserStoreProperty(
+ UserCoreConstants.RealmConfig.PROPERTY_USERNAME_UNIQUE);
+ if ("true".equals(uniqueAcrossTenants)) {
+ try {
+ if (superTenantUserRealm.getUserStoreManager().isExistingUser(
+ tenant.getAdminName())) {
+ throw new Exception("User name : " + tenant.getAdminName() +
+ " exists in the system. " +
+ "Please pick another user name for tenant Administrator.");
+ }
+ } catch (UserStoreException e) {
+ String msg = "Error in checking whether the user already exists in the system";
+ log.error(msg, e);
+ throw new Exception(msg, e);
+ }
+ }
+ if (tenant.getAdminName().matches(DefaultTenantPersistor.ILLEGAL_CHARACTERS_FOR_PATH)) {
+ String msg = "The tenant admin ' " + tenant.getAdminName() +
+ " ' contains one or more illegal characters" +
+ " (~!@#$;%^*()+={}[]|\\<>)";
+ log.error(msg);
+ throw new Exception(msg);
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("Admin User Name has been validated.");
+ }
+ }
+
+ /**
+ * Persists the given tenant
+ * @param tenant - tenant to be persisted
+ * @return tenant Id
+ * @throws Exception, if persisting tenant failed.
+ */
+ public int persistTenant(Tenant tenant) throws Exception {
+ String tenantDomain = tenant.getDomain();
+ int tenantId;
+ validateAdminUserName(tenant);
+ boolean isDomainAvailable = CommonUtil.isDomainNameAvailable(tenantDomain);
+ if (!isDomainAvailable) {
+ throw new Exception("Domain is not available to register");
+ }
+
+ tenantId = addTenant(tenant);
+ tenant.setId(tenantId);
+
+ try {
+ doPostTenantCreationActions(tenant, null);
+ } catch (Exception e) {
+ String msg = "Error performing post tenant creation actions";
+ if(log.isDebugEnabled()) {
+ log.debug(msg, e);
+ }
+ throw new Exception(msg);
+ }
+ return tenantId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/internal/TenantMgtCoreServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/internal/TenantMgtCoreServiceComponent.java b/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/internal/TenantMgtCoreServiceComponent.java
new file mode 100644
index 0000000..6b1dab9
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/internal/TenantMgtCoreServiceComponent.java
@@ -0,0 +1,129 @@
+/*
+* 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.core.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.component.ComponentContext;
+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.service.TenantRegistryLoader;
+import org.wso2.carbon.registry.core.session.UserRegistry;
+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.apache.stratos.tenant.mgt.core.DefaultTenantPersistor;
+
+/**
+ * @scr.component name="org.wso2.carbon.tenant.mgt.core" 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="tenant.registryloader"
+ * interface="org.wso2.carbon.registry.core.service.TenantRegistryLoader"
+ * cardinality="1..1" policy="dynamic" bind="setTenantRegistryLoader"
+ * unbind="unsetTenantRegistryLoader"
+ */
+public class TenantMgtCoreServiceComponent {
+ private static Log log = LogFactory.getLog(TenantMgtCoreServiceComponent.class);
+
+ private static BundleContext bundleContext;
+ private static RealmService realmService;
+ private static RegistryService registryService;
+ private static TenantPersistor tenantPersistor;
+ private static TenantRegistryLoader registryLoader;
+
+ protected void activate(ComponentContext context) {
+ try {
+ tenantPersistor = new DefaultTenantPersistor();
+ bundleContext = context.getBundleContext();
+ bundleContext.registerService(TenantPersistor.class.getName(), tenantPersistor, null);
+ log.debug("******* Tenant Core bundle is activated ******* ");
+ } catch (Exception e) {
+ log.error("Error occurred while activating tenant.mgt.core bundle. " + e);
+ }
+ }
+
+ protected void setTenantRegistryLoader(TenantRegistryLoader tenantRegLoader) {
+ TenantMgtCoreServiceComponent.registryLoader = tenantRegLoader;
+ }
+
+ protected void unsetTenantRegistryLoader(TenantRegistryLoader tenantRegLoader) {
+ TenantMgtCoreServiceComponent.registryLoader = null;
+ }
+
+ protected void deactivate(ComponentContext context) {
+ log.debug("******* Tenant Core bundle is deactivated ******* ");
+ }
+
+ protected void setRegistryService(RegistryService registryService) {
+ TenantMgtCoreServiceComponent.registryService = registryService;
+ }
+
+ protected void unsetRegistryService(RegistryService registryService) {
+ setRegistryService(null);
+ }
+
+ protected void setRealmService(RealmService realmService) {
+ TenantMgtCoreServiceComponent.realmService = realmService;
+ }
+
+ protected void unsetRealmService(RealmService realmService) {
+ setRealmService(null);
+ }
+
+ public static BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ 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 TenantRegistryLoader getRegistryLoader() {
+ return registryLoader;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/util/TenantCoreUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/util/TenantCoreUtil.java b/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/util/TenantCoreUtil.java
new file mode 100644
index 0000000..d2fd2be
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.core/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/core/util/TenantCoreUtil.java
@@ -0,0 +1,76 @@
+package org.apache.stratos.tenant.mgt.core.util;
+
+import org.apache.stratos.tenant.mgt.core.internal.TenantMgtCoreServiceComponent;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+import org.wso2.carbon.registry.core.Resource;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.utils.AuthenticationObserver;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+import org.wso2.carbon.stratos.common.constants.StratosConstants;
+
+
+/**
+ * Tenant Core Util class - used by any service that needs to create a tenant.
+ */
+public class TenantCoreUtil {
+
+ private static final Log log = LogFactory.getLog(TenantCoreUtil.class);
+
+ /**
+ * Initializes the registry for the tenant.
+ *
+ * @param tenantId
+ * tenant id.
+ */
+ public static void initializeRegistry(int tenantId) {
+ BundleContext bundleContext = TenantMgtCoreServiceComponent.getBundleContext();
+ if (bundleContext != null) {
+ ServiceTracker tracker =
+ new ServiceTracker(bundleContext,
+ AuthenticationObserver.class.getName(),
+ null);
+ tracker.open();
+ Object[] services = tracker.getServices();
+ if (services != null) {
+ for (Object service : services) {
+ ((AuthenticationObserver) service).startedAuthentication(tenantId);
+ }
+ }
+ tracker.close();
+ }
+ }
+
+ /**
+ * Setting the Originated
+ * @param tenantId - tenant Id
+ * @param originatedService - The Service from where the tenant registration was originated.
+ * @throws Exception, Registry Exception, if error in putting the originated Service resource
+ * to the governance registry.
+ */
+ public static void setOriginatedService(int tenantId,
+ String originatedService) throws Exception {
+ if (originatedService != null) {
+ String originatedServicePath =
+ StratosConstants.ORIGINATED_SERVICE_PATH +
+ StratosConstants.PATH_SEPARATOR +
+ StratosConstants.ORIGINATED_SERVICE +
+ StratosConstants.PATH_SEPARATOR + tenantId;
+ try {
+ Resource origServiceRes = TenantMgtCoreServiceComponent.
+ getGovernanceSystemRegistry(MultitenantConstants.SUPER_TENANT_ID).newResource();
+ origServiceRes.setContent(originatedService);
+ TenantMgtCoreServiceComponent.getGovernanceSystemRegistry(MultitenantConstants.SUPER_TENANT_ID).
+ put(originatedServicePath, origServiceRes);
+ } catch (RegistryException e) {
+ String msg = "Error in putting the originated service resource " +
+ "to the governance registry";
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/pom.xml b/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/pom.xml
new file mode 100644
index 0000000..d230d5d
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/pom.xml
@@ -0,0 +1,103 @@
+<!--
+# 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>stratos-components-parent</artifactId>
+ <version>2.0.0</version>
+<relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.stratos.tenant.mgt.email.sender</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Stratos - Tenant Management Email Sender Component</name>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Name>${project.artifactId}</Bundle-Name>
+ <Private-Package>
+ org.apache.stratos.tenant.mgt.email.sender.internal.*,
+ org.apache.stratos.tenant.mgt.email.sender.util.*,
+ </Private-Package>
+ <Export-Package>
+ org.apache.stratos.tenant.mgt.email.sender.listener.*
+ </Export-Package>
+ <Import-Package>
+ !javax.xml.namespace,
+ javax.xml.namespace; version=0.0.0,
+ org.wso2.carbon.email.sender.api,
+ *;resolution:=optional
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.axis2.wso2</groupId>
+ <artifactId>axis2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.13</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.stratos.common</artifactId>
+ <version>2.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.email.verification</artifactId>
+ <version>4.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.core</artifactId>
+ <version>4.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.email.sender</artifactId>
+ <version>2.1.0</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/internal/DataHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/internal/DataHolder.java b/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/internal/DataHolder.java
new file mode 100644
index 0000000..99710c9
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/internal/DataHolder.java
@@ -0,0 +1,104 @@
+/*
+ * 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.email.sender.internal;
+
+import org.wso2.carbon.email.verification.util.EmailVerifcationSubscriber;
+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.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.osgi.framework.BundleContext;
+
+/**
+ * Utility methods for the email sender component
+ */
+public class DataHolder {
+
+ private static RegistryService registryService;
+ private static RealmService realmService;
+ private static ConfigurationContextService configurationContextService;
+ private static EmailVerifcationSubscriber emailVerificationService;
+ private static BundleContext bundleContext;
+
+ public static BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public static void setBundleContext(BundleContext bundleContext) {
+ DataHolder.bundleContext = bundleContext;
+ }
+
+ public static ConfigurationContextService getConfigurationContextService() {
+ return configurationContextService;
+ }
+
+ public static void setConfigurationContextService(
+ ConfigurationContextService configurationContextService) {
+ DataHolder.configurationContextService = configurationContextService;
+ }
+
+ public static ConfigurationContext getConfigurationContext() {
+ return configurationContextService.getServerConfigContext();
+ }
+
+ public static synchronized void setRegistryService(RegistryService service) {
+ if ((registryService == null) || (service == null)) {
+ registryService = service;
+ }
+ }
+
+ public static RegistryService getRegistryService() {
+ return registryService;
+ }
+
+ public static synchronized void setRealmService(RealmService service) {
+ if ((realmService == null) || (service == null)){
+ realmService = service;
+ }
+ }
+
+ 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 void setEmailVerificationService(EmailVerifcationSubscriber emailService) {
+ if ((emailVerificationService == null) || (emailService == null)){
+ emailVerificationService = emailService;
+ }
+ }
+
+ public static EmailVerifcationSubscriber getEmailVerificationService() {
+ return emailVerificationService;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/internal/TenantMgtEmailSenderServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/internal/TenantMgtEmailSenderServiceComponent.java b/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/internal/TenantMgtEmailSenderServiceComponent.java
new file mode 100644
index 0000000..e51a22f
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/internal/TenantMgtEmailSenderServiceComponent.java
@@ -0,0 +1,105 @@
+/*
+* 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.email.sender.internal;
+
+import org.wso2.carbon.email.verification.util.EmailVerifcationSubscriber;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.stratos.common.util.CommonUtil;
+import org.apache.stratos.tenant.mgt.email.sender.listener.EmailSenderListener;
+import org.apache.stratos.tenant.mgt.email.sender.util.TenantMgtEmailSenderUtil;
+import org.wso2.carbon.user.core.service.RealmService;
+import org.wso2.carbon.utils.ConfigurationContextService;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * @scr.component name="org.wso2.carbon.tenant.mgt.email.sender"
+ * 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="emailverification.service"
+ * interface= "org.wso2.carbon.email.verification.util.EmailVerifcationSubscriber"
+ * cardinality="1..1" policy="dynamic"
+ * bind="setEmailVerificationService" unbind="unsetEmailVerificationService"
+ */
+public class TenantMgtEmailSenderServiceComponent {
+ private static Log log = LogFactory.getLog(TenantMgtEmailSenderServiceComponent.class);
+
+ protected void activate(ComponentContext context) {
+ try {
+ DataHolder.setBundleContext(context.getBundleContext());
+ if (!CommonUtil.isTenantManagementEmailsDisabled()) {
+ TenantMgtEmailSenderUtil.init();
+ EmailSenderListener emailSenderListener = new EmailSenderListener();
+ context.getBundleContext().registerService(
+ org.wso2.carbon.stratos.common.listeners.TenantMgtListener.class.getName(),
+ emailSenderListener, null);
+ log.debug("******* Tenant Management Emails are enabled ******* ");
+ }
+ log.debug("******* Tenant Registration Email Sender bundle is activated ******* ");
+ } catch (Throwable e) {
+ log.error("******* Tenant Registration Email Sender bundle failed activating ****", e);
+ }
+ }
+
+ protected void deactivate(ComponentContext context) {
+ log.debug("******* Email Sender bundle is deactivated ******* ");
+ }
+
+ protected void setRegistryService(RegistryService registryService) {
+ DataHolder.setRegistryService(registryService);
+ }
+
+ protected void unsetRegistryService(RegistryService registryService) {
+ DataHolder.setRegistryService(null);
+ }
+
+ protected void setRealmService(RealmService realmService) {
+ DataHolder.setRealmService(realmService);
+ }
+
+ protected void unsetRealmService(RealmService realmService) {
+ DataHolder.setRealmService(null);
+ }
+
+ protected void setConfigurationContextService(ConfigurationContextService service) {
+ DataHolder.setConfigurationContextService(service);
+ }
+
+ protected void unsetConfigurationContextService(ConfigurationContextService service) {
+ DataHolder.setConfigurationContextService(null);
+ }
+
+ protected void setEmailVerificationService(EmailVerifcationSubscriber emailService) {
+ DataHolder.setEmailVerificationService(emailService);
+ }
+
+ protected void unsetEmailVerificationService(EmailVerifcationSubscriber emailService) {
+ DataHolder.setEmailVerificationService(null);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/listener/EmailSenderListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/listener/EmailSenderListener.java b/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/listener/EmailSenderListener.java
new file mode 100644
index 0000000..b3fdb03
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/listener/EmailSenderListener.java
@@ -0,0 +1,70 @@
+package org.apache.stratos.tenant.mgt.email.sender.listener;
+
+import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
+import org.wso2.carbon.stratos.common.exception.StratosException;
+import org.wso2.carbon.stratos.common.listeners.TenantMgtListener;
+import org.apache.stratos.tenant.mgt.email.sender.util.TenantMgtEmailSenderUtil;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class EmailSenderListener implements TenantMgtListener {
+
+ private static final int EXEC_ORDER = 20;
+ private static final Log log = LogFactory.getLog(EmailSenderListener.class);
+
+ public void onTenantCreate(TenantInfoBean tenantInfoBean) throws StratosException {
+ try {
+ TenantMgtEmailSenderUtil.sendTenantCreationVerification(tenantInfoBean);
+ } catch (Exception e) {
+ String message = "Error sending tenant creation Mail to tenant domain "
+ + tenantInfoBean.getTenantDomain();
+ log.error(message, e);
+ throw new StratosException(message, e);
+ }
+ TenantMgtEmailSenderUtil.notifyTenantCreationToSuperAdmin(tenantInfoBean);
+ }
+
+ public int getListenerOrder() {
+ return EXEC_ORDER;
+ }
+
+ public void onTenantRename(int tenantId, String oldDomainName,
+ String newDomainName) throws StratosException {
+ // Do nothing.
+
+ }
+
+ public void onTenantUpdate(TenantInfoBean tenantInfoBean) throws StratosException {
+ if ((tenantInfoBean.getAdminPassword() != null) &&
+ (!tenantInfoBean.getAdminPassword().equals(""))) {
+ try {
+ TenantMgtEmailSenderUtil.notifyResetPassword(tenantInfoBean);
+ } catch (Exception e) {
+ String message = "Error sending tenant update Mail to tenant domain "
+ + tenantInfoBean.getTenantDomain();
+ log.error(message, e);
+ throw new StratosException(message, e);
+ }
+ }
+ }
+
+ public void onTenantInitialActivation(int tenantId) throws StratosException {
+ // send the notification message to the tenant admin
+ TenantMgtEmailSenderUtil.notifyTenantInitialActivation(tenantId);
+ }
+
+ public void onTenantActivation(int tenantId) throws StratosException {
+ // Do nothing.
+ }
+
+ public void onTenantDeactivation(int tenantId) throws StratosException {
+ // Do nothing.
+ }
+
+ public void onSubscriptionPlanChange(int tenentId, String oldPlan,
+ String newPlan) throws StratosException {
+ // Do nothing.
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/util/TenantMgtEmailSenderUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/util/TenantMgtEmailSenderUtil.java b/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/util/TenantMgtEmailSenderUtil.java
new file mode 100644
index 0000000..6b64019
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.email.sender/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/email/sender/util/TenantMgtEmailSenderUtil.java
@@ -0,0 +1,482 @@
+/*
+ * 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.email.sender.util;
+
+import org.apache.stratos.tenant.mgt.email.sender.internal.DataHolder;
+import org.wso2.carbon.email.sender.api.EmailSender;
+import org.wso2.carbon.email.sender.api.EmailSenderConfiguration;
+import org.wso2.carbon.email.verification.util.EmailVerifcationSubscriber;
+import org.wso2.carbon.email.verification.util.EmailVerifierConfig;
+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.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.util.ClaimsMgtUtil;
+import org.wso2.carbon.stratos.common.util.CommonUtil;
+import org.wso2.carbon.user.api.Tenant;
+import org.wso2.carbon.user.core.tenant.TenantManager;
+import org.wso2.carbon.utils.AuthenticationObserver;
+import org.wso2.carbon.utils.CarbonUtils;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * Utility methods for the email sender component
+ */
+public class TenantMgtEmailSenderUtil {
+
+ private static final Log log = LogFactory.getLog(TenantMgtEmailSenderUtil.class);
+
+ private static EmailSender successMsgSender;
+ private static EmailSender tenantCreationNotifier;
+ private static EmailSender tenantActivationNotifier;
+ private static EmailSender passwordResetMsgSender;
+ private static EmailVerifierConfig emailVerifierConfig;
+ private static EmailVerifierConfig superTenantEmailVerifierConfig = null;
+
+ public static void init() {
+ initTenantActivatedEmailSender();
+ initSuperTenantNotificationEmailSender();
+ initEmailVerificationSender();
+ initPasswordResetEmailSender();
+ }
+
+ /**
+ * Sends validation mail to the tenant admin upon the tenant creation
+ *
+ * @param tenantInfoBean - registered tenant's details
+ * @throws Exception, if the sending mail failed
+ */
+ public static void sendTenantCreationVerification(
+ TenantInfoBean tenantInfoBean) throws Exception {
+ String confirmationKey = generateConfirmationKey(tenantInfoBean,
+ DataHolder.getRegistryService().getConfigSystemRegistry(
+ MultitenantConstants.SUPER_TENANT_ID));
+
+ if (CommonUtil.isTenantActivationModerated()) {
+ requestSuperTenantModeration(tenantInfoBean, confirmationKey);
+ } else {
+ //request for verification
+ requestUserVerification(tenantInfoBean, confirmationKey);
+ }
+ }
+
+ /**
+ * Emails the tenant admin notifying the account creation.
+ *
+ * @param tenantId tenant Id
+ */
+ public static void notifyTenantInitialActivation(int tenantId) {
+ TenantManager tenantManager = DataHolder.getTenantManager();
+ String firstName = "";
+ String domainName = "";
+ String adminName = "";
+ String email = "";
+ try {
+ Tenant tenant = tenantManager.getTenant(tenantId);
+ domainName = tenant.getDomain();
+ firstName = ClaimsMgtUtil.getFirstName(DataHolder.getRealmService(), tenantId);
+ adminName = tenant.getAdminName();
+ email = tenant.getEmail();
+ } catch (Exception e) {
+ String msg = "Unable to get the tenant with the tenant domain";
+ log.error(msg, e);
+ // just catch from here.
+ }
+
+ // load the mail configuration
+ Map<String, String> userParams = new HashMap<String, String>();
+ userParams.put("first-name", firstName);
+ userParams.put("user-name", adminName);
+ userParams.put("domain-name", domainName);
+
+ try {
+ successMsgSender.sendEmail(email, userParams);
+ } catch (Exception e) {
+ // just catch from here..
+ String msg = "Error in sending the notification email.";
+ log.error(msg, e);
+ }
+
+ // send the notification message to the super tenant
+ notifyTenantActivationToSuperAdmin(domainName, adminName, email);
+ }
+
+ /**
+ * Emails the super admin notifying the account creation for a new tenant.
+ *
+ * @param tenantInfoBean - tenant details
+ */
+ public static void notifyTenantCreationToSuperAdmin(TenantInfoBean tenantInfoBean) {
+ String notificationEmailAddress = CommonUtil.getNotificationEmailAddress();
+
+ if (notificationEmailAddress.trim().equals("")) {
+ if (log.isDebugEnabled()) {
+ log.debug("No super-admin notification email address is set to notify upon a" +
+ " tenant registration");
+ }
+ return;
+ }
+
+ Map<String, String> userParams = initializeSuperTenantNotificationParams(
+ tenantInfoBean.getTenantDomain(), tenantInfoBean.getAdmin(),
+ tenantInfoBean.getEmail());
+
+ try {
+ tenantCreationNotifier.sendEmail(notificationEmailAddress, userParams);
+ } catch (Exception e) {
+ // just catch from here..
+ String msg = "Error in sending the notification email.";
+ log.error(msg, e);
+ }
+ }
+
+ public static void notifyResetPassword(TenantInfoBean tenantInfoBean) throws Exception {
+ int tenantId = tenantInfoBean.getTenantId();
+ String firstName = ClaimsMgtUtil.getFirstName(DataHolder.getRealmService(), tenantId);
+
+ // load the mail configuration
+ Map<String, String> userParams = new HashMap<String, String>();
+ userParams.put("user-name", tenantInfoBean.getAdmin());
+ userParams.put("first-name", firstName);
+ userParams.put("domain-name", tenantInfoBean.getTenantDomain());
+ userParams.put("password", tenantInfoBean.getAdminPassword());
+
+ try {
+ passwordResetMsgSender.sendEmail(tenantInfoBean.getEmail(), userParams);
+ } catch (Exception e) {
+ // just catch from here..
+ String msg = "Error in sending the notification email.";
+ log.error(msg, e);
+ }
+ }
+
+ /**
+ * Emails the super admin notifying the account activation for an unactivated tenant.
+ *
+ * @param domainName tenant domain
+ * @param adminName tenant admin
+ * @param email tenant's email address
+ */
+ private static void notifyTenantActivationToSuperAdmin(String domainName, String adminName,
+ String email) {
+ String notificationEmailAddress = CommonUtil.getNotificationEmailAddress();
+
+ if (notificationEmailAddress.trim().equals("")) {
+ if (log.isDebugEnabled()) {
+ log.debug("No super-admin notification email address is set to notify upon a"
+ + " tenant activation");
+ }
+ return;
+ }
+
+ Map<String, String> userParams =
+ initializeSuperTenantNotificationParams(domainName, adminName, email);
+
+ try {
+ tenantActivationNotifier.sendEmail(notificationEmailAddress, userParams);
+ } catch (Exception e) {
+ // just catch from here..
+ String msg = "Error in sending the notification email.";
+ log.error(msg, e);
+ }
+ }
+
+ /**
+ * generates the confirmation key for the tenant
+ *
+ * @param tenantInfoBean - tenant details
+ * @param superTenantConfigSystemRegistry
+ * - super tenant config system registry.
+ * @return confirmation key
+ * @throws RegistryException if generation of the confirmation key failed.
+ */
+ private static String generateConfirmationKey(TenantInfoBean tenantInfoBean,
+ UserRegistry superTenantConfigSystemRegistry
+ ) throws RegistryException {
+ // generating the confirmation key
+ String confirmationKey = UUIDGenerator.generateUUID();
+ UserRegistry superTenantGovernanceSystemRegistry;
+ try {
+ superTenantGovernanceSystemRegistry =
+ DataHolder.getRegistryService().getGovernanceSystemRegistry(
+ MultitenantConstants.SUPER_TENANT_ID);
+ } catch (RegistryException e) {
+ String msg = "Exception in getting the governance system registry for the super tenant";
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ Resource resource;
+ String emailVerificationPath = StratosConstants.ADMIN_EMAIL_VERIFICATION_FLAG_PATH +
+ RegistryConstants.PATH_SEPARATOR +
+ tenantInfoBean.getTenantId();
+ try {
+ if (superTenantGovernanceSystemRegistry.resourceExists(emailVerificationPath)) {
+ resource = superTenantGovernanceSystemRegistry.get(emailVerificationPath);
+ } else {
+ resource = superTenantGovernanceSystemRegistry.newResource();
+ }
+ resource.setContent(confirmationKey);
+ } catch (RegistryException e) {
+ String msg = "Error in creating the resource or getting the resource" +
+ "from the email verification path";
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ // email is not validated yet, this prop is used to activate the tenant later.
+ resource.addProperty(StratosConstants.IS_EMAIL_VALIDATED, "false");
+ resource.addProperty(StratosConstants.TENANT_ADMIN, tenantInfoBean.getAdmin());
+ try {
+ superTenantGovernanceSystemRegistry.put(emailVerificationPath, resource);
+ } catch (RegistryException e) {
+ String msg = "Error in putting the resource to the super tenant registry" +
+ " for the email verification path";
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+
+ // Used for * as a Service impl.
+ // Store the cloud service from which the register req. is originated.
+ if (tenantInfoBean.getOriginatedService() != null) {
+ String originatedServicePath =
+ StratosConstants.ORIGINATED_SERVICE_PATH +
+ StratosConstants.PATH_SEPARATOR +
+ StratosConstants.ORIGINATED_SERVICE +
+ StratosConstants.PATH_SEPARATOR + tenantInfoBean.getTenantId();
+ try {
+ Resource origServiceRes = superTenantConfigSystemRegistry.newResource();
+ origServiceRes.setContent(tenantInfoBean.getOriginatedService());
+ superTenantGovernanceSystemRegistry.put(originatedServicePath, origServiceRes);
+ } catch (RegistryException e) {
+ String msg = "Error in putting the originated service resource "
+ + "to the governance registry";
+ log.error(msg, e);
+ throw new RegistryException(msg, e);
+ }
+ }
+ initializeRegistry(tenantInfoBean.getTenantId());
+ if (log.isDebugEnabled()) {
+ log.debug("Successfully generated the confirmation key.");
+ }
+ return confirmationKey;
+ }
+
+ /**
+ * Sends mail for the super tenant for the account moderation. Once super tenant clicks the
+ * link provided in the email, the tenant will be activated.
+ *
+ * @param tenantInfoBean - the tenant who registered an account
+ * @param confirmationKey confirmation key.
+ * @throws Exception if an exception is thrown from EmailVerificationSubscriber.
+ */
+ private static void requestSuperTenantModeration(TenantInfoBean tenantInfoBean,
+ String confirmationKey) throws Exception {
+ try {
+ Map<String, String> dataToStore = new HashMap<String, String>();
+ dataToStore.put("email", CommonUtil.getSuperAdminEmail());
+ dataToStore.put("first-name", tenantInfoBean.getFirstname());
+ dataToStore.put("userName", tenantInfoBean.getAdmin());
+ dataToStore.put("tenantDomain", tenantInfoBean.getTenantDomain());
+ dataToStore.put("confirmationKey", confirmationKey);
+
+ DataHolder.getEmailVerificationService().requestUserVerification(
+ dataToStore, superTenantEmailVerifierConfig);
+ if (log.isDebugEnabled()) {
+ log.debug("Email verification for the tenant registration.");
+ }
+ } catch (Exception e) {
+ String msg = "Error in notifying the super tenant on the account creation for " +
+ "the domain: " + tenantInfoBean.getTenantDomain();
+ log.error(msg);
+ throw new Exception(msg, e);
+ }
+ }
+
+ /**
+ * request email verification from the user.
+ *
+ * @param tenantInfoBean - Tenant information
+ * @param confirmationKey confirmation key.
+ * @throws Exception if an exception is thrown from EmailVerificationSubscriber.
+ */
+ private static void requestUserVerification(TenantInfoBean tenantInfoBean,
+ String confirmationKey) throws Exception {
+ try {
+ Map<String, String> dataToStore = new HashMap<String, String>();
+ dataToStore.put("email", tenantInfoBean.getEmail());
+ dataToStore.put("first-name", tenantInfoBean.getFirstname());
+ dataToStore.put("userName", tenantInfoBean.getAdmin());
+ dataToStore.put("tenantDomain", tenantInfoBean.getTenantDomain());
+ dataToStore.put("confirmationKey", confirmationKey);
+
+ EmailVerifcationSubscriber emailVerifier = DataHolder.getEmailVerificationService();
+ emailVerifier.requestUserVerification(dataToStore, emailVerifierConfig);
+ if (log.isDebugEnabled()) {
+ log.debug("Email verification for the tenant registration.");
+ }
+ } catch (Exception e) {
+ String msg = "Error in notifying tenant of domain: " + tenantInfoBean.getTenantDomain();
+ log.error(msg);
+ throw new Exception(msg, e);
+ }
+ }
+
+ /**
+ * Initializes the registry for the tenant.
+ *
+ * @param tenantId tenant id.
+ */
+ private static void initializeRegistry(int tenantId) {
+ BundleContext bundleContext = DataHolder.getBundleContext();
+ if (bundleContext != null) {
+ ServiceTracker tracker =
+ new ServiceTracker(bundleContext,
+ AuthenticationObserver.class.getName(),
+ null);
+ tracker.open();
+ Object[] services = tracker.getServices();
+ if (services != null) {
+ for (Object service : services) {
+ ((AuthenticationObserver) service).startedAuthentication(tenantId);
+ }
+ }
+ tracker.close();
+ }
+ }
+
+ /**
+ * loads the notification configurations for the mail to super tenant for account creations
+ * and activations.
+ */
+ private static void initSuperTenantNotificationEmailSender() {
+ // Tenant Registration Email Configurations
+ String tenantRegistrationEmailConfFile =
+ CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ StratosConstants.EMAIL_CONFIG + File.separator +
+ "email-new-tenant-registration.xml";
+ EmailSenderConfiguration newTenantRegistrationEmailConf =
+ EmailSenderConfiguration.loadEmailSenderConfiguration(
+ tenantRegistrationEmailConfFile);
+ tenantCreationNotifier = new EmailSender(newTenantRegistrationEmailConf);
+
+ // Tenant Activation Email Configurations
+ String tenantActivationEmailConfFile =
+ CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ StratosConstants.EMAIL_CONFIG + File.separator +
+ "email-new-tenant-activation.xml";
+ EmailSenderConfiguration newTenantActivationEmailConf =
+ EmailSenderConfiguration
+ .loadEmailSenderConfiguration(tenantActivationEmailConfFile);
+ tenantActivationNotifier = new EmailSender(newTenantActivationEmailConf);
+ }
+
+ /**
+ * loads the Email configuration files to be sent on the tenant registrations.
+ */
+ private static void initEmailVerificationSender() {
+ String confXml =
+ CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ StratosConstants.EMAIL_CONFIG + File.separator + "email-registration.xml";
+ try {
+ emailVerifierConfig = org.wso2.carbon.email.verification.util.Util
+ .loadeMailVerificationConfig(confXml);
+ } catch (Exception e) {
+ String msg = "Email Registration Configuration file not found. "
+ + "Pls check the repository/conf/email folder.";
+ log.error(msg);
+ }
+ String superTenantConfXml =
+ CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ StratosConstants.EMAIL_CONFIG + File.separator +
+ "email-registration-moderation.xml";
+ try {
+ superTenantEmailVerifierConfig = org.wso2.carbon.email.verification.util.Util
+ .loadeMailVerificationConfig(superTenantConfXml);
+ } catch (Exception e) {
+ String msg =
+ "Email Moderation Configuration file not found. "
+ + "Pls check the repository/conf/email folder.";
+ log.error(msg);
+ }
+ }
+
+ /**
+ * loads the Email configuration files to be sent on the tenant activations.
+ */
+ private static void initTenantActivatedEmailSender() {
+ String confFilename =
+ CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ StratosConstants.EMAIL_CONFIG + File.separator +
+ "email-registration-complete.xml";
+ EmailSenderConfiguration successMsgConfig =
+ EmailSenderConfiguration.loadEmailSenderConfiguration(confFilename);
+ successMsgSender = new EmailSender(successMsgConfig);
+ }
+
+ private static void initPasswordResetEmailSender() {
+ String passwordResetConfigFileName = CarbonUtils.getCarbonConfigDirPath()+ File.separator +
+ StratosConstants.EMAIL_CONFIG + File.separator + "email-password-reset.xml";
+ EmailSenderConfiguration passwordResetMsgConfig =
+ EmailSenderConfiguration.loadEmailSenderConfiguration(passwordResetConfigFileName);
+ passwordResetMsgSender = new EmailSender(passwordResetMsgConfig);
+ }
+
+ /**
+ * Initializes the super tenant notification parameters
+ *
+ * @param domainName - tenant domain
+ * @param adminName - tenant admin
+ * @param email - tenant email
+ * @return the parameters
+ */
+ private static Map<String, String> initializeSuperTenantNotificationParams(
+ String domainName, String adminName, String email) {
+ TenantManager tenantManager = DataHolder.getTenantManager();
+ String firstName = "";
+ String lastName = "";
+ try {
+ int tenantId = tenantManager.getTenantId(domainName);
+ firstName = ClaimsMgtUtil.getFirstName(DataHolder.getRealmService(), tenantId);
+ lastName = ClaimsMgtUtil.getLastName(DataHolder.getRealmService(), tenantId);
+
+ } catch (Exception e) {
+ String msg = "Unable to get the tenant with the tenant domain";
+ log.error(msg, e);
+ // just catch from here.
+ }
+
+ // load the mail configuration
+ Map<String, String> userParams = new HashMap<String, String>();
+ userParams.put("user-name", adminName);
+ userParams.put("domain-name", domainName);
+ userParams.put("email-address", email);
+ userParams.put("first-name", firstName);
+ userParams.put("last-name", lastName);
+ return userParams;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/pom.xml b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/pom.xml
new file mode 100644
index 0000000..76f84db
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/pom.xml
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+# 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>stratos-components-parent</artifactId>
+ <version>2.0.0</version>
+<relativePath>../../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.stratos.tenant.mgt.ui</artifactId>
+ <version>2.1.0</version>
+ <packaging>bundle</packaging>
+ <name>Apache Stratos - User Interface for Tenant CRUD operations</name>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Name>${project.artifactId}</Bundle-Name>
+ <Export-Package>
+ org.apache.stratos.tenant.mgt.ui.*,
+ </Export-Package>
+ <Import-Package>
+ org.apache.stratos.tenant.mgt.stub.*; version="${carbon.platform.package.import.version.range}",
+ org.apache.axis2.client.*,
+ javax.servlet;version="${imp.pkg.version.javax.servlet}",
+ javax.servlet.http;version="${imp.pkg.version.javax.servlet}",
+ org.apache.lucene.*,
+ *;resolution:=optional
+ </Import-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ <Carbon-Component>UIBundle</Carbon-Component>
+ </instructions>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.common.ui</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.core</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.equinox</groupId>
+ <artifactId>javax.servlet</artifactId>
+ <version>3.0.0.v201112011016</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.axis2.wso2</groupId>
+ <artifactId>axis2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ws.commons.axiom.wso2</groupId>
+ <artifactId>axiom</artifactId>
+ <version>1.2.11.wso2v2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.ui</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.tenant.mgt.stub</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.stratos.common</artifactId>
+ <version>2.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.json.wso2</groupId>
+ <artifactId>json</artifactId>
+ <version>1.0.0.wso2v1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.stratos.common.stub</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ </dependencies>
+</project>