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:38 UTC
[03/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/util/TenantRegistryDataDeletionUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantRegistryDataDeletionUtil.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantRegistryDataDeletionUtil.java
deleted file mode 100644
index f640c65..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantRegistryDataDeletionUtil.java
+++ /dev/null
@@ -1,119 +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.util;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-public class TenantRegistryDataDeletionUtil {
- public static final Log log = LogFactory.getLog(TenantRegistryDataDeletionUtil.class);
-
- /**
- * Delete all tenant information related to tenant stored in REG tables
- * @param tenantId id of tenant whose data should be deleted
- * @param conn database connection object
- * @throws SQLException thrown if an error occurs while executing the queries
- */
- public static void deleteTenantRegistryData(int tenantId, Connection conn) throws Exception {
- try {
- conn.setAutoCommit(false);
- String deleteClusterLockSql = "DELETE FROM REG_CLUSTER_LOCK WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteClusterLockSql, tenantId);
-
- String deleteLogSql = "DELETE FROM REG_LOG WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteLogSql, tenantId);
-
- String deleteAssociationSql = "DELETE FROM REG_ASSOCIATION WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteAssociationSql, tenantId);
-
- String deleteSnapshotSql = "DELETE FROM REG_SNAPSHOT WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteSnapshotSql, tenantId);
-
- String deleteResourceCommentSql = "DELETE FROM REG_RESOURCE_COMMENT WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteResourceCommentSql, tenantId);
-
- String deleteCommentSql = "DELETE FROM REG_COMMENT WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteCommentSql, tenantId);
-
- String deleteResourceRatingSql = "DELETE FROM REG_RESOURCE_RATING WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteResourceRatingSql, tenantId);
-
- String deleteRatingSql = "DELETE FROM REG_RATING WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteRatingSql, tenantId);
-
- String deleteResourceTagSql = "DELETE FROM REG_RESOURCE_TAG WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteResourceTagSql, tenantId);
-
- String deleteTagSql = "DELETE FROM REG_TAG WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteTagSql, tenantId);
-
- String deleteResourcePropertySql = "DELETE FROM REG_RESOURCE_PROPERTY WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteResourcePropertySql, tenantId);
-
- String deletePropertySql = "DELETE FROM REG_PROPERTY WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deletePropertySql, tenantId);
-
- String deleteResourceHistorySql = "DELETE FROM REG_RESOURCE_HISTORY WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteResourceHistorySql, tenantId);
-
- String deleteContentHistorySql = "DELETE FROM REG_CONTENT_HISTORY WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteContentHistorySql, tenantId);
-
- String deleteResourceSql = "DELETE FROM REG_RESOURCE WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteResourceSql, tenantId);
-
- String deleteContentSql = "DELETE FROM REG_CONTENT WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteContentSql, tenantId);
-
- String deletePathSql = "DELETE FROM REG_PATH WHERE REG_TENANT_ID = ?";
- executeDeleteQuery(conn, deletePathSql, tenantId);
-
- conn.commit();
- } catch (SQLException e) {
- conn.rollback();
- String errorMsg = "An error occurred while deleting registry data for tenant: " + tenantId;
- log.error(errorMsg, e);
- throw new Exception(errorMsg, e);
- } finally {
- conn.close();
- }
- }
-
- private static void executeDeleteQuery(Connection conn, String query, int tenantId)
- throws Exception {
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement(query);
- ps.setInt(1, tenantId);
- ps.executeUpdate();
- } catch (SQLException e) {
- String errMsg = "Error executing query " + query + " for tenant: " + tenantId;
- log.error(errMsg, e);
- throw new Exception(errMsg, e);
- } finally {
- if (ps != null) {
- ps.close();
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantUMDataDeletionUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantUMDataDeletionUtil.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantUMDataDeletionUtil.java
deleted file mode 100644
index d857e38..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantUMDataDeletionUtil.java
+++ /dev/null
@@ -1,112 +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.util;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.SQLException;
-
-public class TenantUMDataDeletionUtil {
- public static final Log log = LogFactory.getLog(TenantUMDataDeletionUtil.class);
-
- /**
- * Delete all tenant information related to tenant stored in UM tables
- * @param tenantId id of tenant whose data should be deleted
- * @param conn database connection object
- * @throws SQLException thrown if an error occurs while executing the queries
- */
- public static void deleteTenantUMData(int tenantId, Connection conn) throws Exception {
- try {
- conn.setAutoCommit(false);
- String deleteUserPermissionSql = "DELETE FROM UM_USER_PERMISSION WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteUserPermissionSql, tenantId);
-
- String deleteRolePermissionSql = "DELETE FROM UM_ROLE_PERMISSION WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteRolePermissionSql, tenantId);
-
- String deletePermissionSql = "DELETE FROM UM_PERMISSION WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deletePermissionSql, tenantId);
-
- String deleteClaimBehaviourSql = "DELETE FROM UM_CLAIM_BEHAVIOR WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteClaimBehaviourSql, tenantId);
-
- String deleteProfileConfigSql = "DELETE FROM UM_PROFILE_CONFIG WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteProfileConfigSql, tenantId);
-
- String deleteClaimSql = "DELETE FROM UM_CLAIM WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteClaimSql, tenantId);
-
- String deleteDialectSql = "DELETE FROM UM_DIALECT WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteDialectSql, tenantId);
-
- String deleteUserAttributeSql = "DELETE FROM UM_USER_ATTRIBUTE WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteUserAttributeSql, tenantId);
-
- String deleteHybridUserRoleSql = "DELETE FROM UM_HYBRID_USER_ROLE WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteHybridUserRoleSql, tenantId);
-
- String deleteHybridRoleSql = "DELETE FROM UM_HYBRID_ROLE WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteHybridRoleSql, tenantId);
-
- String deleteHybridRememberMeSql = "DELETE FROM UM_HYBRID_REMEMBER_ME WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteHybridRememberMeSql, tenantId);
-
- String deleteUserRoleSql = "DELETE FROM UM_USER_ROLE WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteUserRoleSql, tenantId);
-
- String deleteRoleSql = "DELETE FROM UM_ROLE WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteRoleSql, tenantId);
-
- String deleteUserSql = "DELETE FROM UM_USER WHERE UM_TENANT_ID = ?";
- executeDeleteQuery(conn, deleteUserSql, tenantId);
-
- String deleteTenantSql = "DELETE FROM UM_TENANT WHERE UM_ID = ?";
- executeDeleteQuery(conn, deleteTenantSql, tenantId);
-
- conn.commit();
- } catch (Exception e) {
- conn.rollback();
- String errorMsg = "An error occurred while deleting registry data for tenant: " + tenantId;
- log.error(errorMsg, e);
- throw new Exception(errorMsg, e);
- } finally {
- conn.close();
- }
- }
-
- private static void executeDeleteQuery(Connection conn, String query, int tenantId)
- throws Exception {
- PreparedStatement ps = null;
- try {
- ps = conn.prepareStatement(query);
- ps.setInt(1, tenantId);
- ps.executeUpdate();
- } catch (SQLException e) {
- String errMsg = "Error executing query " + query + " for tenant: " + tenantId;
- log.error(errMsg, e);
- throw new Exception(errMsg, e);
- } finally {
- if (ps != null) {
- ps.close();
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/resources/META-INF/component.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/resources/META-INF/component.xml b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/resources/META-INF/component.xml
deleted file mode 100644
index 883930f..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/resources/META-INF/component.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Copyright (c) 2009, 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.
- -->
-
-<component xmlns="http://products.wso2.org/carbon">
- <ManagementPermissions>
- <ManagementPermission>
- <DisplayName>Manage</DisplayName>
- <ResourceId>/permission/protected/manage</ResourceId>
- </ManagementPermission>
- <ManagementPermission>
- <DisplayName>Monitor</DisplayName>
- <ResourceId>/permission/protected/manage/monitor</ResourceId>
- </ManagementPermission>
- <ManagementPermission>
- <DisplayName>Tenants</DisplayName>
- <ResourceId>/permission/protected/manage/monitor/tenants</ResourceId>
- </ManagementPermission>
- <ManagementPermission>
- <DisplayName>Modify</DisplayName>
- <ResourceId>/permission/protected/manage/modify</ResourceId>
- </ManagementPermission>
- <ManagementPermission>
- <DisplayName>Tenants</DisplayName>
- <ResourceId>/permission/protected/manage/modify/tenants</ResourceId>
- </ManagementPermission>
- </ManagementPermissions>
-</component>
\ 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/resources/META-INF/services.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/resources/META-INF/services.xml b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/resources/META-INF/services.xml
deleted file mode 100644
index 7e87c44..0000000
--- a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/resources/META-INF/services.xml
+++ /dev/null
@@ -1,155 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- !
- ! Copyright 2006 The Apache Software Foundation.
- !
- ! 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.
- !-->
-<serviceGroup>
-
- <service name="TenantMgtService" scope="transportsession">
- <transports>
- <transport>https</transport>
- </transports>
- <parameter name="ServiceClass" locked="false">
- org.apache.stratos.tenant.mgt.services.TenantSelfRegistrationService
- </parameter>
- <operation name="registerTenant">
- </operation>
- <operation name="checkDomainAvailability">
- </operation>
- <operation name="validateOrSuggestDomain">
- </operation>
- <operation name="generateRandomCaptcha">
- </operation>
- </service>
-
- <service name="TenantMgtAdminService" scope="transportsession">
- <transports>
- <transport>https</transport>
- </transports>
- <parameter name="ServiceClass" locked="false">
- org.apache.stratos.tenant.mgt.services.TenantMgtAdminService
- </parameter>
- <operation name="addTenant">
- <parameter name="superTenantService" locked="true">true</parameter>
- <parameter name="AuthorizationAction" locked="true">/permission/protected/manage/monitor/tenants</parameter>
- </operation>
- <operation name="retrieveTenants">
- <parameter name="superTenantService" locked="true">true</parameter>
- <parameter name="AuthorizationAction" locked="true">/permission/protected/manage/monitor/tenants</parameter>
- </operation>
- <operation name="retrievePaginatedTenants">
- <parameter name="superTenantService" locked="true">true</parameter>
- <parameter name="AuthorizationAction" locked="true">/permission/protected/manage/monitor/tenants</parameter>
- </operation>
- <operation name="retrievePartialSearchTenants">
- <parameter name="superTenantService" locked="true">true</parameter>
- <parameter name="AuthorizationAction" locked="true">/permission/protected/manage/monitor/tenants</parameter>
- </operation>
- <operation name="retrievePaginatedPartialSearchTenants">
- <parameter name="superTenantService" locked="true">true</parameter>
- <parameter name="AuthorizationAction" locked="true">/permission/protected/manage/monitor/tenants</parameter>
- </operation>
- <operation name="getTenant">
- <parameter name="superTenantService" locked="true">true</parameter>
- <parameter name="AuthorizationAction" locked="true">/permission/protected/manage/monitor/tenants</parameter>
- </operation>
- <operation name="updateTenant">
- <parameter name="superTenantService" locked="true">true</parameter>
- <parameter name="AuthorizationAction" locked="true">/permission/protected/manage/modify/tenants</parameter>
- </operation>
- <operation name="activateTenant">
- <parameter name="superTenantService" locked="true">true</parameter>
- <parameter name="AuthorizationAction" locked="true">/permission/protected/manage/modify/tenants</parameter>
- </operation>
- <operation name="deactivateTenant">
- <parameter name="superTenantService" locked="true">true</parameter>
- <parameter name="AuthorizationAction" locked="true">/permission/protected/manage/modify/tenants</parameter>
- </operation>
- <operation name="deleteTenant">
- <parameter name="superTenantService" locked="true">true</parameter>
- <parameter name="AuthorizationAction" locked="true">/permission/protected/manage/modify/tenants</parameter>
- </operation>
- <parameter name="adminService" locked="true">true</parameter>
- </service>
-
- <service name="GAppTenantRegistrationService">
- <transports>
- <transport>https</transport>
- </transports>
- <schema schemaNamespace="http://org.apache.axis2/xsd" elementFormDefaultQualified="true"/>
- <description>Rampart protected service that is used to setup Google Apps domain</description>
- <parameter name="ServiceClass">org.apache.stratos.tenant.mgt.services.GAppTenantRegistrationService</parameter>
- <parameter name="adminService" locked="true">false</parameter>
-
- <module ref="rampart"/>
-
- <wsp:Policy wsu:Id="SigOnly"
- xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
- xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
- <wsp:ExactlyOne>
- <wsp:All>
- <sp:AsymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
- <wsp:Policy>
- <sp:InitiatorToken>
- <wsp:Policy>
- <sp:X509Token
- sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
- <wsp:Policy>
- <sp:RequireThumbprintReference/>
- <sp:WssX509V3Token10/>
- </wsp:Policy>
- </sp:X509Token>
- </wsp:Policy>
- </sp:InitiatorToken>
- <sp:RecipientToken>
- <wsp:Policy>
- <sp:X509Token
- sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never">
- <wsp:Policy>
- <sp:RequireThumbprintReference/>
- <sp:WssX509V3Token10/>
- </wsp:Policy>
- </sp:X509Token>
- </wsp:Policy>
- </sp:RecipientToken>
- <sp:AlgorithmSuite>
- <wsp:Policy>
- <sp:Basic256/>
- </wsp:Policy>
- </sp:AlgorithmSuite>
- <sp:Layout>
- <wsp:Policy>
- <sp:Strict/>
- </wsp:Policy>
- </sp:Layout>
- <sp:IncludeTimestamp/>
- <sp:OnlySignEntireHeadersAndBody/>
- </wsp:Policy>
- </sp:AsymmetricBinding>
- <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
- <wsp:Policy>
- <sp:MustSupportRefKeyIdentifier/>
- <sp:MustSupportRefIssuerSerial/>
- </wsp:Policy>
- </sp:Wss10>
- <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
- <sp:Body/>
- </sp:SignedParts>
- </wsp:All>
- </wsp:ExactlyOne>
- </wsp:Policy>
- </service>
- <parameter name="hiddenService" locked="true">true</parameter>
-</serviceGroup>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/pom.xml b/components/org.apache.stratos.tenant.mgt/pom.xml
new file mode 100644
index 0000000..27c9b40
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/pom.xml
@@ -0,0 +1,123 @@
+<!--
+# 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>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.stratos.tenant.mgt</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Stratos - Tenant Managment</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.internal.*,
+ org.apache.stratos.tenant.mgt.persistence.*,
+ </Private-Package>
+ <Import-Package>
+ org.apache.stratos.common.*,
+ org.wso2.carbon.registry.core.*;version=1.0.1,
+ org.wso2.carbon.captcha.mgt.*,
+ !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.beans.*,
+ org.apache.stratos.tenant.mgt.exception.*,
+ org.apache.stratos.tenant.mgt.realm.*,
+ org.apache.stratos.tenant.mgt.services.*,
+ org.apache.stratos.tenant.mgt.util.*,
+ </Export-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.user.core</artifactId>
+ <version>${wso2carbon.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.tenant.mgt.core</artifactId>
+ <version>${apache.stratos.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.core</artifactId>
+ <version>${wso2carbon.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.um.ws.api</artifactId>
+ <version>${wso2carbon.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.captcha.mgt</artifactId>
+ <version>${wso2carbon.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.common</artifactId>
+ <version>${apache.stratos.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.admin.mgt</artifactId>
+ <version>${wso2carbon.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rampart.wso2</groupId>
+ <artifactId>rampart-policy</artifactId>
+ <version>${rampart.wso2.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rampart.wso2</groupId>
+ <artifactId>rampart-core</artifactId>
+ <version>${rampart.wso2.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/beans/PaginatedTenantInfoBean.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/beans/PaginatedTenantInfoBean.java b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/beans/PaginatedTenantInfoBean.java
new file mode 100644
index 0000000..3a16cac
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/beans/PaginatedTenantInfoBean.java
@@ -0,0 +1,52 @@
+/*
+ * 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.beans;
+
+import org.apache.stratos.common.beans.TenantInfoBean;
+import org.wso2.carbon.utils.Pageable;
+
+import java.util.List;
+
+/**
+ * Bean for paginated tenant information
+ */
+public class PaginatedTenantInfoBean implements Pageable {
+ private TenantInfoBean[] tenantInfoBeans;
+ private int numberOfPages;
+
+ public TenantInfoBean[] getTenantInfoBeans() {
+ return tenantInfoBeans;
+ }
+
+ public void setTenantInfoBeans(TenantInfoBean[] tenantInfoBeans) {
+ this.tenantInfoBeans = tenantInfoBeans;
+ }
+
+ public int getNumberOfPages() {
+ return numberOfPages;
+ }
+
+ public void setNumberOfPages(int numberOfPages) {
+ this.numberOfPages = numberOfPages;
+ }
+
+ public <T> void set(List<T> items) {
+ this.tenantInfoBeans = items.toArray(new TenantInfoBean[items.size()]);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/exception/TenantManagementException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/exception/TenantManagementException.java b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/exception/TenantManagementException.java
new file mode 100644
index 0000000..1207f5d
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/exception/TenantManagementException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.exception;
+
+/**
+ * Tenant Management Specific Exception.
+ */
+public class TenantManagementException extends Exception {
+
+ public TenantManagementException(String msg, Exception e) {
+ super(msg, e);
+ }
+
+ public TenantManagementException(String msg) {
+ super(msg);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/ac065d73/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/internal/TenantMgtServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/internal/TenantMgtServiceComponent.java b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/internal/TenantMgtServiceComponent.java
new file mode 100644
index 0000000..a65d275
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/internal/TenantMgtServiceComponent.java
@@ -0,0 +1,261 @@
+/*
+* 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.apache.stratos.common.TenantBillingService;
+import org.apache.stratos.common.listeners.TenantMgtListener;
+import org.apache.stratos.common.util.CommonUtil;
+import org.apache.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.apache.stratos.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.apache.stratos.tenant.mgt.listener.service"
+ * interface="org.apache.stratos.common.listeners.TenantMgtListener"
+ * cardinality="0..n" policy="dynamic"
+ * bind="setTenantMgtListenerService"
+ * unbind="unsetTenantMgtListenerService"
+ * @scr.reference name="default.tenant.billing.service"
+ * interface="org.apache.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/src/main/java/org/apache/stratos/tenant/mgt/internal/util/TenantMgtRampartUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/internal/util/TenantMgtRampartUtil.java b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/internal/util/TenantMgtRampartUtil.java
new file mode 100644
index 0000000..7cc40c7
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/internal/util/TenantMgtRampartUtil.java
@@ -0,0 +1,48 @@
+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/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java
new file mode 100644
index 0000000..171f9a3
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/CloudWSRealmConfigBuilder.java
@@ -0,0 +1,138 @@
+/*
+* 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/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java
new file mode 100644
index 0000000..a213ee9
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/realm/IdaasWSRealmConfigBuilder.java
@@ -0,0 +1,87 @@
+/*
+* 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/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java
new file mode 100644
index 0000000..d011ec1
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/GAppTenantRegistrationService.java
@@ -0,0 +1,120 @@
+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.apache.stratos.common.beans.TenantInfoBean;
+import org.apache.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/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java
new file mode 100644
index 0000000..fec72a1
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/InMemoryPasswordcallbackHandler.java
@@ -0,0 +1,38 @@
+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/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java
new file mode 100644
index 0000000..664e31d
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/src/main/java/org/apache/stratos/tenant/mgt/services/TenantMgtAdminService.java
@@ -0,0 +1,496 @@
+/*
+ * 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.apache.stratos.common.beans.TenantInfoBean;
+import org.apache.stratos.common.exception.StratosException;
+import org.apache.stratos.common.util.ClaimsMgtUtil;
+import org.apache.stratos.common.util.CommonUtil;
+import org.apache.stratos.tenant.mgt.beans.PaginatedTenantInfoBean;
+import org.apache.stratos.tenant.mgt.core.internal.TenantMgtCoreServiceComponent;
+import org.apache.stratos.tenant.mgt.internal.TenantMgtServiceComponent;
+import org.apache.stratos.tenant.mgt.util.TenantMgtUtil;
+import org.wso2.carbon.user.core.UserRealm;
+import org.wso2.carbon.user.core.UserStoreException;
+import org.wso2.carbon.user.core.UserStoreManager;
+import org.wso2.carbon.user.core.tenant.Tenant;
+import org.wso2.carbon.user.core.tenant.TenantManager;
+import org.wso2.carbon.utils.DataPaginator;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+
+import org.apache.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);
+ }
+ }
+}