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:29 UTC

[1/7] Tenat-mgt refactoring

Updated Branches:
  refs/heads/master c1fffa70b -> 8c3796dcf


http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/select_domain.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/select_domain.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/select_domain.jsp
new file mode 100644
index 0000000..9adfe7f
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/select_domain.jsp
@@ -0,0 +1,389 @@
+<!--
+~ 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.
+-->
+<%@ page import="org.wso2.carbon.stratos.common.constants.StratosConstants" %>
+<%@ page import="org.wso2.carbon.stratos.common.util.CommonUtil" %>
+<%@ page import="org.wso2.carbon.register.ui.utils.TenantConfigUtil" %>
+<%@ page import="org.wso2.carbon.tenant.register.stub.beans.xsd.CaptchaInfoBean" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+<jsp:include page="../registry_common/registry_common-i18n-ajaxprocessor.jsp"/>
+<script type="text/javascript" src="../registry_common/js/registry_validation.js"></script>
+<script type="text/javascript" src="../registry_common/js/registry_common.js"></script>
+<script type="text/javascript" src="../ajax/js/prototype.js"></script>
+<script type="text/javascript" src="js/select_domain.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.form.js"></script>
+<script type="text/javascript" src="../dialog/js/jqueryui/jquery-ui.min.js"></script>
+<script type="text/javascript" src="../googleanalytics/js/googleAnalyticsProcessor.js"></script>
+<carbon:jsi18n
+        resourceBundle="org.wso2.carbon.register.ui.i18n.JSResources"
+        request="<%=request%>"/>
+<fmt:bundle basename="org.wso2.carbon.register.ui.i18n.Resources">
+
+<jsp:include page="../registry_common/registry_common-i18n-ajaxprocessor.jsp"/>
+<link href="../tenant-register/css/tenant-register.css" rel="stylesheet" type="text/css" media="all"/>
+<script type="text/javascript" src="js/register_config.js"></script>
+<script type="text/javascript">
+
+    var packageInfo;
+    
+    function setFreeUsagePlan() {
+        var foundFreePlan = false;
+        for (var i = 0; i < packageInfo.length; i++) {
+            if (packageInfo[i].subscriptionCharge == "0") {
+                document.getElementById("selectedUsagePlan").value = packageInfo[i].name;
+                foundFreePlan = true;
+                return;
+            }
+        }
+        if(!foundFreePlan) {
+            document.getElementById("selectedUsagePlan").value = packageInfo[0].name;
+        }
+    }
+
+    jQuery(document).ready(
+                          function() {
+                              jQuery.ajax({
+                                  type: 'POST',
+                                  url: 'get_package_info_ajaxprocessor.jsp',
+                                  dataType: 'json',
+                                  data: 'plan=0',
+                                  async: false,
+                                  success: function(data) {
+                                      packageInfo = data;
+                                  },
+                                  error:function (xhr, ajaxOptions, thrownError) {
+                                      CARBON.showErrorDialog('Could not get package information.');
+                                  }
+                              });
+
+                          }
+            );
+</script>
+
+
+<%
+    String domainName = "";
+    String admin = "";
+    String email = "";
+    String firstname = "";
+    String lastname = "";
+    String usagePlan = "";
+    String license = CommonUtil.getEula();
+    boolean isPublicCloud = CommonUtil.isPublicCloudSetup();
+
+    session.setAttribute(StratosConstants.ORIGINATED_SERVICE,
+            request.getParameter(StratosConstants.ORIGINATED_SERVICE));
+    String domain = (String) session.getAttribute("temp-domain-to-register");
+    if (domain == null) {
+        domain = "";
+    }
+    session.removeAttribute("temp-domain-to-register");
+    // hm, i'm not sure whether we really need to clear the success key, if someone in the same session
+    // have succeeded validating the domain, we should let them ignore the validation step. but if
+    // someone look at this without much investigation, he may think this is a bug, so thought of clearing
+    // it anyway...
+    session.removeAttribute("validate-domain-success-key");
+    if ("false".equals(session.getAttribute("temp-domain-available"))) {
+        session.removeAttribute("temp-domain-available");
+%>
+
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+        CARBON.showWarningDialog(jsi18n["domain.unavailable"]);
+    });
+</script>
+<%
+    }
+%>
+<link href="../tenant-register/css/tenant-register.css" rel="stylesheet" type="text/css" media="all"/>
+
+<%
+    CaptchaInfoBean captchaInfoBean;
+    try {
+        captchaInfoBean = TenantConfigUtil.generateRandomCaptcha(config, session);
+    } catch (Exception e) {
+        return;
+    }
+    String captchaImagePath = captchaInfoBean.getImagePath();
+
+    String captchaImageUrl = "../../" + captchaImagePath;
+    String captchaSecretKey = captchaInfoBean.getSecretKey();
+
+    if (session.getAttribute("submit-domain") != null) {
+        domain = (String) session.getAttribute("submit-domain");
+        session.setAttribute("submit-domain", null);
+    }
+    if (session.getAttribute("submit-admin") != null) {
+        admin = (String) session.getAttribute("submit-admin");
+        session.setAttribute("submit-admin", null);
+    }
+    if (session.getAttribute("submit-admin-email") != null) {
+        email = (String) session.getAttribute("submit-admin-email");
+        session.setAttribute("submit-admin-email", null);
+    }
+    if (session.getAttribute("submit-admin-firstname") != null) {
+        firstname = (String) session.getAttribute("submit-admin-firstname");
+        session.setAttribute("submit-admin-firstname", null);
+    }
+    if (session.getAttribute("submit-admin-lastname") != null) {
+        lastname = (String) session.getAttribute("submit-admin-lastname");
+        session.setAttribute("submit-admin-lastname", null);
+    }
+%>
+
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<%
+    if ("failed".equals(session.getAttribute("kaptcha-status"))) {
+        session.setAttribute("kaptcha-status", null);
+%>
+
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+        CARBON.showWarningDialog('Please enter the letters shown as in the image to register.');
+    });
+</script>
+<%
+    }
+
+    if ("true".equals(session.getAttribute("add-tenant-failed"))) {
+        session.removeAttribute("add-tenant-failed");
+%>
+
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+        CARBON.showWarningDialog('Organization registration failed. Please try again with a different domain.');
+    });
+</script>
+<%
+    }
+%>
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+
+        jQuery(".toggle_container").show();
+        /*Hide (Collapse) the toggle containers on load use show() instead of hide() in the
+         above code if you want to keep the content section expanded. */
+
+        jQuery("h2.trigger").click(function() {
+            if (jQuery(this).next().is(":visible")) {
+                this.className = "active trigger";
+            } else {
+                this.className = "trigger";
+            }
+
+            jQuery(this).next().slideToggle("fast");
+            return false; //Prevent the browser jump to the link anchor
+        });
+    });
+</script>
+<div id="middle">
+
+    <h2><fmt:message key="register.new.organization"/></h2>
+
+    <div id="workArea">
+        <div class="registration_help"><fmt:message key="required.msg"/></div>
+        <div id="activityReason" style="display: none;"></div>
+        <form id="addTenantForm" action="submit_tenant_ajaxprocessor.jsp" method="post">
+
+            <table class="styledLeft">
+                <tbody>
+                <tr>
+                    <td class="nopadding">
+                        <h2 class="trigger"><a href="#"><fmt:message key="domain.information"/></a></h2>
+
+                        <div class="toggle_container">
+                            <table class="normal-nopadding" cellspacing="0">
+                                <tbody>
+                                <tr>
+                                    <td class="leftCol-med"><fmt:message key="domain"/><span class="required">*</span>
+                                    </td>
+                                    <td colspan="2"><input onblur="fillAdminValue()"
+                                                           value="<%=domain%>" type="text"
+                                                           name="domain" id="domain"
+                                                           style="width:400px" value=""/>
+                                        <input type="button" value="Check Availability"
+                                               onclick="checkDomainAvailability(<%=isPublicCloud?"true":"false"%>)"/> <span
+                                                id="busyCheck"></span>
+                                    </td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2">Provide a domain for your tenant, in the
+                                        format "example.com". This domain should be unique.
+                                        If this is a legitimate domain, optionally you will be able to validate the ownership of the domain.
+                                    </td>
+                                </tr>
+
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2">
+                                        <div id="domain-confirmation-msg"></div>
+                                    </td>
+                                </tr>
+
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2">
+                                        <input type="checkbox" name="domain-confirmation"
+                                               value="yes">Validate the domain now
+                                        (optional)</input>
+                                    </td>
+                                </tr>
+
+                                </tbody>
+                            </table>
+                        </div>
+
+                        <h2 class="trigger"><a href="#"><fmt:message key="contact.details"/></a></h2>
+
+                        <div class="toggle_container">
+                            <table class="normal-nopadding" cellspacing="0">
+                                <tbody>
+                                <tr>
+                                    <td class="leftCol-med"><fmt:message key="admin.firstname"/><span
+                                            class="required">*</span></td>
+                                    <td><input type="text" name="admin-firstname" id="admin-firstname"
+                                               style="width:400px" value="<%=firstname%>"/></td>
+                                </tr>
+                                <tr>
+                                    <td><fmt:message key="admin.lastname"/><span class="required">*</span></td>
+                                    <td><input type="text" name="admin-lastname" id="admin-lastname" style="width:400px"
+                                               value="<%=lastname%>"/></td>
+                                </tr>
+                                <tr>
+                                    <td><fmt:message key="admin.username"/><span class="required">*</span></td>
+                                    <td><input type="text" name="admin" id="admin" style="width:400px"
+                                               value="<%=admin%>"/><span id="adminValue"></span></td>
+                                </tr>
+                                <tr>
+                                    <td><fmt:message key="admin.password"/>
+                                        <span class="required">*</span></td>
+                                    <td><input type="password" name="admin-password" id="admin-password"
+                                               style="width:400px"/></td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td class="registration_help">(Minimum of 6 Characters in length)</td>
+                                </tr>
+                                <tr>
+                                    <td><fmt:message key="admin.password.repeat"/>
+                                        <span class="required">*</span></td>
+                                    <td><input type="password" name="admin-password-repeat" id="admin-password-repeat"
+                                               style="width:400px"/></td>
+                                </tr>
+                                <tr>
+                                    <td class="leftCol-med"><fmt:message key="admin.email"/><span
+                                            class="required">*</span></td>
+                                    <td colspan="2"><input type="text" name="admin-email" id="admin-email"
+                                                           style="width:400px" value="<%=email%>"/></td>
+                                </tr>
+                                <tr>
+                                    <td class="leftCol-med"><fmt:message key="word.verification"/><span
+                                            class="required">*</span></td>
+                                    <td colspan="2"><fmt:message key="captcha.message"/></td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2">
+                                        <div id="kaptchaImgDiv"></div>
+                                    </td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2" height="100"><input type="text" id="captcha-user-answer"
+                                                                        name="captcha-user-answer" style="width:400px"
+                                                                        value=""/></td>
+                                </tr>
+                                </tbody>
+                            </table>
+                        </div>
+
+                        <%
+                            if (isPublicCloud) {
+                        %>
+                        <h2 class="trigger"><a href="#"><fmt:message key="terms.of.use"/></a></h2>
+
+                        <div class="toggle_container">
+                            <table class="normal-nopadding" cellspacing="0">
+                                <tbody>
+
+
+                                <tr></tr>
+                                <tr>
+                                    <td>
+                                        <textarea rows="10" readonly="readonly" name="license-text"
+                                                  style="width:100%"><%=license%>
+                                        </textarea>
+                                    </td>
+                                </tr>
+                                <tr>
+                                    <td><input type="checkbox" name="activateButton" id="activateButton"
+                                               onclick="activateSubmit(form.activateButton.checked)"/>
+                                        <label for="activateButton"><fmt:message key="accept.eula"/></label></td>
+                                </tr>
+                                <%
+                                    }
+                                %>
+
+
+                                </tbody>
+                            </table>
+                        </div>
+                    </td>
+                </tr>
+                <tr id="buttonRow" colspan="2">
+                    <td class="buttonRow">
+                        <input type="hidden" name="selectedUsagePlan" id="selectedUsagePlan"/>
+                        <input type="hidden" name="captcha-secret-key" value="<%=captchaSecretKey%>"/>
+                        <%
+                            if (isPublicCloud) {
+                        %>
+                        <input class="button" id="submit-button" type="button" disabled="disabled" style="float:left; margin-top:4px"
+                               value="Next >" onclick="setFreeUsagePlan();addTenant();jQuery(this).attr('disabled', true);jQuery('#waitMessage').toggle('fast')"/>
+                        <%
+                        } else {
+                        %>
+                        <input class="button" id="submit-button" type="button" style="float:left; margin-top:4px"
+                               value="Next >" onclick="setFreeUsagePlan();addTenant();jQuery(this).attr('disabled', true);jQuery('#waitMessage').toggle('fast')"/>
+                        <%
+                            }
+                        %>
+                        <div id="waitMessage" style="font-size:13px !important;margin-top:5px; float:left;display:none"><img
+                                src="images/ajax-loader.gif" align="left" hspace="20"/>Registering new tenant ...
+                        </div>
+                        <div style="clear:both"></div>
+                    </td>
+                </tr>
+                </tbody>
+            </table>
+        </form>
+        <br/>
+    </div>
+</div>
+<script type="text/javascript">
+    showKaptcha('<%=captchaImageUrl%>');
+</script>
+</fmt:bundle>
+
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/select_usage_plan.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/select_usage_plan.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/select_usage_plan.jsp
new file mode 100644
index 0000000..3425d00
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/select_usage_plan.jsp
@@ -0,0 +1,279 @@
+<!--
+~ 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.
+-->
+<%@ page import="org.wso2.carbon.stratos.common.constants.StratosConstants" %>
+<%@ page import="org.wso2.carbon.stratos.common.util.CommonUtil" %>
+<%@ page import="org.wso2.carbon.register.ui.utils.TenantConfigUtil" %>
+<%@ page import="org.wso2.carbon.tenant.register.stub.beans.xsd.CaptchaInfoBean" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+<jsp:include page="../registry_common/registry_common-i18n-ajaxprocessor.jsp"/>
+<script type="text/javascript" src="../registry_common/js/registry_validation.js"></script>
+<script type="text/javascript" src="../registry_common/js/registry_common.js"></script>
+<script type="text/javascript" src="../ajax/js/prototype.js"></script>
+<script type="text/javascript" src="js/select_domain.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.form.js"></script>
+<script type="text/javascript" src="../dialog/js/jqueryui/jquery-ui.min.js"></script>
+<script type="text/javascript" src="../googleanalytics/js/googleAnalyticsProcessor.js"></script>
+<carbon:jsi18n
+        resourceBundle="org.wso2.carbon.register.ui.i18n.JSResources"
+        request="<%=request%>"/>
+<fmt:bundle basename="org.wso2.carbon.register.ui.i18n.Resources">
+
+<jsp:include page="../registry_common/registry_common-i18n-ajaxprocessor.jsp"/>
+<link href="../tenant-register/css/tenant-register.css" rel="stylesheet" type="text/css" media="all"/>
+<script type="text/javascript" src="js/register_config.js"></script>
+<script type="text/javascript">
+
+<%
+    boolean chargeOnRegistration = CommonUtil.isChargedOnRegistration();
+    String regDomain = (String)session.getAttribute("regTenantDomain");
+%>
+    var packageInfo;
+    function showRentalMessage() {
+
+        if (packageInfo == null) {
+            jQuery.ajax({
+                type: 'POST',
+                url: 'get_package_info_ajaxprocessor.jsp',
+                dataType: 'json',
+                data: 'plan=0',
+                async: false,
+                success: function(data) {
+                    packageInfo = data;
+                },
+                error:function (xhr, ajaxOptions, thrownError) {
+                    CARBON.showErrorDialog('Could not get package information.');
+                }
+            });
+        }
+
+        var plan = document.getElementById('selectedUsagePlan').
+                options[document.getElementById('selectedUsagePlan').selectedIndex].value;
+        var charge;
+        for (var i = 0; i < packageInfo.length; i++) {
+            if (packageInfo[i].name == plan) {
+                charge = packageInfo[i].subscriptionCharge;
+                break;
+            }
+
+        }
+
+        document.getElementById('packagePrice').innerHTML = '<b>' + '<fmt:message key="billing.currency"/>' + charge + " per month" + '</b>';
+
+    }
+
+    function makePayment() {
+        var selectEl = document.getElementById("selectedUsagePlan");
+        var selectedUsagePlan = selectEl.options[selectEl.selectedIndex].value;
+        var regTenantDomain = '<%= regDomain%>';
+
+
+        for (var i = 0; i < packageInfo.length; i++) {
+        <% if (chargeOnRegistration) { %>
+            if (packageInfo[i].name == selectedUsagePlan && packageInfo[i].subscriptionCharge != "0") {
+                CARBON.showConfirmationDialog('<fmt:message key="redirect.to.paypal.msg1"/>' + " " + '<fmt:message key="billing.currency"/>' + packageInfo[i].subscriptionCharge +
+                                              ". " + '<fmt:message key="redirect.to.paypal.msg2"/>', function() {
+                    document.getElementById('waitMessage').style.display = 'block';
+                    document.forms["selectUsagePlan"].submit();
+                }, function () {
+                    document.getElementById('submit-button').removeAttribute('disabled');
+                })
+
+            } else if (packageInfo[i].name == selectedUsagePlan && packageInfo[i].subscriptionCharge == "0") {
+                location.href = "../tenant-register/success_register.jsp";
+                break;
+            }
+            <% } else { %>
+                if(packageInfo[i].name == selectedUsagePlan && packageInfo[i].subscriptionCharge != "0") {
+                    jQuery.ajax({
+                        type: 'POST',
+                        url: '../payment/upgrade_registration_usage_plan_ajaxprocessor.jsp',
+                        data: {selectedUsagePlan: selectedUsagePlan, regTenantDomain: regTenantDomain},
+                        async: false,
+                        success: function(msg) {
+                    }});
+                    location.href = "../tenant-register/success_register.jsp";
+                    break;
+                } else if (packageInfo[i].name == selectedUsagePlan && packageInfo[i].subscriptionCharge == "0") {
+                    location.href = "../tenant-register/success_register.jsp";
+                    break;
+                }
+        <% } %>
+
+        }
+    }
+
+    function cancelPaymet() {
+        location.href = "../tenant-register/success_register.jsp";
+    }
+
+    jQuery(document).ready(
+                          function() {
+                              jQuery.ajax({
+                                  type: 'POST',
+                                  url: 'get_package_info_ajaxprocessor.jsp',
+                                  dataType: 'json',
+                                  data: 'plan=0',
+                                  async: false,
+                                  success: function(data) {
+                                      packageInfo = data;
+                                  },
+                                  error:function (xhr, ajaxOptions, thrownError) {
+                                      CARBON.showErrorDialog('Could not get package information.');
+                                  }
+                              });
+
+                              var charge;
+                              var name;
+                              for (var i = 0; i < packageInfo.length; i++) {
+                                  charge = packageInfo[i].subscriptionCharge;
+                                  name = packageInfo[i].name;
+                                  option = document.createElement("option");
+                                  option.value = name;
+                                  option.innerHTML = name;
+                                  document.getElementById('selectedUsagePlan').appendChild(option);
+
+                              }
+                          }
+            );
+</script>
+
+
+<%
+    boolean isPublicCloud = CommonUtil.isPublicCloudSetup();
+
+    session.setAttribute(StratosConstants.ORIGINATED_SERVICE,
+            request.getParameter(StratosConstants.ORIGINATED_SERVICE));
+    String domain = (String) session.getAttribute("temp-domain-to-register");
+    if (domain == null) {
+        domain = "";
+    }
+    session.removeAttribute("temp-domain-to-register");
+    // hm, i'm not sure whether we really need to clear the success key, if someone in the same session
+    // have succeeded validating the domain, we should let them ignore the validation step. but if
+    // someone look at this without much investigation, he may think this is a bug, so thought of clearing
+    // it anyway...
+    session.removeAttribute("validate-domain-success-key");
+    if ("false".equals(session.getAttribute("temp-domain-available"))) {
+        session.removeAttribute("temp-domain-available");
+%>
+
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+        CARBON.showWarningDialog(jsi18n["domain.unavailable"]);
+    });
+</script>
+<%
+    }
+%>
+<link href="../tenant-register/css/tenant-register.css" rel="stylesheet" type="text/css" media="all"/>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+
+        jQuery(".toggle_container").show();
+        /*Hide (Collapse) the toggle containers on load use show() instead of hide() in the
+         above code if you want to keep the content section expanded. */
+
+        jQuery("h2.trigger").click(function() {
+            if (jQuery(this).next().is(":visible")) {
+                this.className = "active trigger";
+            } else {
+                this.className = "trigger";
+            }
+
+            jQuery(this).next().slideToggle("fast");
+            return false; //Prevent the browser jump to the link anchor
+        });
+    });
+
+</script>
+<div id="middle">
+
+    <h2><fmt:message key="register.new.organization"/></h2>
+
+    <div id="workArea">
+        <div class="registration_help"><fmt:message key="required.msg"/></div>
+        <div id="activityReason" style="display: none;"></div>
+        <form id="selectUsagePlan" action="init_payment_ajaxprocessor.jsp" method="post">
+
+            <table class="styledLeft">
+                <tbody>
+                <tr>
+                    <td class="nopadding">
+                        <h2 class="trigger"><a href="#"><fmt:message key="usage.plan.information"/></a></h2>
+
+                        <div class="toggle_container">
+                            <table class="normal-nopadding" cellspacing="0">
+                                <tbody>
+                                <tr>
+                                    <td class="leftCol-med">
+                                        <fmt:message key="select.usage.plan.for.tenant"/><span class="required">*</span>
+                                    </td>
+                                    <td colspan="2">
+                                        <select name="selectedUsagePlan" id="selectedUsagePlan"
+                                                onchange="showRentalMessage();">
+                                        </select>
+                                        <a href="<%=CommonUtil.getStratosConfig().getUsagePlanURL()%>" target="_blank">
+                                            <b>Pricing Info</b>
+                                        </a>
+                                    </td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2" id="packagePrice" class="registration_help"><b><fmt:message
+                                            key="demo.package.price"/></b></td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2" class="registration_help"><fmt:message
+                                            key="select.package.message"/>
+                                    </td>
+                                </tr>
+                                </tbody>
+                            </table>
+                        </div>                        
+                    </td>
+                </tr>
+                <tr id="buttonRow">
+                    <td class="buttonRow">
+                        <input class="button" id="submit-button" type="button" style="float:left; margin-top:4px; margin-right:4px;"
+                               value="Submit" onclick="makePayment();jQuery(this).attr('disabled', true)"/>
+                        <input class="button" id="cancel-button" type="button" style="float:left; margin-top:4px"
+                               value="Cancel" onclick="cancelPaymet()"/>
+                        <div id="waitMessage" style="font-size:13px !important;margin-top:5px; float:left; display:none"><img
+                                src="images/ajax-loader.gif" align="left" hspace="20"/>Connecting to PayPal ...
+                        </div>
+                        <div style="clear:both"></div>
+                    </td>
+                </tr>
+                </tbody>
+            </table>
+        </form>
+        <br/>
+    </div>
+</div>
+</fmt:bundle>
+
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/submit_tenant_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/submit_tenant_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/submit_tenant_ajaxprocessor.jsp
new file mode 100644
index 0000000..e6059f1
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/submit_tenant_ajaxprocessor.jsp
@@ -0,0 +1,66 @@
+<!--
+ ~ 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.
+ -->
+<%@ page import="org.wso2.carbon.register.ui.utils.TenantConfigUtil" %>
+<%@ page import="org.wso2.carbon.stratos.common.constants.StratosConstants"%>
+<%@ page import="org.wso2.carbon.captcha.mgt.constants.CaptchaMgtConstants"%>
+<%@ page import="org.wso2.carbon.utils.multitenancy.MultitenantConstants" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+<carbon:jsi18n
+		resourceBundle="org.wso2.carbon.register.ui.i18n.JSResources"
+		request="<%=request%>" />
+<%
+
+    try {
+        String gotoConfirmDomain = request.getParameter("domain-confirmation");
+        String domain = request.getParameter("domain");
+
+        String key = TenantConfigUtil.registerTenantConfigBean(request, config, session);
+
+        session.removeAttribute(StratosConstants.ORIGINATED_SERVICE);
+        session.setAttribute("add-tenant-success", "true");
+        session.setAttribute("regTenantDomain", domain);
+
+        String contextPath = "/" + MultitenantConstants.TENANT_AWARE_URL_PREFIX + "/" + request.getParameter("domain");
+        //response.sendRedirect(contextPath + "/carbon/tenant-theme/theme_mgt.jsp?redirectWith=" + key);
+        // now we send the login page.
+
+       // response.sendRedirect(contextPath + "/carbon/admin/login.jsp");
+
+        if (gotoConfirmDomain != null && gotoConfirmDomain.equals("yes")) {
+            // send me to the domain validation form
+            response.sendRedirect("../validate-domain/validate_domain_not_logged_in.jsp?domain=" + domain);
+        }
+        else {
+            // send me direct to the add tenant form, without successkey they will add the suffix -unverified
+            response.sendRedirect("../tenant-register/select_usage_plan.jsp");
+        }
+
+    } catch (Exception e) {
+        String msg = e.getMessage();
+        TenantConfigUtil.setSubmissionValuesForSession(request);
+        if (msg.contains(CaptchaMgtConstants.CAPTCHA_ERROR_MSG)) {
+            session.setAttribute("kaptcha-status", "failed");
+        } else {
+        session.setAttribute("add-tenant-failed", "true");
+        }
+        response.sendRedirect("../tenant-register/select_domain.jsp");
+        return;
+    }
+%>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/success_register.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/success_register.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/success_register.jsp
new file mode 100644
index 0000000..dc60f1b
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/success_register.jsp
@@ -0,0 +1,77 @@
+<!--
+~ 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.
+-->
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<link href="css/tenant-register.css" rel="stylesheet" type="text/css" media="all"/>
+
+<%
+    // String contextPath = "/" + MultitenantConstants.TENANT_AWARE_URL_PREFIX + "/" + request.getParameter("domain");
+%>
+<div id="middle">
+
+    <h2>
+        Account Created Successfully
+    </h2>
+
+    <div id="workArea">
+
+       <h3>Congratulations! You have successfully created an account for your organization with WSO2 Stratos. </h3>
+
+        <p style="font-size:16px" align="left">
+        A confirmation email has been sent to your email address for this account. Please follow the instructions in the email to activate the account.
+        After that login from the <a href="/carbon/admin/login.jsp"> <b>login page</b></a>.
+        </p>
+    </div>
+
+
+    <div class="clear"></div>
+    <div class="features">
+        <div class="feature">
+            <img src="images/feature-01-icon.gif"/>
+
+            <h2>Elasticity</h2>
+
+            <p>
+                Stratos manages your underlying cloud infrastructure to seamlessly handle the scalability demands of
+                your application.
+            </p>
+        </div>
+        <div class="feature">
+            <img src="images/feature-02-icon.gif"/>
+
+            <h2>Multi-tenancy</h2>
+
+            <p>
+                Departments, developer groups, or projects run fully independently, but share the same middleware
+                platform for maximum resource utilization.
+            </p>
+        </div>
+        <div class="feature">
+            <img src="images/feature-03-icon.gif"/>
+
+            <h2>Self Provisioning</h2>
+
+            <p>
+                Authorized users can provision new tenants from a web portal in moments.
+            </p>
+        </div>
+        <div class="clear"></div>
+    </div>
+
+
+


[7/7] git commit: Tenat-mgt refactoring

Posted by is...@apache.org.
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>


[4/7] Tenat-mgt refactoring

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

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/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
new file mode 100644
index 0000000..f640c65
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantRegistryDataDeletionUtil.java
@@ -0,0 +1,119 @@
+/*
+*  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/8c3796dc/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
new file mode 100644
index 0000000..d857e38
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/util/TenantUMDataDeletionUtil.java
@@ -0,0 +1,112 @@
+/*
+*  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/8c3796dc/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
new file mode 100644
index 0000000..883930f
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/resources/META-INF/component.xml
@@ -0,0 +1,41 @@
+<?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/8c3796dc/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
new file mode 100644
index 0000000..7e87c44
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/resources/META-INF/services.xml
@@ -0,0 +1,155 @@
+<?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/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/pom.xml b/components/org.apache.stratos.tenant.registration.ui/2.1.0/pom.xml
new file mode 100644
index 0000000..d37932f
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/pom.xml
@@ -0,0 +1,123 @@
+<?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.wso2.carbon</groupId>
+        <artifactId>tenant-mgt-parent</artifactId>
+        <version>2.1.0</version>
+<relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>org.wso2.carbon.register.ui</artifactId>
+	<version>2.1.0</version>
+    <packaging>bundle</packaging>
+    <name>WSO2 Stratos - Self Registration For New Tenant - User Interface</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.wso2.carbon.register.ui.*,
+                        </Export-Package>
+                        <Import-Package>
+                        	org.wso2.carbon.tenant.register.stub.*; version="${carbon.platform.package.import.version.range}"
+                            javax.servlet;version="${imp.pkg.version.javax.servlet}",
+                            javax.servlet.http;version="${imp.pkg.version.javax.servlet}",
+                            !javax.xml.namespace,
+                            javax.xml.namespace; version=0.0.0,                            
+                            org.apache.lucene.*,
+                            org.wso2.carbon.captcha.mgt.*,
+                            *;resolution:=optional
+                        </Import-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>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.registry.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.equinox</groupId>
+            <artifactId>javax.servlet</artifactId>
+            <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>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.ui</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.core</artifactId>
+        </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.tenant.register.stub</artifactId>
+        </dependency>
+         <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.stratos.common.stub</artifactId>
+        </dependency>
+        <dependency>
+          <groupId>org.json.wso2</groupId>
+          <artifactId>json</artifactId>
+        </dependency>
+        <dependency>
+           <groupId>org.wso2.carbon</groupId>
+           <artifactId>org.wso2.carbon.captcha.mgt</artifactId>
+            <version>${wso2carbon.version}</version>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/clients/PackageInfoServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/clients/PackageInfoServiceClient.java b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/clients/PackageInfoServiceClient.java
new file mode 100644
index 0000000..8fc3195
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/clients/PackageInfoServiceClient.java
@@ -0,0 +1,77 @@
+package org.wso2.carbon.register.ui.clients;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.stratos.common.packages.stub.PackageInfoServiceStub;
+import org.wso2.carbon.stratos.common.packages.stub.PackageInfo;
+
+/**
+ * PackageInfoService client
+ */
+public class PackageInfoServiceClient {
+
+    private static Log log = LogFactory.getLog(PackageInfoServiceClient.class);
+
+    private PackageInfoServiceStub stub;
+    private String epr;
+
+    public PackageInfoServiceClient(
+            String cookie, String backendServerURL, ConfigurationContext configContext)
+            throws Exception {
+
+        epr = backendServerURL + "PackageInfoService";
+
+        try {
+            stub = new PackageInfoServiceStub(configContext, epr);
+
+            ServiceClient client = stub._getServiceClient();
+            Options option = client.getOptions();
+            option.setManageSession(true);
+            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate PackageInfoService client. " + axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new RegistryException(msg, axisFault);
+        }
+    }
+
+    public PackageInfo[] getBillingPackages() throws Exception {
+
+        try {
+            return stub.getPackageInfos();
+        } catch (Exception e) {
+            String msg = "Failed to get package information: " + e.getMessage();
+            log.error(msg, e);
+            throw new Exception(msg, e);
+        }
+    }
+
+    public JSONArray getBillingPackagesJsonArray() throws Exception {
+
+        try {
+            PackageInfo[] packageInfoArray = stub.getPackageInfos();
+            JSONArray jsonPackageInfoArray = new JSONArray();
+            for (PackageInfo packageInfo : packageInfoArray) {
+                JSONObject packageInfoObj = new JSONObject();
+                packageInfoObj.put("name", packageInfo.getName());
+                //TODO https://wso2.org/jira/browse/STRATOS-1819
+                packageInfoObj.put("subscriptionCharge", packageInfo.getSubscriptionCharge());
+                jsonPackageInfoArray.put(packageInfoObj);
+            }
+            return jsonPackageInfoArray;
+        } catch (Exception e) {
+            String msg = "Failed to get package information: " + e.getMessage();
+            log.error(msg, e);
+            throw new Exception(msg, e);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/clients/TenantSelfRegistrationClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/clients/TenantSelfRegistrationClient.java b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/clients/TenantSelfRegistrationClient.java
new file mode 100644
index 0000000..7eb58e4
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/clients/TenantSelfRegistrationClient.java
@@ -0,0 +1,107 @@
+/*
+*  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.wso2.carbon.register.ui.clients;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.CarbonConstants;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.tenant.register.stub.TenantMgtServiceStub;
+import org.wso2.carbon.tenant.register.stub.beans.xsd.CaptchaInfoBean;
+import org.wso2.carbon.tenant.register.stub.beans.xsd.TenantInfoBean;
+import org.wso2.carbon.ui.CarbonUIUtil;
+import org.wso2.carbon.utils.ServerConstants;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpSession;
+
+/**
+ * Tenant Self Registration Client class
+ */
+public class TenantSelfRegistrationClient {
+     private static final Log log = LogFactory.getLog(TenantSelfRegistrationClient.class);
+
+    private TenantMgtServiceStub stub;
+    private String epr;
+
+    public TenantSelfRegistrationClient(
+            String cookie, String backendServerURL, ConfigurationContext configContext)
+            throws RegistryException {
+
+        epr = backendServerURL + "TenantMgtService";
+
+        try {
+            stub = new TenantMgtServiceStub(configContext, epr);
+
+            ServiceClient client = stub._getServiceClient();
+            Options option = client.getOptions();
+            option.setManageSession(true);
+            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate AddServices service client. " + axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new RegistryException(msg, axisFault);
+        }
+    }
+
+    public TenantSelfRegistrationClient(ServletConfig config, HttpSession session)
+            throws RegistryException {
+
+        String cookie = (String)session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
+        String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
+        ConfigurationContext configContext = (ConfigurationContext) config.
+                getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
+        epr = backendServerURL + "TenantMgtService";
+
+        try {
+            stub = new TenantMgtServiceStub(configContext, epr);
+
+            ServiceClient client = stub._getServiceClient();
+            Options option = client.getOptions();
+            option.setManageSession(true);
+            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate Add Services service client. " + axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new RegistryException(msg, axisFault);
+        }
+    }
+
+    public String registerTenant(TenantInfoBean tenantInfoBean,
+                                 CaptchaInfoBean captchaInfoBean) throws Exception {
+        return stub.registerTenant(tenantInfoBean, captchaInfoBean);
+     }
+
+    public boolean checkDomainAvailability(String domainName) throws Exception {
+        return stub.checkDomainAvailability(domainName);
+    }
+
+    public String validateOrSuggestDomain(String domainName, String successKey) throws Exception {
+        return stub.validateOrSuggestDomain(domainName, successKey);
+    }
+
+    public CaptchaInfoBean generateRandomCaptcha() throws Exception {
+        return stub.generateRandomCaptcha();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/utils/TenantConfigUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/utils/TenantConfigUtil.java b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/utils/TenantConfigUtil.java
new file mode 100644
index 0000000..fc08c7b
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/java/org/wso2/carbon/register/ui/utils/TenantConfigUtil.java
@@ -0,0 +1,248 @@
+/*
+ *  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.wso2.carbon.register.ui.utils;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.util.Base64;
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.stratos.common.constants.StratosConstants;
+import org.wso2.carbon.register.ui.clients.TenantSelfRegistrationClient;
+import org.wso2.carbon.registry.common.ui.UIException;
+import org.wso2.carbon.tenant.register.stub.beans.xsd.CaptchaInfoBean;
+import org.wso2.carbon.tenant.register.stub.beans.xsd.TenantInfoBean;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import java.io.StringReader;
+import java.util.Calendar;
+import java.util.Iterator;
+
+/**
+ * Utility methods for tenant configuration
+ */
+public class TenantConfigUtil {
+    private static final Log log = LogFactory.getLog(TenantConfigUtil.class);
+
+    /**
+     * Registers the tenant
+     *
+     * @param request HttpServletRequest
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @return String
+     * @throws UIException
+     */
+    public static String registerTenantConfigBean(HttpServletRequest request,
+                                                  ServletConfig config, HttpSession session) throws UIException {
+        TenantInfoBean tenantInfoBean = new TenantInfoBean();
+        CaptchaInfoBean captchaInfoBean = new CaptchaInfoBean();
+
+        try {
+            // filling tenant info.
+            tenantInfoBean.setFirstname(request.getParameter("admin-firstname"));
+            tenantInfoBean.setLastname(request.getParameter("admin-lastname"));
+            tenantInfoBean.setAdmin(request.getParameter("admin"));
+            tenantInfoBean.setAdminPassword(request.getParameter("admin-password"));
+            tenantInfoBean.setTenantDomain(resolveDomainName(request.getParameter("domain")));
+            tenantInfoBean.setEmail(request.getParameter("admin-email"));
+            tenantInfoBean.setSuccessKey((String) session.getAttribute("validate-domain-success-key"));
+            tenantInfoBean.setUsagePlan(request.getParameter("selectedUsagePlan"));
+            tenantInfoBean.setOriginatedService(TenantConfigUtil.base64Decode((String) session.getAttribute(
+                    StratosConstants.ORIGINATED_SERVICE)));
+            tenantInfoBean.setCreatedDate(Calendar.getInstance());
+            // filling captcha info
+            captchaInfoBean.setSecretKey(request.getParameter("captcha-secret-key"));
+            captchaInfoBean.setUserAnswer(request.getParameter("captcha-user-answer"));
+
+            TenantSelfRegistrationClient selfRegistrationClient =
+                    new TenantSelfRegistrationClient(config, session);
+
+            String returnText = selfRegistrationClient.registerTenant(tenantInfoBean, captchaInfoBean);
+
+            return returnText;
+
+        } catch (Exception e) {
+            AxisFault fault = new AxisFault(e.getMessage());
+            String msg = fault.getReason() + " Failed to add tenant config. tenant-domain: " +
+                    tenantInfoBean.getTenantDomain() + ", " +
+                    "tenant-admin: " + tenantInfoBean.getAdmin() + ".";
+            log.error(msg, e);
+            // we are preserving the original message.
+            throw new UIException(e.getMessage(), e);
+        }
+    }
+
+
+    // do this before the send redirect.
+
+    public static void setSubmissionValuesForSession(HttpServletRequest request) {
+        HttpSession session = request.getSession();
+
+        session.setAttribute("submit-domain", resolveDomainName(request.getParameter("domain")));
+        session.setAttribute("submit-admin", request.getParameter("admin"));
+        session.setAttribute("submit-admin-firstname", request.getParameter("admin-firstname"));
+        session.setAttribute("submit-admin-lastname", request.getParameter("admin-lastname"));
+        session.setAttribute("submit-admin-email", request.getParameter("admin-email"));
+    }
+
+
+    /**
+     * Checks the availability of the domain
+     *
+     * @param request HttpServletRequest
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @return true, if domain is available to register
+     * @throws UIException if failed to check the availability.
+     */
+    public static boolean checkDomainAvailability(
+            HttpServletRequest request, ServletConfig config, HttpSession session)
+            throws UIException {
+        String tenantDomain = null;
+        try {
+            tenantDomain = resolveDomainName(request.getParameter("domain"));
+            TenantSelfRegistrationClient selfRegistrationClient =
+                    new TenantSelfRegistrationClient(config, session);
+            return selfRegistrationClient.checkDomainAvailability(tenantDomain);
+        } catch (Exception e) {
+            String msg = "Failed to check the domain availability:" + tenantDomain + ".";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+
+    /**
+     * Validates or suggests the domain
+     *
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @return domain
+     * @throws UIException, if validating or suggesting the domain failed.
+     */
+    public static String validateOrSuggestDomain(ServletConfig config,
+                                                 HttpSession session) throws UIException {
+        String tempDomainToRegister = resolveDomainName(
+                (String) session.getAttribute("temp-domain-to-register"));
+        // here successKey can be null, in such cases services will directly go to suggest a name
+        String successKey = (String) session.getAttribute("validate-domain-success-key");
+
+        try {
+            TenantSelfRegistrationClient selfRegistrationClient =
+                    new TenantSelfRegistrationClient(config, session);
+            return selfRegistrationClient.validateOrSuggestDomain(tempDomainToRegister, successKey);
+        } catch (Exception e) {
+            String msg = "Failed to validate or suggest a domain related to :" +
+                    tempDomainToRegister + ".";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+
+    /**
+     * Generates a random captcha
+     *
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @return CaptchaInfoBean
+     * @throws UIException, if generating the random captcha fails.
+     */
+    public static CaptchaInfoBean generateRandomCaptcha(ServletConfig config,
+                                                        HttpSession session) throws UIException {
+        try {
+            TenantSelfRegistrationClient selfRegistrationClient =
+                    new TenantSelfRegistrationClient(config, session);
+            return selfRegistrationClient.generateRandomCaptcha();
+        } catch (Exception e) {
+            String msg = "Error in generating the captcha image.";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+
+    public static HttpServletRequest readIntermediateData(HttpServletRequest request, String data) {
+        try {
+            XMLStreamReader parser =
+                    XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(data));
+            StAXOMBuilder builder = new StAXOMBuilder(parser);
+            OMElement documentElement = builder.getDocumentElement();
+            Iterator it = documentElement.getChildElements();
+            while (it.hasNext()) {
+                OMElement element = (OMElement) it.next();
+                if ("admin".equals(element.getLocalName())) {
+                    request.setAttribute("admin", element.getText());
+                } else if ("firstname".equals(element.getText())) {
+                    request.setAttribute("firstname", element.getText());
+                } else if ("lastname".equals(element.getText())) {
+                    request.setAttribute("lastname", element.getText());
+                } else if ("email".equals(element.getLocalName())) {
+                    request.setAttribute("email", element.getText());
+                } else if ("tenantDomain".equals(element.getLocalName())) {
+                    request.setAttribute("tenantDomain", element.getText());
+                } else if ("confirmationKey".equals(element.getLocalName())) {
+                    request.setAttribute("confirmationKey", element.getText());
+                }
+            }
+        } catch (Exception e) {
+            log.error("Error parsing xml", e);
+        }
+        return request;
+    }
+
+    /**
+     * Resolves the correct domain name in the form of example.com from the user input domain name.
+     * Currently strips out "www."and white space. Can add more checks.
+     *
+     * @param domainNameUserInput the user input domain name
+     * @return the domain after removing (if entered) www. from the input.
+     */
+    public static String resolveDomainName(String domainNameUserInput) {
+        if (domainNameUserInput == null) {
+            String msg = "Provided domain name is null";
+            log.error(msg);
+            return "";
+        }
+        String domainName = domainNameUserInput.trim();
+        if (domainName.startsWith("www.")) {
+            domainName = domainName.substring(4);
+        }
+        return domainName;
+    }
+
+    /**
+     * A basic method to decode the encoded Stratos Service Name
+     *
+     * @param encodedStr Encoded Stratos Service Name
+     * @return Decoded Stratos Service name
+     */
+    private static String base64Decode(String encodedStr) {
+        String decodedStr = null;
+        // Check whether this value is null(not set) or set to "null" which is also possible.
+        if (encodedStr != null && !"null".equals(encodedStr)) {
+            decodedStr = new String(Base64.decode(encodedStr));
+        }
+        return decodedStr;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/META-INF/component.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/META-INF/component.xml b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/META-INF/component.xml
new file mode 100644
index 0000000..aa11e6b
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/META-INF/component.xml
@@ -0,0 +1,70 @@
+<!--
+ ~ 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.
+ -->
+<component xmlns="http://products.wso2.org/carbon">
+    <!-- sample menu configuration -->
+    <menus>
+        <menu>
+            <id>gaas_menu</id>
+            <i18n-key>gaas</i18n-key>
+            <i18n-bundle>org.wso2.carbon.register.ui.i18n.Resources</i18n-bundle>
+            <parent-menu></parent-menu>
+            <link>#</link>
+            <skip-authentication/>
+            <region>region1</region>
+            <order>2</order>
+            <style-class>home</style-class>
+        </menu>
+        <menu>
+            <id>gaas_register_org_menu</id>
+            <i18n-key>register.org.menu</i18n-key>
+            <i18n-bundle>org.wso2.carbon.register.ui.i18n.Resources</i18n-bundle>
+            <parent-menu>gaas_menu</parent-menu>
+            <link>../tenant-register/select_domain.jsp</link>
+            <region>region1</region>
+            <order>1</order>
+            <style-class>manage</style-class>
+            <icon>../tenant-register/images/signup-new-org.gif</icon>
+            <skip-authentication>
+                <skip-link>../tenant-register/self_registration_complete.jsp</skip-link>
+                <skip-link>../tenant-register/domain_availability_ajaxprocessor.jsp</skip-link>
+                <skip-link>../tenant-register/select_domain.jsp</skip-link>
+                <skip-link>../tenant-register/select_usage_plan.jsp</skip-link>
+                <skip-link>../tenant-register/success_register.jsp</skip-link>
+
+                <!-- the following files need to be placed in the validate-domain ui component,
+                 but since it has no menu, it had to be moved here -->
+                <skip-link>../validate-domain/validate_domain_not_logged_in.jsp</skip-link>
+                <skip-link>../validate-domain/validate_with_dns_ajaxprocessor.jsp</skip-link>
+                <skip-link>../validate-domain/validate_with_text_ajaxprocessor.jsp</skip-link>
+                <skip-link>../validate-domain/submit_validate_domain_ajaxprocessor.jsp</skip-link>
+
+                <!-- account-mgt stuff -->
+                <skip-link>../account-mgt/update_verifier.jsp</skip-link>
+                <skip-link>../email-verification/validator_ajaxprocessor.jsp</skip-link>
+                <skip-link>../email-verification/invalid_email.jsp</skip-link>
+                <skip-link>../account-mgt/update_verifier_redirector_ajaxprocessor.jsp</skip-link>
+
+                <!--payment stuff -->
+                <skip-link>../payment/registration_payment.jsp</skip-link>
+                <skip-link>../payment/registration_payment_completed.jsp</skip-link>
+            </skip-authentication>
+            <require-not-logged-in>true</require-not-logged-in>
+        </menu>
+    </menus>
+
+</component>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/register/ui/i18n/JSResources.properties
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/register/ui/i18n/JSResources.properties b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/register/ui/i18n/JSResources.properties
new file mode 100644
index 0000000..c49c4b0
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/register/ui/i18n/JSResources.properties
@@ -0,0 +1,6 @@
+password.mismatched=Passwords do not match.
+email.mismatched=The emails are mismatching.
+current.password.should.provided=You should provide the current password in order to change the password.
+password.length=Your password must be at least 6 characters long. Try again.
+domain.available=Domain is available to register.
+domain.unavailable=Sorry!. The Domain is already registered. Please choose a different domain.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/register/ui/i18n/Resources.properties
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/register/ui/i18n/Resources.properties b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/register/ui/i18n/Resources.properties
new file mode 100644
index 0000000..b757c4f
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/org/wso2/carbon/register/ui/i18n/Resources.properties
@@ -0,0 +1,62 @@
+submit.tenant=Submit Tenant
+domain=Tenant Domain
+domain.information=Domain Information
+terms.of.use=Terms of Use
+contact.details=Contact Details
+admin.username=Admin Username
+username=Username
+username.or.domain=Username/Domain
+current.admin.password=Current Admin Password
+new.admin.password=New Admin Password
+new.admin.password.repeat=New Admin Password (Repeat)
+admin.password=Admin Password
+admin.password.repeat=Admin Password (Repeat)
+govern.add_tenants.menu=Add New Tenant
+govern.view_tenants.menu=View Tenants
+overview=Overview
+tenants.list=Tenants List
+company.organization=Company/Organization
+admin.contact=Admin Contact
+edit=Edit
+multitenancy=Multitenancy
+added.successfully=You have successfully added a new tenant with domain:
+updated.successfully=You have successfully updated the tenant with domain:
+update.added.tenant=Update the just added/updated tenant
+update.tenant=Update Tenant
+add.new.tenant=Add a new tenant
+register.new.organization=Sign up your organization
+view.all.tenants=View all tenants
+tenant.admin=Tenant Admin
+tenant.description=Tenant Description
+admin.fullname=Full Name
+admin.firstname=First Name
+admin.lastname=Last Name
+admin.address=Address
+admin.email=Email
+admin.email.repeat=Email (Repeat)
+admin.telephone=Telephone
+admin.im=IM
+admin.url=URL
+self.registration=Registry Tenant
+gaas=Sign up
+register.org.menu=Sign up new organization
+gaas.register.a.new.tenant=Register A New Tenant
+active=Active
+theme.management=Theme Management
+word.verification=Word Verification
+captcha.message=Type the characters you see in the picture below.
+select.domain.menu=Sign up new organization
+select.domain.title=Select a domain for your organization
+password.reset=Password Reset
+password.reset.failed=Password Reset Attempt Failed
+verified.request.successfully=You have successfully verified your Password reset request.\nPls reset your password below.
+request.verification.failed=Password Reset Verification Failed. \nPls make sure you have clicked the correct link to reset your domain's admin password.
+accept.eula=I have read and accepted the terms in the license agreement above.
+usage.plan.information= Usage Plan Information
+select.usage.plan.for.tenant=Select Usage Plan For Tenant
+demo.package.price=$0 per month
+select.package.message=According to the selected plan, resources will be allocated for you. You can upgrade or downgrade your plan later according to your requirements. If you need more information on plans, click 'Pricing Info'.
+required.msg=All fields marked with an asterisk (<span class="required">*</span>) are required. 
+billing.currency=$
+redirect.to.paypal.msg1=You will be redirected to PayPal to make a registration payment of
+redirect.to.paypal.msg2=Do you wish to proceed?  
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/css/tenant-register.css
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/css/tenant-register.css b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/css/tenant-register.css
new file mode 100644
index 0000000..621c028
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/css/tenant-register.css
@@ -0,0 +1,78 @@
+body {
+	color:#111111;
+	font-size:0.75em;
+	font-size-adjust:none;
+	font-style:normal;
+	font-variant:normal;
+	font-weight:normal;
+	line-height:1.25em;
+	background-image: url(../images/body-bg.gif);
+	background-position: left top;
+	background-repeat: repeat-x;
+	margin: 0px;
+	padding: 0px;
+}
+
+div.clear {
+	clear:both;
+}
+p { }
+
+td { }
+
+a:link { }
+
+a:visited { }
+
+a:hover { }
+
+a:active { }
+
+div.features {
+	background-image: url(../images/features-bg.gif);
+	background-position: 39px 30px;
+	background-repeat: no-repeat;
+}
+div.feature {
+	float: left;
+	width: 221px;
+	margin-left: 39px;
+	margin-top: 30px;
+	padding: 20px;
+	text-align: left;
+}
+div.feature img {
+	float: left;
+	margin-right: 10px;
+	width: 64px;
+}
+div.feature h2 {
+	margin-top: 0px;
+	margin-bottom: 7px;
+	color: #0499CC;
+	font-size: 155%;
+	line-height: 110%;
+	font-weight: normal;
+	
+}
+div.feature p {
+	margin-top: 0px;
+	padding-top: 0px;
+}
+td.page-header-help a{
+    position:absolute;
+    right:20px;
+}
+div#middle div#workArea {
+    padding:0px;
+}
+.registration_help{
+    color:#555;
+    line-height:25px;
+}
+.toggle_container ,h2.trigger {
+    box-shadow: none;
+}
+.leftCol-med{
+    width:180px;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/aboutUsagePlans.html
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/aboutUsagePlans.html b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/aboutUsagePlans.html
new file mode 100644
index 0000000..791b867
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/aboutUsagePlans.html
@@ -0,0 +1,104 @@
+<!--
+ ~ 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.
+ -->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <title>Select Usage Plan For Tenant - User Guide</title>
+  <link href="../../admin/css/documentation.css" rel="stylesheet" type="text/css" media="all" />
+</head>
+
+<body>
+
+
+ <h1>Select Usage Plan For Tenant</h1>
+
+
+ <h2> <b> Usage Plans(Subscriptions)</b></h2>
+
+<p>
+    According to the usage plan that you selected you will get different volume of service and registry
+    bandwidths other services that available for tenants.By selecting right usage plan that suits
+    your requirements you can get maximum profit
+</p>
+
+
+<h2><b>Multitenancy Free</b></h2>
+<p>
+  This is the free usage plan.You will get limited amount of resources.This package is
+  best suite for evaluation and tests.
+</p>
+ <h2><b>Multitenancy Small</b></h2>
+<p>
+   This package is best suite for small business.
+</p>
+<h2><b>Multitenancy Medium</b></h2>
+<p>
+   This usage plan suites for medium scale business.You will get average amount of resources
+    with this package.
+</p>
+<h2><b>Multitenancy Large</b></h2>
+<p>
+   This is the premium usage plan.You will get maximum resources form this plan.
+   This is best suite to large scale business.
+</p>
+
+<p>
+
+   Usage Plan summery
+<table border="1">
+<tr>
+<td>Usage Plan Name</td>
+<td>Number Of Users</td>
+<td>Registry Bandwidth (Mb) </td>
+<td>Service BandWidth (Mb) </td>
+<td>Cost Per Month ($)</td>
+</tr>
+<tr>
+<td>Multitenancy Free</td>
+<td>5</td>
+<td>10</td>
+<td>10</td>
+<td>10</td>
+</tr>
+<tr>
+<td>Multitenancy Small</td>
+<td>10</td>
+<td>25</td>
+<td>25</td>
+<td>25</td>
+</tr>
+<tr>
+<td>Multitenancy Medium</td>
+<td>20</td>
+<td>100</td>
+<td>100</td>
+<td>100</td>
+</tr>
+<tr>
+<td>Multitenancy Large</td>
+<td>50</td>
+<td>200</td>
+<td>200</td>
+<td>200</td>
+</tr>
+</table> 
+<div><strong>Figure1: Usage Plan Summery Table</strong></div>
+</p>
+</body>
+
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/images/add-org.png
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/images/add-org.png b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/images/add-org.png
new file mode 100644
index 0000000..3d97bab
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/images/add-org.png differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/userguide.html
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/userguide.html b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/userguide.html
new file mode 100644
index 0000000..f97cf59
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/docs/userguide.html
@@ -0,0 +1,104 @@
+<!--
+ ~ 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.
+ -->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <title>Multitenancy Tenant Self Registration - User Guide</title>
+  <link href="../../admin/css/documentation.css" rel="stylesheet" type="text/css" media="all" />
+</head>
+
+<body>
+<h1>Tenant Self Registration</h1>
+
+<p style="font-size:small;">
+You can use this form to register an account for the domain of your organization. You can also check whether the domain is available to register here.
+</p>
+<p style="font-size:small;">
+Optionally you can choose to validate the domain, or can go ahead registering without validating the domain for the moment.
+</p>
+
+<p>
+<img src="images/add-org.png" alt="Register New Organization Form"/>
+<div><strong>Figure1: Register A New Organization Form</strong></div>
+</p>
+
+<p>
+
+<p style="font-size:small;">
+You need to provide the following information to register your organization.
+</p>
+
+
+<table border="1">
+    <thead style="font-size:small;">
+        <td>
+           <b> The Form Field </b>
+        </td>
+        <td >
+            <b>Description</b>
+        </td>
+    </thead>
+    <tbody style="font-size:small;">
+        <tr>
+            <td>Domain</td>
+            <td>Enter the domain name of your organization in here.</td>
+        </tr>
+        <tr>
+            <td>Admin Username</td>
+            <td>The username of the first admin account for your organization. You can use this account to login to all WSO2 Stratos services under your domain name. There
+            is a user management UI that you can access after you login to the system where you can add new users (including users under admin role), new roles.
+            </td>
+        </tr>
+        <tr>
+            <td>First Name</td>
+            <td>Your first name, which will be used to address you in the further communication and the notifications.</td>
+        </tr>
+        <tr>
+            <td>Last Name</td>
+            <td>Your last name.</td>
+        </tr>
+        <tr>
+            <td>Admin Password</td>
+            <td>The password of the startup admin account. You can change the password later from the user management UI.</td>
+        </tr>
+        <tr>
+            <td>Admin Password (Repeat)</td>
+            <td>Repeat the password you provided in the above field, so we can catch any typing mistake you made in there.</td>
+        </tr>
+        <tr>
+            <td>Email</td>
+            <td>Your email address. This email will be used to complete the registration process and to contact you for any further requirement.</td>
+        </tr>
+        <tr>
+            <td>Word Verification</td>
+            <td>Enter the letters shown in the above image in this text box. 
+        </tr>
+    </tbody>
+</table>
+
+</p>
+
+<p style="font-size:small;">
+Once you completed the registration, you will be sent an email notification with the account verification information. 
+</p>
+<p style="font-size:small;">
+After verifying your registration, you can log in to the account using the log in page.
+</p>
+</body>
+
+</html>


[3/7] Tenat-mgt refactoring

Posted by is...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/domain_availability_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/domain_availability_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/domain_availability_ajaxprocessor.jsp
new file mode 100644
index 0000000..730d777
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/domain_availability_ajaxprocessor.jsp
@@ -0,0 +1,50 @@
+<!--
+ ~ 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.
+ -->
+<%@ page import="org.wso2.carbon.registry.core.RegistryConstants" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
+<%@ page import="org.wso2.carbon.registry.common.ui.UIException" %>
+<%@ page import="org.wso2.carbon.register.ui.utils.TenantConfigUtil" %>
+<%@ page import="java.util.Enumeration" %>
+<%@ page import="org.wso2.carbon.CarbonConstants" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<%
+try {
+    boolean domainAvailable = TenantConfigUtil.checkDomainAvailability(request, config, session);
+
+    if (domainAvailable) {
+    %>
+    ----DomainAvailable----
+    <%
+    }
+    else {
+    %>
+    ----DomainUnavailable----
+    <%
+    }
+} catch (UIException e) {
+
+%>
+    Error in checking the domain availability.
+    please retry the registration from the <a href="../tenant-register/select_domain.jsp">start</a>.
+<%
+}
+
+%>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/get_package_info_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/get_package_info_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/get_package_info_ajaxprocessor.jsp
new file mode 100644
index 0000000..fe7a6f6
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/get_package_info_ajaxprocessor.jsp
@@ -0,0 +1,39 @@
+<%--
+~ 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.
+--%>
+<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
+<%@ page import="org.json.JSONArray" %>
+<%@ page import="org.wso2.carbon.register.ui.clients.PackageInfoServiceClient" %>
+<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
+<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
+<%@ page import="org.wso2.carbon.CarbonConstants" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<%
+
+    String backendServerUrl = CarbonUIUtil.getServerURL(config.getServletContext(), session);
+    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
+    ConfigurationContext configContext =
+            (ConfigurationContext)config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
+
+    PackageInfoServiceClient client = new PackageInfoServiceClient(cookie, backendServerUrl,configContext);
+    JSONArray packageInfoArray = client.getBillingPackagesJsonArray();
+
+    out.write(packageInfoArray.toString());
+%>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/ajax-loader.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/ajax-loader.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/ajax-loader.gif
new file mode 100644
index 0000000..f2a1bc0
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/ajax-loader.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/body-bg.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/body-bg.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/body-bg.gif
new file mode 100644
index 0000000..5db1464
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/body-bg.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/button-back.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/button-back.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/button-back.gif
new file mode 100644
index 0000000..6a52e34
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/button-back.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/content-back-left.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/content-back-left.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/content-back-left.jpg
new file mode 100644
index 0000000..ebfe8ed
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/content-back-left.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/content-back.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/content-back.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/content-back.jpg
new file mode 100644
index 0000000..62b8da1
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/content-back.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/create-org-button.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/create-org-button.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/create-org-button.gif
new file mode 100644
index 0000000..b7e62a3
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/create-org-button.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-01-icon.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-01-icon.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-01-icon.gif
new file mode 100644
index 0000000..ff3ba26
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-01-icon.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-02-icon.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-02-icon.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-02-icon.gif
new file mode 100644
index 0000000..ee4cb66
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-02-icon.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-03-icon.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-03-icon.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-03-icon.gif
new file mode 100644
index 0000000..8f3c2a1
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/feature-03-icon.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/features-bg.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/features-bg.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/features-bg.gif
new file mode 100644
index 0000000..dd9e693
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/features-bg.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/footer.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/footer.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/footer.jpg
new file mode 100644
index 0000000..c617091
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/footer.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/forum.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/forum.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/forum.gif
new file mode 100644
index 0000000..e92779a
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/forum.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/header.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/header.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/header.jpg
new file mode 100644
index 0000000..4438a06
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/header.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/help.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/help.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/help.gif
new file mode 100644
index 0000000..43242c2
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/help.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/images.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/images.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/images.gif
new file mode 100644
index 0000000..94b46dc
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/images.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/issue-tracker.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/issue-tracker.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/issue-tracker.gif
new file mode 100644
index 0000000..9029c12
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/issue-tracker.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/logo.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/logo.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/logo.jpg
new file mode 100644
index 0000000..202360d
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/logo.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/mailing-list.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/mailing-list.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/mailing-list.gif
new file mode 100644
index 0000000..06d61e3
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/mailing-list.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/page-back.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/page-back.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/page-back.jpg
new file mode 100644
index 0000000..2e21b54
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/page-back.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/people.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/people.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/people.gif
new file mode 100644
index 0000000..edfa49b
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/people.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/services.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/services.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/services.gif
new file mode 100755
index 0000000..9883116
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/services.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/signup-new-org.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/signup-new-org.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/signup-new-org.gif
new file mode 100644
index 0000000..640a501
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/signup-new-org.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/thememgt.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/thememgt.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/thememgt.gif
new file mode 100644
index 0000000..e554e87
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/thememgt.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/user-guide.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/user-guide.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/user-guide.gif
new file mode 100644
index 0000000..9342adc
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/images/user-guide.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/init_payment_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/init_payment_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/init_payment_ajaxprocessor.jsp
new file mode 100755
index 0000000..d827f7c
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/init_payment_ajaxprocessor.jsp
@@ -0,0 +1,101 @@
+<!--
+ ~ 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.
+ -->
+<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
+<%@ page import="org.json.JSONArray"%>
+<%@ page import="org.wso2.carbon.CarbonConstants" %>
+<%@ page import="org.wso2.carbon.register.ui.clients.PackageInfoServiceClient" %>
+<%@ page import="org.wso2.carbon.stratos.common.util.CommonUtil" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
+<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
+<%@ page import="java.util.Collections" %>
+<%@ page import="java.util.Enumeration" %>
+<%@ page import="java.util.Iterator" %>
+<%@ page import="java.util.List" %>
+<%@ page import="java.util.Map" %>
+<%@ page import="org.json.JSONException" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+<carbon:jsi18n
+		resourceBundle="org.wso2.carbon.register.ui.i18n.JSResources"
+		request="<%=request%>" />
+<script type="text/javascript" src="../registry_common/js/registry_validation.js"></script>
+<script type="text/javascript" src="../registry_common/js/registry_common.js"></script>
+<script type="text/javascript" src="../ajax/js/prototype.js"></script>
+<script type="text/javascript" src="js/register_config.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.form.js"></script>
+<script type="text/javascript" src="../dialog/js/jqueryui/jquery-ui.min.js"></script>
+<%
+    String tenantDomain = request.getParameter("domain");
+    // The actual usage plan the tenant selects in select_usage_plan.jsp
+    String selectedUsagePlan = request.getParameter("selectedUsagePlan");
+    session.setAttribute("selectedUsagePlan", selectedUsagePlan);
+    
+    String backendServerUrl = CarbonUIUtil.getServerURL(config.getServletContext(), session);
+    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
+    ConfigurationContext configContext =
+            (ConfigurationContext)config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
+
+    PackageInfoServiceClient client = new PackageInfoServiceClient(cookie, backendServerUrl,configContext);
+    JSONArray packageInfoArray = client.getBillingPackagesJsonArray();
+    String amount = "0";
+
+    for (int i = 0; i < packageInfoArray.length(); i++) {
+        try {
+            if (packageInfoArray.getJSONObject(i).getString("name").equals(selectedUsagePlan)) {
+                amount = packageInfoArray.getJSONObject(i).getString("subscriptionCharge");
+            }
+        } catch (JSONException e) {
+            //
+        }
+    }
+
+    String successUrl;
+    String paypalUrl = CommonUtil.getStratosConfig().getPaypalUrl();
+    String adminConsoleURL = CarbonUIUtil.getAdminConsoleURL(request);
+    adminConsoleURL = adminConsoleURL.substring(0, adminConsoleURL.indexOf("carbon"));
+     successUrl = adminConsoleURL + "carbon/payment/registration_payment.jsp";
+    String cancelUrl = adminConsoleURL + "carbon/admin/login.jsp";
+%>
+
+<script type="text/javascript">
+
+
+        var successUrl = '<%=successUrl%>';
+        var cancelUrl = '<%=cancelUrl%>';
+        var amount = '<%=amount%>';
+        var tenantDomain = '<%=tenantDomain%>';
+        jQuery.ajax({
+            type: 'GET',
+            url: '../payment/setEC-ajaxprocessor.jsp',
+            data: 'successUrl=' + successUrl + '&cancelUrl=' + cancelUrl + '&amount=' + amount + '&tenantDomain=' + tenantDomain,
+            dataType: 'json',
+            async: false,
+            success: function(msg) {
+                var resp = msg;
+                if(resp.ack=='Success'){
+                    location.href = '<%=paypalUrl%>' + resp.token;
+                }else{
+                    location.href = cancelUrl;
+                }
+            },
+            error:function () {
+                location.href = cancelUrl;
+            }
+        });
+</script>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/js/register_config.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/js/register_config.js b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/js/register_config.js
new file mode 100644
index 0000000..fdcd24e
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/js/register_config.js
@@ -0,0 +1,147 @@
+function addTenant(isPublicCloud) {
+    var domain = document.getElementById('domain');
+    var reason = "";
+    var addTenantForm = document.getElementById('addTenantForm');
+    var adminPassword = "";
+    var adminPasswordRepeat = "";
+    var email = "";
+    var firstname = document.getElementById('admin-firstname');
+    var lastname = document.getElementById('admin-lastname');
+    var adminName = document.getElementById('admin');
+    adminPassword = document.getElementById('admin-password');
+    adminPasswordRepeat = document.getElementById('admin-password-repeat');
+    email = document.getElementById('admin-email');
+
+    // the domain validation part is moved to the select_domain.js
+
+    var reason = validateEmpty(domain, "Domain");
+    if (reason == "") {
+        reason += checkDomain(domain, isPublicCloud);
+    }
+    if (reason == "") {
+        reason += validateEmpty(firstname, "First Name");
+    }
+    if (reason == "") {
+        reason += validateIllegal(firstname, "First Name");
+    }
+    if (reason == "") {
+        reason += validateEmpty(lastname, "Last Name");
+    }
+    if (reason == "") {
+        reason += validateIllegal(lastname, "Last Name");
+    }
+    if (reason == "") {
+        reason += validateEmpty(adminName, "Admin Username");
+    }
+    if (reason == "") {
+        reason += validateIllegal(adminName, "Admin Username");
+    }
+    if (reason == "") {
+        reason += validateUsername(adminName);
+    }
+    if (reason == "") {
+        reason += validateEmpty(adminPassword, "Admin Password");
+    }
+    if (reason == "") {
+        reason += validateAdminPassword(adminPassword);
+    }
+    if (reason == "") {
+        reason += validateEmpty(adminPasswordRepeat, "Admin Password (Repeat)");
+    }
+    if (reason == "") {
+        reason += validateEmpty(email, "Email");
+    }
+    if (reason == "") {
+        reason += validateEmail(email);
+    }
+    if (reason == "") {
+        if (adminPassword.value != adminPasswordRepeat.value) {
+            reason += jsi18n["password.mismatched"];
+        }
+        if (adminPassword.value.length < 6) {
+            reason += jsi18n["password.length"];
+        }
+    }
+    if (reason != "") {
+        CARBON.showWarningDialog(reason);
+        document.getElementbyId("submit-button").disabled = false;
+        document.getElementById('waitMessage').style.display = 'none';
+        return;
+    }
+    addTenantForm.submit();
+}
+
+function validateAdminPassword(fld) {
+    var error = "";
+
+    if (fld.value == "") {
+        error = org_wso2_carbon_registry_common_ui_jsi18n["no.password"] + "<br />";
+    } /* else if ((fld.value.length < 3) || (fld.value.length > 15)) {
+     error = org_wso2_carbon_registry_common_ui_jsi18n["wrong.password"] + "<br />";
+     } else if (illegalChars.test(fld.value)) {
+     error = org_wso2_carbon_registry_common_ui_jsi18n["illegal.password"] + "<br />";
+     } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
+     error = "The password must contain at least one numeral.<br />";
+     } */ else {
+        fld.style.background = 'White';
+    }
+    return error;
+}
+
+function activationChanged(cbox, domain) {
+    if (!cbox.checked) {
+        CARBON.showConfirmationDialog("Are you sure you want to deactivate the domain: " +
+                                      domain + ".", function() {
+            var submitForm = document.getElementById(domain + "_form");
+            submitForm.submit();
+        }, function() {
+            cbox.checked = "on";
+        });
+    } else {
+        var submitForm = document.getElementById(domain + "_form");
+        submitForm.submit();
+    }
+}
+
+function fillAdminValue() {
+    var adminValue = document.getElementById('adminValue');
+    var domain = document.getElementById('domain');
+
+    var reason = validateIllegal(domain, "Domain");
+    if (reason != "") {
+        CARBON.showErrorDialog(reason);
+        adminValue.innerHTML = '';
+        return;
+    }
+
+    if (domain.value == "") {
+        adminValue.innerHTML = '' + domain.value;
+    }
+    else {
+        adminValue.innerHTML = '@' + domain.value;
+    }
+}
+
+function showregistrationfail() {
+    var error = "";
+    CARBON.showWarningDialog(error);
+}
+
+var kaptchaImgUrl;
+function showKaptcha(kaptchaImgUrlArg) {
+    kaptchaImgUrl = kaptchaImgUrlArg;
+    var kaptchaImgDiv = document.getElementById("kaptchaImgDiv");
+    kaptchaImgDiv.innerHTML = "<img src='../tenant-register/images/ajax-loader.gif' alt='busy'/>";
+    setTimeout("showKaptchaTimely()", 4000);
+}
+
+function showKaptchaTimely() {
+    var kaptchaImgDiv = document.getElementById("kaptchaImgDiv");
+    kaptchaImgDiv.innerHTML = "<img src='" + kaptchaImgUrl + "' alt='If you can not see the captcha " +
+                              "image please refresh the page or click the link again.'/>";
+}
+
+function activateSubmit(fld) {
+    var submitButton = document.getElementById('submit-button');
+    submitButton.disabled = !fld;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/js/select_domain.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/js/select_domain.js b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/js/select_domain.js
new file mode 100644
index 0000000..592e308
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/js/select_domain.js
@@ -0,0 +1,75 @@
+function checkDomainAvailability(isPublicCloud) {
+    var domain = document.getElementById('domain');
+
+    var reason = validateEmpty(domain, "Domain");
+    if (reason == "") {
+        reason += checkDomain(domain, isPublicCloud);
+    }
+
+    if(reason != "") {
+        CARBON.showWarningDialog(reason);
+        return false;
+    }
+
+    var busyCheck = document.getElementById("busyCheck");
+    busyCheck.innerHTML = "<img src=\"images/ajax-loader.gif\"/>";
+    
+    var domain_confirmation_div = document.getElementById("domain-confirmation-msg");
+    
+    new Ajax.Request('../tenant-register/domain_availability_ajaxprocessor.jsp',
+    {
+        method:'post',
+        parameters: {domain: domain.value},
+
+        onSuccess: function(transport) {
+            busyCheck.innerHTML = "";
+            var returnValue = transport.responseText;
+            if (returnValue.search(/----DomainAvailable----/) == -1) {
+                domain_confirmation_div.style.color = "#f00";
+                domain_confirmation_div.innerHTML = jsi18n["domain.unavailable"]; 
+                result = false;
+            } else {
+                domain_confirmation_div.style.color = "#058000";
+                domain_confirmation_div.innerHTML = jsi18n["domain.available"];
+                result = true;
+            }
+        },
+
+        onFailure: function(transport){
+            busyCheck.innerHTML = "";
+        }
+    });
+}
+
+function clearDomainConfirmationMsg() {
+    var domain_confirmation_div = document.getElementById("domain-confirmation-msg");
+    domain_confirmation_div.innerHTML = "";
+}
+
+
+function checkDomain(fld, isPublicCloudSetup)
+{
+    var error = "";
+    var domain = fld.value;
+    var lastIndexOfDot = domain.lastIndexOf(".");
+    var indexOfDot = domain.indexOf(".");
+    var extension = domain.substring(lastIndexOfDot, domain.length);
+
+    var illegalChars = /([^a-zA-Z0-9\._\-])/; // allow only letters and numbers . - _and period
+    if (extension.indexOf("-trial") >= 0 || extension.indexOf("-unverified") >= 0) {
+        // we are not allowing to create a domain with -trial or -unverified is in the extension
+        error = "The domain name you entered is not valid. Please enter a valid domain name.";
+    }
+    else if (isPublicCloudSetup && (lastIndexOfDot <= 0)) {
+        error = "Invalid domain: " + domain + ". You should have an extension to your domain.";
+    }
+    else if (indexOfDot == 0) {
+        error = "Invalid domain, starting with '.'";
+    }
+    else if (illegalChars.test(fld.value)) {
+        error = "The domain only allows letters, numbers, '.', '-' and '_'. <br />";
+    } else {
+        fld.style.background = 'White';
+    }
+    return error;
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/select_domain.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/select_domain.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/select_domain.jsp
new file mode 100644
index 0000000..9adfe7f
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/select_domain.jsp
@@ -0,0 +1,389 @@
+<!--
+~ 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.
+-->
+<%@ page import="org.wso2.carbon.stratos.common.constants.StratosConstants" %>
+<%@ page import="org.wso2.carbon.stratos.common.util.CommonUtil" %>
+<%@ page import="org.wso2.carbon.register.ui.utils.TenantConfigUtil" %>
+<%@ page import="org.wso2.carbon.tenant.register.stub.beans.xsd.CaptchaInfoBean" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+<jsp:include page="../registry_common/registry_common-i18n-ajaxprocessor.jsp"/>
+<script type="text/javascript" src="../registry_common/js/registry_validation.js"></script>
+<script type="text/javascript" src="../registry_common/js/registry_common.js"></script>
+<script type="text/javascript" src="../ajax/js/prototype.js"></script>
+<script type="text/javascript" src="js/select_domain.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.form.js"></script>
+<script type="text/javascript" src="../dialog/js/jqueryui/jquery-ui.min.js"></script>
+<script type="text/javascript" src="../googleanalytics/js/googleAnalyticsProcessor.js"></script>
+<carbon:jsi18n
+        resourceBundle="org.wso2.carbon.register.ui.i18n.JSResources"
+        request="<%=request%>"/>
+<fmt:bundle basename="org.wso2.carbon.register.ui.i18n.Resources">
+
+<jsp:include page="../registry_common/registry_common-i18n-ajaxprocessor.jsp"/>
+<link href="../tenant-register/css/tenant-register.css" rel="stylesheet" type="text/css" media="all"/>
+<script type="text/javascript" src="js/register_config.js"></script>
+<script type="text/javascript">
+
+    var packageInfo;
+    
+    function setFreeUsagePlan() {
+        var foundFreePlan = false;
+        for (var i = 0; i < packageInfo.length; i++) {
+            if (packageInfo[i].subscriptionCharge == "0") {
+                document.getElementById("selectedUsagePlan").value = packageInfo[i].name;
+                foundFreePlan = true;
+                return;
+            }
+        }
+        if(!foundFreePlan) {
+            document.getElementById("selectedUsagePlan").value = packageInfo[0].name;
+        }
+    }
+
+    jQuery(document).ready(
+                          function() {
+                              jQuery.ajax({
+                                  type: 'POST',
+                                  url: 'get_package_info_ajaxprocessor.jsp',
+                                  dataType: 'json',
+                                  data: 'plan=0',
+                                  async: false,
+                                  success: function(data) {
+                                      packageInfo = data;
+                                  },
+                                  error:function (xhr, ajaxOptions, thrownError) {
+                                      CARBON.showErrorDialog('Could not get package information.');
+                                  }
+                              });
+
+                          }
+            );
+</script>
+
+
+<%
+    String domainName = "";
+    String admin = "";
+    String email = "";
+    String firstname = "";
+    String lastname = "";
+    String usagePlan = "";
+    String license = CommonUtil.getEula();
+    boolean isPublicCloud = CommonUtil.isPublicCloudSetup();
+
+    session.setAttribute(StratosConstants.ORIGINATED_SERVICE,
+            request.getParameter(StratosConstants.ORIGINATED_SERVICE));
+    String domain = (String) session.getAttribute("temp-domain-to-register");
+    if (domain == null) {
+        domain = "";
+    }
+    session.removeAttribute("temp-domain-to-register");
+    // hm, i'm not sure whether we really need to clear the success key, if someone in the same session
+    // have succeeded validating the domain, we should let them ignore the validation step. but if
+    // someone look at this without much investigation, he may think this is a bug, so thought of clearing
+    // it anyway...
+    session.removeAttribute("validate-domain-success-key");
+    if ("false".equals(session.getAttribute("temp-domain-available"))) {
+        session.removeAttribute("temp-domain-available");
+%>
+
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+        CARBON.showWarningDialog(jsi18n["domain.unavailable"]);
+    });
+</script>
+<%
+    }
+%>
+<link href="../tenant-register/css/tenant-register.css" rel="stylesheet" type="text/css" media="all"/>
+
+<%
+    CaptchaInfoBean captchaInfoBean;
+    try {
+        captchaInfoBean = TenantConfigUtil.generateRandomCaptcha(config, session);
+    } catch (Exception e) {
+        return;
+    }
+    String captchaImagePath = captchaInfoBean.getImagePath();
+
+    String captchaImageUrl = "../../" + captchaImagePath;
+    String captchaSecretKey = captchaInfoBean.getSecretKey();
+
+    if (session.getAttribute("submit-domain") != null) {
+        domain = (String) session.getAttribute("submit-domain");
+        session.setAttribute("submit-domain", null);
+    }
+    if (session.getAttribute("submit-admin") != null) {
+        admin = (String) session.getAttribute("submit-admin");
+        session.setAttribute("submit-admin", null);
+    }
+    if (session.getAttribute("submit-admin-email") != null) {
+        email = (String) session.getAttribute("submit-admin-email");
+        session.setAttribute("submit-admin-email", null);
+    }
+    if (session.getAttribute("submit-admin-firstname") != null) {
+        firstname = (String) session.getAttribute("submit-admin-firstname");
+        session.setAttribute("submit-admin-firstname", null);
+    }
+    if (session.getAttribute("submit-admin-lastname") != null) {
+        lastname = (String) session.getAttribute("submit-admin-lastname");
+        session.setAttribute("submit-admin-lastname", null);
+    }
+%>
+
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<%
+    if ("failed".equals(session.getAttribute("kaptcha-status"))) {
+        session.setAttribute("kaptcha-status", null);
+%>
+
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+        CARBON.showWarningDialog('Please enter the letters shown as in the image to register.');
+    });
+</script>
+<%
+    }
+
+    if ("true".equals(session.getAttribute("add-tenant-failed"))) {
+        session.removeAttribute("add-tenant-failed");
+%>
+
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+        CARBON.showWarningDialog('Organization registration failed. Please try again with a different domain.');
+    });
+</script>
+<%
+    }
+%>
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+
+        jQuery(".toggle_container").show();
+        /*Hide (Collapse) the toggle containers on load use show() instead of hide() in the
+         above code if you want to keep the content section expanded. */
+
+        jQuery("h2.trigger").click(function() {
+            if (jQuery(this).next().is(":visible")) {
+                this.className = "active trigger";
+            } else {
+                this.className = "trigger";
+            }
+
+            jQuery(this).next().slideToggle("fast");
+            return false; //Prevent the browser jump to the link anchor
+        });
+    });
+</script>
+<div id="middle">
+
+    <h2><fmt:message key="register.new.organization"/></h2>
+
+    <div id="workArea">
+        <div class="registration_help"><fmt:message key="required.msg"/></div>
+        <div id="activityReason" style="display: none;"></div>
+        <form id="addTenantForm" action="submit_tenant_ajaxprocessor.jsp" method="post">
+
+            <table class="styledLeft">
+                <tbody>
+                <tr>
+                    <td class="nopadding">
+                        <h2 class="trigger"><a href="#"><fmt:message key="domain.information"/></a></h2>
+
+                        <div class="toggle_container">
+                            <table class="normal-nopadding" cellspacing="0">
+                                <tbody>
+                                <tr>
+                                    <td class="leftCol-med"><fmt:message key="domain"/><span class="required">*</span>
+                                    </td>
+                                    <td colspan="2"><input onblur="fillAdminValue()"
+                                                           value="<%=domain%>" type="text"
+                                                           name="domain" id="domain"
+                                                           style="width:400px" value=""/>
+                                        <input type="button" value="Check Availability"
+                                               onclick="checkDomainAvailability(<%=isPublicCloud?"true":"false"%>)"/> <span
+                                                id="busyCheck"></span>
+                                    </td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2">Provide a domain for your tenant, in the
+                                        format "example.com". This domain should be unique.
+                                        If this is a legitimate domain, optionally you will be able to validate the ownership of the domain.
+                                    </td>
+                                </tr>
+
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2">
+                                        <div id="domain-confirmation-msg"></div>
+                                    </td>
+                                </tr>
+
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2">
+                                        <input type="checkbox" name="domain-confirmation"
+                                               value="yes">Validate the domain now
+                                        (optional)</input>
+                                    </td>
+                                </tr>
+
+                                </tbody>
+                            </table>
+                        </div>
+
+                        <h2 class="trigger"><a href="#"><fmt:message key="contact.details"/></a></h2>
+
+                        <div class="toggle_container">
+                            <table class="normal-nopadding" cellspacing="0">
+                                <tbody>
+                                <tr>
+                                    <td class="leftCol-med"><fmt:message key="admin.firstname"/><span
+                                            class="required">*</span></td>
+                                    <td><input type="text" name="admin-firstname" id="admin-firstname"
+                                               style="width:400px" value="<%=firstname%>"/></td>
+                                </tr>
+                                <tr>
+                                    <td><fmt:message key="admin.lastname"/><span class="required">*</span></td>
+                                    <td><input type="text" name="admin-lastname" id="admin-lastname" style="width:400px"
+                                               value="<%=lastname%>"/></td>
+                                </tr>
+                                <tr>
+                                    <td><fmt:message key="admin.username"/><span class="required">*</span></td>
+                                    <td><input type="text" name="admin" id="admin" style="width:400px"
+                                               value="<%=admin%>"/><span id="adminValue"></span></td>
+                                </tr>
+                                <tr>
+                                    <td><fmt:message key="admin.password"/>
+                                        <span class="required">*</span></td>
+                                    <td><input type="password" name="admin-password" id="admin-password"
+                                               style="width:400px"/></td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td class="registration_help">(Minimum of 6 Characters in length)</td>
+                                </tr>
+                                <tr>
+                                    <td><fmt:message key="admin.password.repeat"/>
+                                        <span class="required">*</span></td>
+                                    <td><input type="password" name="admin-password-repeat" id="admin-password-repeat"
+                                               style="width:400px"/></td>
+                                </tr>
+                                <tr>
+                                    <td class="leftCol-med"><fmt:message key="admin.email"/><span
+                                            class="required">*</span></td>
+                                    <td colspan="2"><input type="text" name="admin-email" id="admin-email"
+                                                           style="width:400px" value="<%=email%>"/></td>
+                                </tr>
+                                <tr>
+                                    <td class="leftCol-med"><fmt:message key="word.verification"/><span
+                                            class="required">*</span></td>
+                                    <td colspan="2"><fmt:message key="captcha.message"/></td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2">
+                                        <div id="kaptchaImgDiv"></div>
+                                    </td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2" height="100"><input type="text" id="captcha-user-answer"
+                                                                        name="captcha-user-answer" style="width:400px"
+                                                                        value=""/></td>
+                                </tr>
+                                </tbody>
+                            </table>
+                        </div>
+
+                        <%
+                            if (isPublicCloud) {
+                        %>
+                        <h2 class="trigger"><a href="#"><fmt:message key="terms.of.use"/></a></h2>
+
+                        <div class="toggle_container">
+                            <table class="normal-nopadding" cellspacing="0">
+                                <tbody>
+
+
+                                <tr></tr>
+                                <tr>
+                                    <td>
+                                        <textarea rows="10" readonly="readonly" name="license-text"
+                                                  style="width:100%"><%=license%>
+                                        </textarea>
+                                    </td>
+                                </tr>
+                                <tr>
+                                    <td><input type="checkbox" name="activateButton" id="activateButton"
+                                               onclick="activateSubmit(form.activateButton.checked)"/>
+                                        <label for="activateButton"><fmt:message key="accept.eula"/></label></td>
+                                </tr>
+                                <%
+                                    }
+                                %>
+
+
+                                </tbody>
+                            </table>
+                        </div>
+                    </td>
+                </tr>
+                <tr id="buttonRow" colspan="2">
+                    <td class="buttonRow">
+                        <input type="hidden" name="selectedUsagePlan" id="selectedUsagePlan"/>
+                        <input type="hidden" name="captcha-secret-key" value="<%=captchaSecretKey%>"/>
+                        <%
+                            if (isPublicCloud) {
+                        %>
+                        <input class="button" id="submit-button" type="button" disabled="disabled" style="float:left; margin-top:4px"
+                               value="Next >" onclick="setFreeUsagePlan();addTenant();jQuery(this).attr('disabled', true);jQuery('#waitMessage').toggle('fast')"/>
+                        <%
+                        } else {
+                        %>
+                        <input class="button" id="submit-button" type="button" style="float:left; margin-top:4px"
+                               value="Next >" onclick="setFreeUsagePlan();addTenant();jQuery(this).attr('disabled', true);jQuery('#waitMessage').toggle('fast')"/>
+                        <%
+                            }
+                        %>
+                        <div id="waitMessage" style="font-size:13px !important;margin-top:5px; float:left;display:none"><img
+                                src="images/ajax-loader.gif" align="left" hspace="20"/>Registering new tenant ...
+                        </div>
+                        <div style="clear:both"></div>
+                    </td>
+                </tr>
+                </tbody>
+            </table>
+        </form>
+        <br/>
+    </div>
+</div>
+<script type="text/javascript">
+    showKaptcha('<%=captchaImageUrl%>');
+</script>
+</fmt:bundle>
+
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/select_usage_plan.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/select_usage_plan.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/select_usage_plan.jsp
new file mode 100644
index 0000000..3425d00
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/select_usage_plan.jsp
@@ -0,0 +1,279 @@
+<!--
+~ 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.
+-->
+<%@ page import="org.wso2.carbon.stratos.common.constants.StratosConstants" %>
+<%@ page import="org.wso2.carbon.stratos.common.util.CommonUtil" %>
+<%@ page import="org.wso2.carbon.register.ui.utils.TenantConfigUtil" %>
+<%@ page import="org.wso2.carbon.tenant.register.stub.beans.xsd.CaptchaInfoBean" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+<jsp:include page="../registry_common/registry_common-i18n-ajaxprocessor.jsp"/>
+<script type="text/javascript" src="../registry_common/js/registry_validation.js"></script>
+<script type="text/javascript" src="../registry_common/js/registry_common.js"></script>
+<script type="text/javascript" src="../ajax/js/prototype.js"></script>
+<script type="text/javascript" src="js/select_domain.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.form.js"></script>
+<script type="text/javascript" src="../dialog/js/jqueryui/jquery-ui.min.js"></script>
+<script type="text/javascript" src="../googleanalytics/js/googleAnalyticsProcessor.js"></script>
+<carbon:jsi18n
+        resourceBundle="org.wso2.carbon.register.ui.i18n.JSResources"
+        request="<%=request%>"/>
+<fmt:bundle basename="org.wso2.carbon.register.ui.i18n.Resources">
+
+<jsp:include page="../registry_common/registry_common-i18n-ajaxprocessor.jsp"/>
+<link href="../tenant-register/css/tenant-register.css" rel="stylesheet" type="text/css" media="all"/>
+<script type="text/javascript" src="js/register_config.js"></script>
+<script type="text/javascript">
+
+<%
+    boolean chargeOnRegistration = CommonUtil.isChargedOnRegistration();
+    String regDomain = (String)session.getAttribute("regTenantDomain");
+%>
+    var packageInfo;
+    function showRentalMessage() {
+
+        if (packageInfo == null) {
+            jQuery.ajax({
+                type: 'POST',
+                url: 'get_package_info_ajaxprocessor.jsp',
+                dataType: 'json',
+                data: 'plan=0',
+                async: false,
+                success: function(data) {
+                    packageInfo = data;
+                },
+                error:function (xhr, ajaxOptions, thrownError) {
+                    CARBON.showErrorDialog('Could not get package information.');
+                }
+            });
+        }
+
+        var plan = document.getElementById('selectedUsagePlan').
+                options[document.getElementById('selectedUsagePlan').selectedIndex].value;
+        var charge;
+        for (var i = 0; i < packageInfo.length; i++) {
+            if (packageInfo[i].name == plan) {
+                charge = packageInfo[i].subscriptionCharge;
+                break;
+            }
+
+        }
+
+        document.getElementById('packagePrice').innerHTML = '<b>' + '<fmt:message key="billing.currency"/>' + charge + " per month" + '</b>';
+
+    }
+
+    function makePayment() {
+        var selectEl = document.getElementById("selectedUsagePlan");
+        var selectedUsagePlan = selectEl.options[selectEl.selectedIndex].value;
+        var regTenantDomain = '<%= regDomain%>';
+
+
+        for (var i = 0; i < packageInfo.length; i++) {
+        <% if (chargeOnRegistration) { %>
+            if (packageInfo[i].name == selectedUsagePlan && packageInfo[i].subscriptionCharge != "0") {
+                CARBON.showConfirmationDialog('<fmt:message key="redirect.to.paypal.msg1"/>' + " " + '<fmt:message key="billing.currency"/>' + packageInfo[i].subscriptionCharge +
+                                              ". " + '<fmt:message key="redirect.to.paypal.msg2"/>', function() {
+                    document.getElementById('waitMessage').style.display = 'block';
+                    document.forms["selectUsagePlan"].submit();
+                }, function () {
+                    document.getElementById('submit-button').removeAttribute('disabled');
+                })
+
+            } else if (packageInfo[i].name == selectedUsagePlan && packageInfo[i].subscriptionCharge == "0") {
+                location.href = "../tenant-register/success_register.jsp";
+                break;
+            }
+            <% } else { %>
+                if(packageInfo[i].name == selectedUsagePlan && packageInfo[i].subscriptionCharge != "0") {
+                    jQuery.ajax({
+                        type: 'POST',
+                        url: '../payment/upgrade_registration_usage_plan_ajaxprocessor.jsp',
+                        data: {selectedUsagePlan: selectedUsagePlan, regTenantDomain: regTenantDomain},
+                        async: false,
+                        success: function(msg) {
+                    }});
+                    location.href = "../tenant-register/success_register.jsp";
+                    break;
+                } else if (packageInfo[i].name == selectedUsagePlan && packageInfo[i].subscriptionCharge == "0") {
+                    location.href = "../tenant-register/success_register.jsp";
+                    break;
+                }
+        <% } %>
+
+        }
+    }
+
+    function cancelPaymet() {
+        location.href = "../tenant-register/success_register.jsp";
+    }
+
+    jQuery(document).ready(
+                          function() {
+                              jQuery.ajax({
+                                  type: 'POST',
+                                  url: 'get_package_info_ajaxprocessor.jsp',
+                                  dataType: 'json',
+                                  data: 'plan=0',
+                                  async: false,
+                                  success: function(data) {
+                                      packageInfo = data;
+                                  },
+                                  error:function (xhr, ajaxOptions, thrownError) {
+                                      CARBON.showErrorDialog('Could not get package information.');
+                                  }
+                              });
+
+                              var charge;
+                              var name;
+                              for (var i = 0; i < packageInfo.length; i++) {
+                                  charge = packageInfo[i].subscriptionCharge;
+                                  name = packageInfo[i].name;
+                                  option = document.createElement("option");
+                                  option.value = name;
+                                  option.innerHTML = name;
+                                  document.getElementById('selectedUsagePlan').appendChild(option);
+
+                              }
+                          }
+            );
+</script>
+
+
+<%
+    boolean isPublicCloud = CommonUtil.isPublicCloudSetup();
+
+    session.setAttribute(StratosConstants.ORIGINATED_SERVICE,
+            request.getParameter(StratosConstants.ORIGINATED_SERVICE));
+    String domain = (String) session.getAttribute("temp-domain-to-register");
+    if (domain == null) {
+        domain = "";
+    }
+    session.removeAttribute("temp-domain-to-register");
+    // hm, i'm not sure whether we really need to clear the success key, if someone in the same session
+    // have succeeded validating the domain, we should let them ignore the validation step. but if
+    // someone look at this without much investigation, he may think this is a bug, so thought of clearing
+    // it anyway...
+    session.removeAttribute("validate-domain-success-key");
+    if ("false".equals(session.getAttribute("temp-domain-available"))) {
+        session.removeAttribute("temp-domain-available");
+%>
+
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+        CARBON.showWarningDialog(jsi18n["domain.unavailable"]);
+    });
+</script>
+<%
+    }
+%>
+<link href="../tenant-register/css/tenant-register.css" rel="stylesheet" type="text/css" media="all"/>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<script type="text/javascript">
+    jQuery(document).ready(function() {
+
+        jQuery(".toggle_container").show();
+        /*Hide (Collapse) the toggle containers on load use show() instead of hide() in the
+         above code if you want to keep the content section expanded. */
+
+        jQuery("h2.trigger").click(function() {
+            if (jQuery(this).next().is(":visible")) {
+                this.className = "active trigger";
+            } else {
+                this.className = "trigger";
+            }
+
+            jQuery(this).next().slideToggle("fast");
+            return false; //Prevent the browser jump to the link anchor
+        });
+    });
+
+</script>
+<div id="middle">
+
+    <h2><fmt:message key="register.new.organization"/></h2>
+
+    <div id="workArea">
+        <div class="registration_help"><fmt:message key="required.msg"/></div>
+        <div id="activityReason" style="display: none;"></div>
+        <form id="selectUsagePlan" action="init_payment_ajaxprocessor.jsp" method="post">
+
+            <table class="styledLeft">
+                <tbody>
+                <tr>
+                    <td class="nopadding">
+                        <h2 class="trigger"><a href="#"><fmt:message key="usage.plan.information"/></a></h2>
+
+                        <div class="toggle_container">
+                            <table class="normal-nopadding" cellspacing="0">
+                                <tbody>
+                                <tr>
+                                    <td class="leftCol-med">
+                                        <fmt:message key="select.usage.plan.for.tenant"/><span class="required">*</span>
+                                    </td>
+                                    <td colspan="2">
+                                        <select name="selectedUsagePlan" id="selectedUsagePlan"
+                                                onchange="showRentalMessage();">
+                                        </select>
+                                        <a href="<%=CommonUtil.getStratosConfig().getUsagePlanURL()%>" target="_blank">
+                                            <b>Pricing Info</b>
+                                        </a>
+                                    </td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2" id="packagePrice" class="registration_help"><b><fmt:message
+                                            key="demo.package.price"/></b></td>
+                                </tr>
+                                <tr>
+                                    <td></td>
+                                    <td colspan="2" class="registration_help"><fmt:message
+                                            key="select.package.message"/>
+                                    </td>
+                                </tr>
+                                </tbody>
+                            </table>
+                        </div>                        
+                    </td>
+                </tr>
+                <tr id="buttonRow">
+                    <td class="buttonRow">
+                        <input class="button" id="submit-button" type="button" style="float:left; margin-top:4px; margin-right:4px;"
+                               value="Submit" onclick="makePayment();jQuery(this).attr('disabled', true)"/>
+                        <input class="button" id="cancel-button" type="button" style="float:left; margin-top:4px"
+                               value="Cancel" onclick="cancelPaymet()"/>
+                        <div id="waitMessage" style="font-size:13px !important;margin-top:5px; float:left; display:none"><img
+                                src="images/ajax-loader.gif" align="left" hspace="20"/>Connecting to PayPal ...
+                        </div>
+                        <div style="clear:both"></div>
+                    </td>
+                </tr>
+                </tbody>
+            </table>
+        </form>
+        <br/>
+    </div>
+</div>
+</fmt:bundle>
+
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/submit_tenant_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/submit_tenant_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/submit_tenant_ajaxprocessor.jsp
new file mode 100644
index 0000000..e6059f1
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/submit_tenant_ajaxprocessor.jsp
@@ -0,0 +1,66 @@
+<!--
+ ~ 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.
+ -->
+<%@ page import="org.wso2.carbon.register.ui.utils.TenantConfigUtil" %>
+<%@ page import="org.wso2.carbon.stratos.common.constants.StratosConstants"%>
+<%@ page import="org.wso2.carbon.captcha.mgt.constants.CaptchaMgtConstants"%>
+<%@ page import="org.wso2.carbon.utils.multitenancy.MultitenantConstants" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+<carbon:jsi18n
+		resourceBundle="org.wso2.carbon.register.ui.i18n.JSResources"
+		request="<%=request%>" />
+<%
+
+    try {
+        String gotoConfirmDomain = request.getParameter("domain-confirmation");
+        String domain = request.getParameter("domain");
+
+        String key = TenantConfigUtil.registerTenantConfigBean(request, config, session);
+
+        session.removeAttribute(StratosConstants.ORIGINATED_SERVICE);
+        session.setAttribute("add-tenant-success", "true");
+        session.setAttribute("regTenantDomain", domain);
+
+        String contextPath = "/" + MultitenantConstants.TENANT_AWARE_URL_PREFIX + "/" + request.getParameter("domain");
+        //response.sendRedirect(contextPath + "/carbon/tenant-theme/theme_mgt.jsp?redirectWith=" + key);
+        // now we send the login page.
+
+       // response.sendRedirect(contextPath + "/carbon/admin/login.jsp");
+
+        if (gotoConfirmDomain != null && gotoConfirmDomain.equals("yes")) {
+            // send me to the domain validation form
+            response.sendRedirect("../validate-domain/validate_domain_not_logged_in.jsp?domain=" + domain);
+        }
+        else {
+            // send me direct to the add tenant form, without successkey they will add the suffix -unverified
+            response.sendRedirect("../tenant-register/select_usage_plan.jsp");
+        }
+
+    } catch (Exception e) {
+        String msg = e.getMessage();
+        TenantConfigUtil.setSubmissionValuesForSession(request);
+        if (msg.contains(CaptchaMgtConstants.CAPTCHA_ERROR_MSG)) {
+            session.setAttribute("kaptcha-status", "failed");
+        } else {
+        session.setAttribute("add-tenant-failed", "true");
+        }
+        response.sendRedirect("../tenant-register/select_domain.jsp");
+        return;
+    }
+%>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/success_register.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/success_register.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/success_register.jsp
new file mode 100644
index 0000000..dc60f1b
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.0/src/main/resources/web/tenant-register/success_register.jsp
@@ -0,0 +1,77 @@
+<!--
+~ 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.
+-->
+
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<link href="css/tenant-register.css" rel="stylesheet" type="text/css" media="all"/>
+
+<%
+    // String contextPath = "/" + MultitenantConstants.TENANT_AWARE_URL_PREFIX + "/" + request.getParameter("domain");
+%>
+<div id="middle">
+
+    <h2>
+        Account Created Successfully
+    </h2>
+
+    <div id="workArea">
+
+       <h3>Congratulations! You have successfully created an account for your organization with WSO2 Stratos. </h3>
+
+        <p style="font-size:16px" align="left">
+        A confirmation email has been sent to your email address for this account. Please follow the instructions in the email to activate the account.
+        After that login from the <a href="/carbon/admin/login.jsp"> <b>login page</b></a>.
+        </p>
+    </div>
+
+
+    <div class="clear"></div>
+    <div class="features">
+        <div class="feature">
+            <img src="images/feature-01-icon.gif"/>
+
+            <h2>Elasticity</h2>
+
+            <p>
+                Stratos manages your underlying cloud infrastructure to seamlessly handle the scalability demands of
+                your application.
+            </p>
+        </div>
+        <div class="feature">
+            <img src="images/feature-02-icon.gif"/>
+
+            <h2>Multi-tenancy</h2>
+
+            <p>
+                Departments, developer groups, or projects run fully independently, but share the same middleware
+                platform for maximum resource utilization.
+            </p>
+        </div>
+        <div class="feature">
+            <img src="images/feature-03-icon.gif"/>
+
+            <h2>Self Provisioning</h2>
+
+            <p>
+                Authorized users can provision new tenants from a web portal in moments.
+            </p>
+        </div>
+        <div class="clear"></div>
+    </div>
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/pom.xml b/components/org.apache.stratos.tenant.registration.ui/2.1.1/pom.xml
new file mode 100644
index 0000000..b7e3948
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/pom.xml
@@ -0,0 +1,132 @@
+<?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.register.ui</artifactId>
+	<version>2.1.1</version>
+    <packaging>bundle</packaging>
+    <name>Apache Stratos - Self Registration For New Tenant - User Interface</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.wso2.carbon.register.ui.*,
+                        </Export-Package>
+                        <Import-Package>
+                        	org.wso2.carbon.tenant.register.stub.*; version=4.1.0,
+                            javax.servlet;version="${imp.pkg.version.javax.servlet}",
+                            javax.servlet.http;version="${imp.pkg.version.javax.servlet}",
+                            !javax.xml.namespace,
+                            javax.xml.namespace; version=0.0.0,                            
+                            org.apache.lucene.*,
+                            org.wso2.carbon.captcha.mgt.*,
+                            *;resolution:=optional
+                        </Import-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>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.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>4.1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.core</artifactId>
+        </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.tenant.register.stub</artifactId>
+	    <version>4.1.0</version>
+        </dependency>
+         <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.stratos.common.stub</artifactId>
+	    <version>4.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.captcha.mgt</artifactId>
+            <version>${wso2carbon.version}</version>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/clients/PackageInfoServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/clients/PackageInfoServiceClient.java b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/clients/PackageInfoServiceClient.java
new file mode 100644
index 0000000..8cf6734
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/clients/PackageInfoServiceClient.java
@@ -0,0 +1,77 @@
+package org.apache.stratos.register.ui.clients;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.stratos.common.packages.stub.PackageInfoServiceStub;
+import org.wso2.carbon.stratos.common.packages.stub.PackageInfo;
+
+/**
+ * PackageInfoService client
+ */
+public class PackageInfoServiceClient {
+
+    private static Log log = LogFactory.getLog(PackageInfoServiceClient.class);
+
+    private PackageInfoServiceStub stub;
+    private String epr;
+
+    public PackageInfoServiceClient(
+            String cookie, String backendServerURL, ConfigurationContext configContext)
+            throws Exception {
+
+        epr = backendServerURL + "PackageInfoService";
+
+        try {
+            stub = new PackageInfoServiceStub(configContext, epr);
+
+            ServiceClient client = stub._getServiceClient();
+            Options option = client.getOptions();
+            option.setManageSession(true);
+            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate PackageInfoService client. " + axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new RegistryException(msg, axisFault);
+        }
+    }
+
+    public PackageInfo[] getBillingPackages() throws Exception {
+
+        try {
+            return stub.getPackageInfos();
+        } catch (Exception e) {
+            String msg = "Failed to get package information: " + e.getMessage();
+            log.error(msg, e);
+            throw new Exception(msg, e);
+        }
+    }
+
+    public JSONArray getBillingPackagesJsonArray() throws Exception {
+
+        try {
+            PackageInfo[] packageInfoArray = stub.getPackageInfos();
+            JSONArray jsonPackageInfoArray = new JSONArray();
+            for (PackageInfo packageInfo : packageInfoArray) {
+                JSONObject packageInfoObj = new JSONObject();
+                packageInfoObj.put("name", packageInfo.getName());
+                //TODO https://wso2.org/jira/browse/STRATOS-1819
+                packageInfoObj.put("subscriptionCharge", packageInfo.getSubscriptionCharge());
+                jsonPackageInfoArray.put(packageInfoObj);
+            }
+            return jsonPackageInfoArray;
+        } catch (Exception e) {
+            String msg = "Failed to get package information: " + e.getMessage();
+            log.error(msg, e);
+            throw new Exception(msg, e);
+        }
+
+    }
+}


[2/7] Tenat-mgt refactoring

Posted by is...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/clients/TenantSelfRegistrationClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/clients/TenantSelfRegistrationClient.java b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/clients/TenantSelfRegistrationClient.java
new file mode 100644
index 0000000..1f77f11
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/clients/TenantSelfRegistrationClient.java
@@ -0,0 +1,107 @@
+/*
+*  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.register.ui.clients;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.CarbonConstants;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.tenant.register.stub.TenantMgtServiceStub;
+import org.wso2.carbon.tenant.register.stub.beans.xsd.CaptchaInfoBean;
+import org.wso2.carbon.tenant.register.stub.beans.xsd.TenantInfoBean;
+import org.wso2.carbon.ui.CarbonUIUtil;
+import org.wso2.carbon.utils.ServerConstants;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpSession;
+
+/**
+ * Tenant Self Registration Client class
+ */
+public class TenantSelfRegistrationClient {
+     private static final Log log = LogFactory.getLog(TenantSelfRegistrationClient.class);
+
+    private TenantMgtServiceStub stub;
+    private String epr;
+
+    public TenantSelfRegistrationClient(
+            String cookie, String backendServerURL, ConfigurationContext configContext)
+            throws RegistryException {
+
+        epr = backendServerURL + "TenantMgtService";
+
+        try {
+            stub = new TenantMgtServiceStub(configContext, epr);
+
+            ServiceClient client = stub._getServiceClient();
+            Options option = client.getOptions();
+            option.setManageSession(true);
+            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate AddServices service client. " + axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new RegistryException(msg, axisFault);
+        }
+    }
+
+    public TenantSelfRegistrationClient(ServletConfig config, HttpSession session)
+            throws RegistryException {
+
+        String cookie = (String)session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
+        String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
+        ConfigurationContext configContext = (ConfigurationContext) config.
+                getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
+        epr = backendServerURL + "TenantMgtService";
+
+        try {
+            stub = new TenantMgtServiceStub(configContext, epr);
+
+            ServiceClient client = stub._getServiceClient();
+            Options option = client.getOptions();
+            option.setManageSession(true);
+            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate Add Services service client. " + axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new RegistryException(msg, axisFault);
+        }
+    }
+
+    public String registerTenant(TenantInfoBean tenantInfoBean,
+                                 CaptchaInfoBean captchaInfoBean) throws Exception {
+        return stub.registerTenant(tenantInfoBean, captchaInfoBean);
+     }
+
+    public boolean checkDomainAvailability(String domainName) throws Exception {
+        return stub.checkDomainAvailability(domainName);
+    }
+
+    public String validateOrSuggestDomain(String domainName, String successKey) throws Exception {
+        return stub.validateOrSuggestDomain(domainName, successKey);
+    }
+
+    public CaptchaInfoBean generateRandomCaptcha() throws Exception {
+        return stub.generateRandomCaptcha();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/utils/TenantConfigUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/utils/TenantConfigUtil.java b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/utils/TenantConfigUtil.java
new file mode 100644
index 0000000..a9da43e
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/java/org/apache/stratos/register/ui/utils/TenantConfigUtil.java
@@ -0,0 +1,248 @@
+/*
+ *  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.register.ui.utils;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.util.Base64;
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.stratos.common.constants.StratosConstants;
+import org.apache.stratos.register.ui.clients.TenantSelfRegistrationClient;
+import org.wso2.carbon.registry.common.ui.UIException;
+import org.wso2.carbon.tenant.register.stub.beans.xsd.CaptchaInfoBean;
+import org.wso2.carbon.tenant.register.stub.beans.xsd.TenantInfoBean;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import java.io.StringReader;
+import java.util.Calendar;
+import java.util.Iterator;
+
+/**
+ * Utility methods for tenant configuration
+ */
+public class TenantConfigUtil {
+    private static final Log log = LogFactory.getLog(TenantConfigUtil.class);
+
+    /**
+     * Registers the tenant
+     *
+     * @param request HttpServletRequest
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @return String
+     * @throws UIException
+     */
+    public static String registerTenantConfigBean(HttpServletRequest request,
+                                                  ServletConfig config, HttpSession session) throws UIException {
+        TenantInfoBean tenantInfoBean = new TenantInfoBean();
+        CaptchaInfoBean captchaInfoBean = new CaptchaInfoBean();
+
+        try {
+            // filling tenant info.
+            tenantInfoBean.setFirstname(request.getParameter("admin-firstname"));
+            tenantInfoBean.setLastname(request.getParameter("admin-lastname"));
+            tenantInfoBean.setAdmin(request.getParameter("admin"));
+            tenantInfoBean.setAdminPassword(request.getParameter("admin-password"));
+            tenantInfoBean.setTenantDomain(resolveDomainName(request.getParameter("domain")));
+            tenantInfoBean.setEmail(request.getParameter("admin-email"));
+            tenantInfoBean.setSuccessKey((String) session.getAttribute("validate-domain-success-key"));
+            tenantInfoBean.setUsagePlan(request.getParameter("selectedUsagePlan"));
+            tenantInfoBean.setOriginatedService(TenantConfigUtil.base64Decode((String) session.getAttribute(
+                    StratosConstants.ORIGINATED_SERVICE)));
+            tenantInfoBean.setCreatedDate(Calendar.getInstance());
+            // filling captcha info
+            captchaInfoBean.setSecretKey(request.getParameter("captcha-secret-key"));
+            captchaInfoBean.setUserAnswer(request.getParameter("captcha-user-answer"));
+
+            TenantSelfRegistrationClient selfRegistrationClient =
+                    new TenantSelfRegistrationClient(config, session);
+
+            String returnText = selfRegistrationClient.registerTenant(tenantInfoBean, captchaInfoBean);
+
+            return returnText;
+
+        } catch (Exception e) {
+            AxisFault fault = new AxisFault(e.getMessage());
+            String msg = fault.getReason() + " Failed to add tenant config. tenant-domain: " +
+                    tenantInfoBean.getTenantDomain() + ", " +
+                    "tenant-admin: " + tenantInfoBean.getAdmin() + ".";
+            log.error(msg, e);
+            // we are preserving the original message.
+            throw new UIException(e.getMessage(), e);
+        }
+    }
+
+
+    // do this before the send redirect.
+
+    public static void setSubmissionValuesForSession(HttpServletRequest request) {
+        HttpSession session = request.getSession();
+
+        session.setAttribute("submit-domain", resolveDomainName(request.getParameter("domain")));
+        session.setAttribute("submit-admin", request.getParameter("admin"));
+        session.setAttribute("submit-admin-firstname", request.getParameter("admin-firstname"));
+        session.setAttribute("submit-admin-lastname", request.getParameter("admin-lastname"));
+        session.setAttribute("submit-admin-email", request.getParameter("admin-email"));
+    }
+
+
+    /**
+     * Checks the availability of the domain
+     *
+     * @param request HttpServletRequest
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @return true, if domain is available to register
+     * @throws UIException if failed to check the availability.
+     */
+    public static boolean checkDomainAvailability(
+            HttpServletRequest request, ServletConfig config, HttpSession session)
+            throws UIException {
+        String tenantDomain = null;
+        try {
+            tenantDomain = resolveDomainName(request.getParameter("domain"));
+            TenantSelfRegistrationClient selfRegistrationClient =
+                    new TenantSelfRegistrationClient(config, session);
+            return selfRegistrationClient.checkDomainAvailability(tenantDomain);
+        } catch (Exception e) {
+            String msg = "Failed to check the domain availability:" + tenantDomain + ".";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+
+    /**
+     * Validates or suggests the domain
+     *
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @return domain
+     * @throws UIException, if validating or suggesting the domain failed.
+     */
+    public static String validateOrSuggestDomain(ServletConfig config,
+                                                 HttpSession session) throws UIException {
+        String tempDomainToRegister = resolveDomainName(
+                (String) session.getAttribute("temp-domain-to-register"));
+        // here successKey can be null, in such cases services will directly go to suggest a name
+        String successKey = (String) session.getAttribute("validate-domain-success-key");
+
+        try {
+            TenantSelfRegistrationClient selfRegistrationClient =
+                    new TenantSelfRegistrationClient(config, session);
+            return selfRegistrationClient.validateOrSuggestDomain(tempDomainToRegister, successKey);
+        } catch (Exception e) {
+            String msg = "Failed to validate or suggest a domain related to :" +
+                    tempDomainToRegister + ".";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+
+    /**
+     * Generates a random captcha
+     *
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @return CaptchaInfoBean
+     * @throws UIException, if generating the random captcha fails.
+     */
+    public static CaptchaInfoBean generateRandomCaptcha(ServletConfig config,
+                                                        HttpSession session) throws UIException {
+        try {
+            TenantSelfRegistrationClient selfRegistrationClient =
+                    new TenantSelfRegistrationClient(config, session);
+            return selfRegistrationClient.generateRandomCaptcha();
+        } catch (Exception e) {
+            String msg = "Error in generating the captcha image.";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+
+    public static HttpServletRequest readIntermediateData(HttpServletRequest request, String data) {
+        try {
+            XMLStreamReader parser =
+                    XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(data));
+            StAXOMBuilder builder = new StAXOMBuilder(parser);
+            OMElement documentElement = builder.getDocumentElement();
+            Iterator it = documentElement.getChildElements();
+            while (it.hasNext()) {
+                OMElement element = (OMElement) it.next();
+                if ("admin".equals(element.getLocalName())) {
+                    request.setAttribute("admin", element.getText());
+                } else if ("firstname".equals(element.getText())) {
+                    request.setAttribute("firstname", element.getText());
+                } else if ("lastname".equals(element.getText())) {
+                    request.setAttribute("lastname", element.getText());
+                } else if ("email".equals(element.getLocalName())) {
+                    request.setAttribute("email", element.getText());
+                } else if ("tenantDomain".equals(element.getLocalName())) {
+                    request.setAttribute("tenantDomain", element.getText());
+                } else if ("confirmationKey".equals(element.getLocalName())) {
+                    request.setAttribute("confirmationKey", element.getText());
+                }
+            }
+        } catch (Exception e) {
+            log.error("Error parsing xml", e);
+        }
+        return request;
+    }
+
+    /**
+     * Resolves the correct domain name in the form of example.com from the user input domain name.
+     * Currently strips out "www."and white space. Can add more checks.
+     *
+     * @param domainNameUserInput the user input domain name
+     * @return the domain after removing (if entered) www. from the input.
+     */
+    public static String resolveDomainName(String domainNameUserInput) {
+        if (domainNameUserInput == null) {
+            String msg = "Provided domain name is null";
+            log.error(msg);
+            return "";
+        }
+        String domainName = domainNameUserInput.trim();
+        if (domainName.startsWith("www.")) {
+            domainName = domainName.substring(4);
+        }
+        return domainName;
+    }
+
+    /**
+     * A basic method to decode the encoded Stratos Service Name
+     *
+     * @param encodedStr Encoded Stratos Service Name
+     * @return Decoded Stratos Service name
+     */
+    private static String base64Decode(String encodedStr) {
+        String decodedStr = null;
+        // Check whether this value is null(not set) or set to "null" which is also possible.
+        if (encodedStr != null && !"null".equals(encodedStr)) {
+            decodedStr = new String(Base64.decode(encodedStr));
+        }
+        return decodedStr;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/META-INF/component.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/META-INF/component.xml b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/META-INF/component.xml
new file mode 100644
index 0000000..aa11e6b
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/META-INF/component.xml
@@ -0,0 +1,70 @@
+<!--
+ ~ 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.
+ -->
+<component xmlns="http://products.wso2.org/carbon">
+    <!-- sample menu configuration -->
+    <menus>
+        <menu>
+            <id>gaas_menu</id>
+            <i18n-key>gaas</i18n-key>
+            <i18n-bundle>org.wso2.carbon.register.ui.i18n.Resources</i18n-bundle>
+            <parent-menu></parent-menu>
+            <link>#</link>
+            <skip-authentication/>
+            <region>region1</region>
+            <order>2</order>
+            <style-class>home</style-class>
+        </menu>
+        <menu>
+            <id>gaas_register_org_menu</id>
+            <i18n-key>register.org.menu</i18n-key>
+            <i18n-bundle>org.wso2.carbon.register.ui.i18n.Resources</i18n-bundle>
+            <parent-menu>gaas_menu</parent-menu>
+            <link>../tenant-register/select_domain.jsp</link>
+            <region>region1</region>
+            <order>1</order>
+            <style-class>manage</style-class>
+            <icon>../tenant-register/images/signup-new-org.gif</icon>
+            <skip-authentication>
+                <skip-link>../tenant-register/self_registration_complete.jsp</skip-link>
+                <skip-link>../tenant-register/domain_availability_ajaxprocessor.jsp</skip-link>
+                <skip-link>../tenant-register/select_domain.jsp</skip-link>
+                <skip-link>../tenant-register/select_usage_plan.jsp</skip-link>
+                <skip-link>../tenant-register/success_register.jsp</skip-link>
+
+                <!-- the following files need to be placed in the validate-domain ui component,
+                 but since it has no menu, it had to be moved here -->
+                <skip-link>../validate-domain/validate_domain_not_logged_in.jsp</skip-link>
+                <skip-link>../validate-domain/validate_with_dns_ajaxprocessor.jsp</skip-link>
+                <skip-link>../validate-domain/validate_with_text_ajaxprocessor.jsp</skip-link>
+                <skip-link>../validate-domain/submit_validate_domain_ajaxprocessor.jsp</skip-link>
+
+                <!-- account-mgt stuff -->
+                <skip-link>../account-mgt/update_verifier.jsp</skip-link>
+                <skip-link>../email-verification/validator_ajaxprocessor.jsp</skip-link>
+                <skip-link>../email-verification/invalid_email.jsp</skip-link>
+                <skip-link>../account-mgt/update_verifier_redirector_ajaxprocessor.jsp</skip-link>
+
+                <!--payment stuff -->
+                <skip-link>../payment/registration_payment.jsp</skip-link>
+                <skip-link>../payment/registration_payment_completed.jsp</skip-link>
+            </skip-authentication>
+            <require-not-logged-in>true</require-not-logged-in>
+        </menu>
+    </menus>
+
+</component>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/org/apache/stratos/register/ui/i18n/JSResources.properties
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/org/apache/stratos/register/ui/i18n/JSResources.properties b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/org/apache/stratos/register/ui/i18n/JSResources.properties
new file mode 100644
index 0000000..c49c4b0
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/org/apache/stratos/register/ui/i18n/JSResources.properties
@@ -0,0 +1,6 @@
+password.mismatched=Passwords do not match.
+email.mismatched=The emails are mismatching.
+current.password.should.provided=You should provide the current password in order to change the password.
+password.length=Your password must be at least 6 characters long. Try again.
+domain.available=Domain is available to register.
+domain.unavailable=Sorry!. The Domain is already registered. Please choose a different domain.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/org/apache/stratos/register/ui/i18n/Resources.properties
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/org/apache/stratos/register/ui/i18n/Resources.properties b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/org/apache/stratos/register/ui/i18n/Resources.properties
new file mode 100644
index 0000000..b757c4f
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/org/apache/stratos/register/ui/i18n/Resources.properties
@@ -0,0 +1,62 @@
+submit.tenant=Submit Tenant
+domain=Tenant Domain
+domain.information=Domain Information
+terms.of.use=Terms of Use
+contact.details=Contact Details
+admin.username=Admin Username
+username=Username
+username.or.domain=Username/Domain
+current.admin.password=Current Admin Password
+new.admin.password=New Admin Password
+new.admin.password.repeat=New Admin Password (Repeat)
+admin.password=Admin Password
+admin.password.repeat=Admin Password (Repeat)
+govern.add_tenants.menu=Add New Tenant
+govern.view_tenants.menu=View Tenants
+overview=Overview
+tenants.list=Tenants List
+company.organization=Company/Organization
+admin.contact=Admin Contact
+edit=Edit
+multitenancy=Multitenancy
+added.successfully=You have successfully added a new tenant with domain:
+updated.successfully=You have successfully updated the tenant with domain:
+update.added.tenant=Update the just added/updated tenant
+update.tenant=Update Tenant
+add.new.tenant=Add a new tenant
+register.new.organization=Sign up your organization
+view.all.tenants=View all tenants
+tenant.admin=Tenant Admin
+tenant.description=Tenant Description
+admin.fullname=Full Name
+admin.firstname=First Name
+admin.lastname=Last Name
+admin.address=Address
+admin.email=Email
+admin.email.repeat=Email (Repeat)
+admin.telephone=Telephone
+admin.im=IM
+admin.url=URL
+self.registration=Registry Tenant
+gaas=Sign up
+register.org.menu=Sign up new organization
+gaas.register.a.new.tenant=Register A New Tenant
+active=Active
+theme.management=Theme Management
+word.verification=Word Verification
+captcha.message=Type the characters you see in the picture below.
+select.domain.menu=Sign up new organization
+select.domain.title=Select a domain for your organization
+password.reset=Password Reset
+password.reset.failed=Password Reset Attempt Failed
+verified.request.successfully=You have successfully verified your Password reset request.\nPls reset your password below.
+request.verification.failed=Password Reset Verification Failed. \nPls make sure you have clicked the correct link to reset your domain's admin password.
+accept.eula=I have read and accepted the terms in the license agreement above.
+usage.plan.information= Usage Plan Information
+select.usage.plan.for.tenant=Select Usage Plan For Tenant
+demo.package.price=$0 per month
+select.package.message=According to the selected plan, resources will be allocated for you. You can upgrade or downgrade your plan later according to your requirements. If you need more information on plans, click 'Pricing Info'.
+required.msg=All fields marked with an asterisk (<span class="required">*</span>) are required. 
+billing.currency=$
+redirect.to.paypal.msg1=You will be redirected to PayPal to make a registration payment of
+redirect.to.paypal.msg2=Do you wish to proceed?  
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/css/tenant-register.css
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/css/tenant-register.css b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/css/tenant-register.css
new file mode 100644
index 0000000..621c028
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/css/tenant-register.css
@@ -0,0 +1,78 @@
+body {
+	color:#111111;
+	font-size:0.75em;
+	font-size-adjust:none;
+	font-style:normal;
+	font-variant:normal;
+	font-weight:normal;
+	line-height:1.25em;
+	background-image: url(../images/body-bg.gif);
+	background-position: left top;
+	background-repeat: repeat-x;
+	margin: 0px;
+	padding: 0px;
+}
+
+div.clear {
+	clear:both;
+}
+p { }
+
+td { }
+
+a:link { }
+
+a:visited { }
+
+a:hover { }
+
+a:active { }
+
+div.features {
+	background-image: url(../images/features-bg.gif);
+	background-position: 39px 30px;
+	background-repeat: no-repeat;
+}
+div.feature {
+	float: left;
+	width: 221px;
+	margin-left: 39px;
+	margin-top: 30px;
+	padding: 20px;
+	text-align: left;
+}
+div.feature img {
+	float: left;
+	margin-right: 10px;
+	width: 64px;
+}
+div.feature h2 {
+	margin-top: 0px;
+	margin-bottom: 7px;
+	color: #0499CC;
+	font-size: 155%;
+	line-height: 110%;
+	font-weight: normal;
+	
+}
+div.feature p {
+	margin-top: 0px;
+	padding-top: 0px;
+}
+td.page-header-help a{
+    position:absolute;
+    right:20px;
+}
+div#middle div#workArea {
+    padding:0px;
+}
+.registration_help{
+    color:#555;
+    line-height:25px;
+}
+.toggle_container ,h2.trigger {
+    box-shadow: none;
+}
+.leftCol-med{
+    width:180px;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/aboutUsagePlans.html
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/aboutUsagePlans.html b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/aboutUsagePlans.html
new file mode 100644
index 0000000..791b867
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/aboutUsagePlans.html
@@ -0,0 +1,104 @@
+<!--
+ ~ 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.
+ -->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <title>Select Usage Plan For Tenant - User Guide</title>
+  <link href="../../admin/css/documentation.css" rel="stylesheet" type="text/css" media="all" />
+</head>
+
+<body>
+
+
+ <h1>Select Usage Plan For Tenant</h1>
+
+
+ <h2> <b> Usage Plans(Subscriptions)</b></h2>
+
+<p>
+    According to the usage plan that you selected you will get different volume of service and registry
+    bandwidths other services that available for tenants.By selecting right usage plan that suits
+    your requirements you can get maximum profit
+</p>
+
+
+<h2><b>Multitenancy Free</b></h2>
+<p>
+  This is the free usage plan.You will get limited amount of resources.This package is
+  best suite for evaluation and tests.
+</p>
+ <h2><b>Multitenancy Small</b></h2>
+<p>
+   This package is best suite for small business.
+</p>
+<h2><b>Multitenancy Medium</b></h2>
+<p>
+   This usage plan suites for medium scale business.You will get average amount of resources
+    with this package.
+</p>
+<h2><b>Multitenancy Large</b></h2>
+<p>
+   This is the premium usage plan.You will get maximum resources form this plan.
+   This is best suite to large scale business.
+</p>
+
+<p>
+
+   Usage Plan summery
+<table border="1">
+<tr>
+<td>Usage Plan Name</td>
+<td>Number Of Users</td>
+<td>Registry Bandwidth (Mb) </td>
+<td>Service BandWidth (Mb) </td>
+<td>Cost Per Month ($)</td>
+</tr>
+<tr>
+<td>Multitenancy Free</td>
+<td>5</td>
+<td>10</td>
+<td>10</td>
+<td>10</td>
+</tr>
+<tr>
+<td>Multitenancy Small</td>
+<td>10</td>
+<td>25</td>
+<td>25</td>
+<td>25</td>
+</tr>
+<tr>
+<td>Multitenancy Medium</td>
+<td>20</td>
+<td>100</td>
+<td>100</td>
+<td>100</td>
+</tr>
+<tr>
+<td>Multitenancy Large</td>
+<td>50</td>
+<td>200</td>
+<td>200</td>
+<td>200</td>
+</tr>
+</table> 
+<div><strong>Figure1: Usage Plan Summery Table</strong></div>
+</p>
+</body>
+
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/images/add-org.png
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/images/add-org.png b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/images/add-org.png
new file mode 100644
index 0000000..3d97bab
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/images/add-org.png differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/userguide.html
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/userguide.html b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/userguide.html
new file mode 100644
index 0000000..f97cf59
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/docs/userguide.html
@@ -0,0 +1,104 @@
+<!--
+ ~ 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.
+ -->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <title>Multitenancy Tenant Self Registration - User Guide</title>
+  <link href="../../admin/css/documentation.css" rel="stylesheet" type="text/css" media="all" />
+</head>
+
+<body>
+<h1>Tenant Self Registration</h1>
+
+<p style="font-size:small;">
+You can use this form to register an account for the domain of your organization. You can also check whether the domain is available to register here.
+</p>
+<p style="font-size:small;">
+Optionally you can choose to validate the domain, or can go ahead registering without validating the domain for the moment.
+</p>
+
+<p>
+<img src="images/add-org.png" alt="Register New Organization Form"/>
+<div><strong>Figure1: Register A New Organization Form</strong></div>
+</p>
+
+<p>
+
+<p style="font-size:small;">
+You need to provide the following information to register your organization.
+</p>
+
+
+<table border="1">
+    <thead style="font-size:small;">
+        <td>
+           <b> The Form Field </b>
+        </td>
+        <td >
+            <b>Description</b>
+        </td>
+    </thead>
+    <tbody style="font-size:small;">
+        <tr>
+            <td>Domain</td>
+            <td>Enter the domain name of your organization in here.</td>
+        </tr>
+        <tr>
+            <td>Admin Username</td>
+            <td>The username of the first admin account for your organization. You can use this account to login to all WSO2 Stratos services under your domain name. There
+            is a user management UI that you can access after you login to the system where you can add new users (including users under admin role), new roles.
+            </td>
+        </tr>
+        <tr>
+            <td>First Name</td>
+            <td>Your first name, which will be used to address you in the further communication and the notifications.</td>
+        </tr>
+        <tr>
+            <td>Last Name</td>
+            <td>Your last name.</td>
+        </tr>
+        <tr>
+            <td>Admin Password</td>
+            <td>The password of the startup admin account. You can change the password later from the user management UI.</td>
+        </tr>
+        <tr>
+            <td>Admin Password (Repeat)</td>
+            <td>Repeat the password you provided in the above field, so we can catch any typing mistake you made in there.</td>
+        </tr>
+        <tr>
+            <td>Email</td>
+            <td>Your email address. This email will be used to complete the registration process and to contact you for any further requirement.</td>
+        </tr>
+        <tr>
+            <td>Word Verification</td>
+            <td>Enter the letters shown in the above image in this text box. 
+        </tr>
+    </tbody>
+</table>
+
+</p>
+
+<p style="font-size:small;">
+Once you completed the registration, you will be sent an email notification with the account verification information. 
+</p>
+<p style="font-size:small;">
+After verifying your registration, you can log in to the account using the log in page.
+</p>
+</body>
+
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/domain_availability_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/domain_availability_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/domain_availability_ajaxprocessor.jsp
new file mode 100644
index 0000000..730d777
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/domain_availability_ajaxprocessor.jsp
@@ -0,0 +1,50 @@
+<!--
+ ~ 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.
+ -->
+<%@ page import="org.wso2.carbon.registry.core.RegistryConstants" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
+<%@ page import="org.wso2.carbon.registry.common.ui.UIException" %>
+<%@ page import="org.wso2.carbon.register.ui.utils.TenantConfigUtil" %>
+<%@ page import="java.util.Enumeration" %>
+<%@ page import="org.wso2.carbon.CarbonConstants" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<%
+try {
+    boolean domainAvailable = TenantConfigUtil.checkDomainAvailability(request, config, session);
+
+    if (domainAvailable) {
+    %>
+    ----DomainAvailable----
+    <%
+    }
+    else {
+    %>
+    ----DomainUnavailable----
+    <%
+    }
+} catch (UIException e) {
+
+%>
+    Error in checking the domain availability.
+    please retry the registration from the <a href="../tenant-register/select_domain.jsp">start</a>.
+<%
+}
+
+%>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/get_package_info_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/get_package_info_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/get_package_info_ajaxprocessor.jsp
new file mode 100644
index 0000000..fe7a6f6
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/get_package_info_ajaxprocessor.jsp
@@ -0,0 +1,39 @@
+<%--
+~ 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.
+--%>
+<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
+<%@ page import="org.json.JSONArray" %>
+<%@ page import="org.wso2.carbon.register.ui.clients.PackageInfoServiceClient" %>
+<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
+<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
+<%@ page import="org.wso2.carbon.CarbonConstants" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<%
+
+    String backendServerUrl = CarbonUIUtil.getServerURL(config.getServletContext(), session);
+    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
+    ConfigurationContext configContext =
+            (ConfigurationContext)config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
+
+    PackageInfoServiceClient client = new PackageInfoServiceClient(cookie, backendServerUrl,configContext);
+    JSONArray packageInfoArray = client.getBillingPackagesJsonArray();
+
+    out.write(packageInfoArray.toString());
+%>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/ajax-loader.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/ajax-loader.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/ajax-loader.gif
new file mode 100644
index 0000000..f2a1bc0
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/ajax-loader.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/body-bg.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/body-bg.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/body-bg.gif
new file mode 100644
index 0000000..5db1464
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/body-bg.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/button-back.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/button-back.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/button-back.gif
new file mode 100644
index 0000000..6a52e34
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/button-back.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/content-back-left.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/content-back-left.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/content-back-left.jpg
new file mode 100644
index 0000000..ebfe8ed
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/content-back-left.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/content-back.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/content-back.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/content-back.jpg
new file mode 100644
index 0000000..62b8da1
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/content-back.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/create-org-button.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/create-org-button.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/create-org-button.gif
new file mode 100644
index 0000000..b7e62a3
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/create-org-button.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-01-icon.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-01-icon.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-01-icon.gif
new file mode 100644
index 0000000..ff3ba26
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-01-icon.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-02-icon.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-02-icon.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-02-icon.gif
new file mode 100644
index 0000000..ee4cb66
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-02-icon.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-03-icon.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-03-icon.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-03-icon.gif
new file mode 100644
index 0000000..8f3c2a1
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/feature-03-icon.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/features-bg.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/features-bg.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/features-bg.gif
new file mode 100644
index 0000000..dd9e693
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/features-bg.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/footer.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/footer.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/footer.jpg
new file mode 100644
index 0000000..c617091
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/footer.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/forum.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/forum.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/forum.gif
new file mode 100644
index 0000000..e92779a
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/forum.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/header.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/header.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/header.jpg
new file mode 100644
index 0000000..4438a06
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/header.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/help.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/help.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/help.gif
new file mode 100644
index 0000000..43242c2
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/help.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/images.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/images.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/images.gif
new file mode 100644
index 0000000..94b46dc
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/images.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/issue-tracker.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/issue-tracker.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/issue-tracker.gif
new file mode 100644
index 0000000..9029c12
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/issue-tracker.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/logo.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/logo.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/logo.jpg
new file mode 100644
index 0000000..202360d
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/logo.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/mailing-list.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/mailing-list.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/mailing-list.gif
new file mode 100644
index 0000000..06d61e3
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/mailing-list.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/page-back.jpg
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/page-back.jpg b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/page-back.jpg
new file mode 100644
index 0000000..2e21b54
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/page-back.jpg differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/people.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/people.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/people.gif
new file mode 100644
index 0000000..edfa49b
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/people.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/services.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/services.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/services.gif
new file mode 100755
index 0000000..9883116
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/services.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/signup-new-org.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/signup-new-org.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/signup-new-org.gif
new file mode 100644
index 0000000..640a501
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/signup-new-org.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/thememgt.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/thememgt.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/thememgt.gif
new file mode 100644
index 0000000..e554e87
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/thememgt.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/user-guide.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/user-guide.gif b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/user-guide.gif
new file mode 100644
index 0000000..9342adc
Binary files /dev/null and b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/images/user-guide.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/init_payment_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/init_payment_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/init_payment_ajaxprocessor.jsp
new file mode 100755
index 0000000..d827f7c
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/init_payment_ajaxprocessor.jsp
@@ -0,0 +1,101 @@
+<!--
+ ~ 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.
+ -->
+<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
+<%@ page import="org.json.JSONArray"%>
+<%@ page import="org.wso2.carbon.CarbonConstants" %>
+<%@ page import="org.wso2.carbon.register.ui.clients.PackageInfoServiceClient" %>
+<%@ page import="org.wso2.carbon.stratos.common.util.CommonUtil" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
+<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
+<%@ page import="java.util.Collections" %>
+<%@ page import="java.util.Enumeration" %>
+<%@ page import="java.util.Iterator" %>
+<%@ page import="java.util.List" %>
+<%@ page import="java.util.Map" %>
+<%@ page import="org.json.JSONException" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+<carbon:jsi18n
+		resourceBundle="org.wso2.carbon.register.ui.i18n.JSResources"
+		request="<%=request%>" />
+<script type="text/javascript" src="../registry_common/js/registry_validation.js"></script>
+<script type="text/javascript" src="../registry_common/js/registry_common.js"></script>
+<script type="text/javascript" src="../ajax/js/prototype.js"></script>
+<script type="text/javascript" src="js/register_config.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.form.js"></script>
+<script type="text/javascript" src="../dialog/js/jqueryui/jquery-ui.min.js"></script>
+<%
+    String tenantDomain = request.getParameter("domain");
+    // The actual usage plan the tenant selects in select_usage_plan.jsp
+    String selectedUsagePlan = request.getParameter("selectedUsagePlan");
+    session.setAttribute("selectedUsagePlan", selectedUsagePlan);
+    
+    String backendServerUrl = CarbonUIUtil.getServerURL(config.getServletContext(), session);
+    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
+    ConfigurationContext configContext =
+            (ConfigurationContext)config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
+
+    PackageInfoServiceClient client = new PackageInfoServiceClient(cookie, backendServerUrl,configContext);
+    JSONArray packageInfoArray = client.getBillingPackagesJsonArray();
+    String amount = "0";
+
+    for (int i = 0; i < packageInfoArray.length(); i++) {
+        try {
+            if (packageInfoArray.getJSONObject(i).getString("name").equals(selectedUsagePlan)) {
+                amount = packageInfoArray.getJSONObject(i).getString("subscriptionCharge");
+            }
+        } catch (JSONException e) {
+            //
+        }
+    }
+
+    String successUrl;
+    String paypalUrl = CommonUtil.getStratosConfig().getPaypalUrl();
+    String adminConsoleURL = CarbonUIUtil.getAdminConsoleURL(request);
+    adminConsoleURL = adminConsoleURL.substring(0, adminConsoleURL.indexOf("carbon"));
+     successUrl = adminConsoleURL + "carbon/payment/registration_payment.jsp";
+    String cancelUrl = adminConsoleURL + "carbon/admin/login.jsp";
+%>
+
+<script type="text/javascript">
+
+
+        var successUrl = '<%=successUrl%>';
+        var cancelUrl = '<%=cancelUrl%>';
+        var amount = '<%=amount%>';
+        var tenantDomain = '<%=tenantDomain%>';
+        jQuery.ajax({
+            type: 'GET',
+            url: '../payment/setEC-ajaxprocessor.jsp',
+            data: 'successUrl=' + successUrl + '&cancelUrl=' + cancelUrl + '&amount=' + amount + '&tenantDomain=' + tenantDomain,
+            dataType: 'json',
+            async: false,
+            success: function(msg) {
+                var resp = msg;
+                if(resp.ack=='Success'){
+                    location.href = '<%=paypalUrl%>' + resp.token;
+                }else{
+                    location.href = cancelUrl;
+                }
+            },
+            error:function () {
+                location.href = cancelUrl;
+            }
+        });
+</script>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/js/register_config.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/js/register_config.js b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/js/register_config.js
new file mode 100644
index 0000000..fdcd24e
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/js/register_config.js
@@ -0,0 +1,147 @@
+function addTenant(isPublicCloud) {
+    var domain = document.getElementById('domain');
+    var reason = "";
+    var addTenantForm = document.getElementById('addTenantForm');
+    var adminPassword = "";
+    var adminPasswordRepeat = "";
+    var email = "";
+    var firstname = document.getElementById('admin-firstname');
+    var lastname = document.getElementById('admin-lastname');
+    var adminName = document.getElementById('admin');
+    adminPassword = document.getElementById('admin-password');
+    adminPasswordRepeat = document.getElementById('admin-password-repeat');
+    email = document.getElementById('admin-email');
+
+    // the domain validation part is moved to the select_domain.js
+
+    var reason = validateEmpty(domain, "Domain");
+    if (reason == "") {
+        reason += checkDomain(domain, isPublicCloud);
+    }
+    if (reason == "") {
+        reason += validateEmpty(firstname, "First Name");
+    }
+    if (reason == "") {
+        reason += validateIllegal(firstname, "First Name");
+    }
+    if (reason == "") {
+        reason += validateEmpty(lastname, "Last Name");
+    }
+    if (reason == "") {
+        reason += validateIllegal(lastname, "Last Name");
+    }
+    if (reason == "") {
+        reason += validateEmpty(adminName, "Admin Username");
+    }
+    if (reason == "") {
+        reason += validateIllegal(adminName, "Admin Username");
+    }
+    if (reason == "") {
+        reason += validateUsername(adminName);
+    }
+    if (reason == "") {
+        reason += validateEmpty(adminPassword, "Admin Password");
+    }
+    if (reason == "") {
+        reason += validateAdminPassword(adminPassword);
+    }
+    if (reason == "") {
+        reason += validateEmpty(adminPasswordRepeat, "Admin Password (Repeat)");
+    }
+    if (reason == "") {
+        reason += validateEmpty(email, "Email");
+    }
+    if (reason == "") {
+        reason += validateEmail(email);
+    }
+    if (reason == "") {
+        if (adminPassword.value != adminPasswordRepeat.value) {
+            reason += jsi18n["password.mismatched"];
+        }
+        if (adminPassword.value.length < 6) {
+            reason += jsi18n["password.length"];
+        }
+    }
+    if (reason != "") {
+        CARBON.showWarningDialog(reason);
+        document.getElementbyId("submit-button").disabled = false;
+        document.getElementById('waitMessage').style.display = 'none';
+        return;
+    }
+    addTenantForm.submit();
+}
+
+function validateAdminPassword(fld) {
+    var error = "";
+
+    if (fld.value == "") {
+        error = org_wso2_carbon_registry_common_ui_jsi18n["no.password"] + "<br />";
+    } /* else if ((fld.value.length < 3) || (fld.value.length > 15)) {
+     error = org_wso2_carbon_registry_common_ui_jsi18n["wrong.password"] + "<br />";
+     } else if (illegalChars.test(fld.value)) {
+     error = org_wso2_carbon_registry_common_ui_jsi18n["illegal.password"] + "<br />";
+     } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
+     error = "The password must contain at least one numeral.<br />";
+     } */ else {
+        fld.style.background = 'White';
+    }
+    return error;
+}
+
+function activationChanged(cbox, domain) {
+    if (!cbox.checked) {
+        CARBON.showConfirmationDialog("Are you sure you want to deactivate the domain: " +
+                                      domain + ".", function() {
+            var submitForm = document.getElementById(domain + "_form");
+            submitForm.submit();
+        }, function() {
+            cbox.checked = "on";
+        });
+    } else {
+        var submitForm = document.getElementById(domain + "_form");
+        submitForm.submit();
+    }
+}
+
+function fillAdminValue() {
+    var adminValue = document.getElementById('adminValue');
+    var domain = document.getElementById('domain');
+
+    var reason = validateIllegal(domain, "Domain");
+    if (reason != "") {
+        CARBON.showErrorDialog(reason);
+        adminValue.innerHTML = '';
+        return;
+    }
+
+    if (domain.value == "") {
+        adminValue.innerHTML = '' + domain.value;
+    }
+    else {
+        adminValue.innerHTML = '@' + domain.value;
+    }
+}
+
+function showregistrationfail() {
+    var error = "";
+    CARBON.showWarningDialog(error);
+}
+
+var kaptchaImgUrl;
+function showKaptcha(kaptchaImgUrlArg) {
+    kaptchaImgUrl = kaptchaImgUrlArg;
+    var kaptchaImgDiv = document.getElementById("kaptchaImgDiv");
+    kaptchaImgDiv.innerHTML = "<img src='../tenant-register/images/ajax-loader.gif' alt='busy'/>";
+    setTimeout("showKaptchaTimely()", 4000);
+}
+
+function showKaptchaTimely() {
+    var kaptchaImgDiv = document.getElementById("kaptchaImgDiv");
+    kaptchaImgDiv.innerHTML = "<img src='" + kaptchaImgUrl + "' alt='If you can not see the captcha " +
+                              "image please refresh the page or click the link again.'/>";
+}
+
+function activateSubmit(fld) {
+    var submitButton = document.getElementById('submit-button');
+    submitButton.disabled = !fld;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/js/select_domain.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/js/select_domain.js b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/js/select_domain.js
new file mode 100644
index 0000000..592e308
--- /dev/null
+++ b/components/org.apache.stratos.tenant.registration.ui/2.1.1/src/main/resources/web/tenant-register/js/select_domain.js
@@ -0,0 +1,75 @@
+function checkDomainAvailability(isPublicCloud) {
+    var domain = document.getElementById('domain');
+
+    var reason = validateEmpty(domain, "Domain");
+    if (reason == "") {
+        reason += checkDomain(domain, isPublicCloud);
+    }
+
+    if(reason != "") {
+        CARBON.showWarningDialog(reason);
+        return false;
+    }
+
+    var busyCheck = document.getElementById("busyCheck");
+    busyCheck.innerHTML = "<img src=\"images/ajax-loader.gif\"/>";
+    
+    var domain_confirmation_div = document.getElementById("domain-confirmation-msg");
+    
+    new Ajax.Request('../tenant-register/domain_availability_ajaxprocessor.jsp',
+    {
+        method:'post',
+        parameters: {domain: domain.value},
+
+        onSuccess: function(transport) {
+            busyCheck.innerHTML = "";
+            var returnValue = transport.responseText;
+            if (returnValue.search(/----DomainAvailable----/) == -1) {
+                domain_confirmation_div.style.color = "#f00";
+                domain_confirmation_div.innerHTML = jsi18n["domain.unavailable"]; 
+                result = false;
+            } else {
+                domain_confirmation_div.style.color = "#058000";
+                domain_confirmation_div.innerHTML = jsi18n["domain.available"];
+                result = true;
+            }
+        },
+
+        onFailure: function(transport){
+            busyCheck.innerHTML = "";
+        }
+    });
+}
+
+function clearDomainConfirmationMsg() {
+    var domain_confirmation_div = document.getElementById("domain-confirmation-msg");
+    domain_confirmation_div.innerHTML = "";
+}
+
+
+function checkDomain(fld, isPublicCloudSetup)
+{
+    var error = "";
+    var domain = fld.value;
+    var lastIndexOfDot = domain.lastIndexOf(".");
+    var indexOfDot = domain.indexOf(".");
+    var extension = domain.substring(lastIndexOfDot, domain.length);
+
+    var illegalChars = /([^a-zA-Z0-9\._\-])/; // allow only letters and numbers . - _and period
+    if (extension.indexOf("-trial") >= 0 || extension.indexOf("-unverified") >= 0) {
+        // we are not allowing to create a domain with -trial or -unverified is in the extension
+        error = "The domain name you entered is not valid. Please enter a valid domain name.";
+    }
+    else if (isPublicCloudSetup && (lastIndexOfDot <= 0)) {
+        error = "Invalid domain: " + domain + ". You should have an extension to your domain.";
+    }
+    else if (indexOfDot == 0) {
+        error = "Invalid domain, starting with '.'";
+    }
+    else if (illegalChars.test(fld.value)) {
+        error = "The domain only allows letters, numbers, '.', '-' and '_'. <br />";
+    } else {
+        fld.style.background = 'White';
+    }
+    return error;
+}


[6/7] Tenat-mgt refactoring

Posted by is...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/clients/PackageInfoServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/clients/PackageInfoServiceClient.java b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/clients/PackageInfoServiceClient.java
new file mode 100644
index 0000000..39dbf21
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/clients/PackageInfoServiceClient.java
@@ -0,0 +1,79 @@
+package org.apache.stratos.tenant.mgt.ui.clients;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.stratos.common.packages.stub.PackageInfoServiceStub;
+import org.wso2.carbon.stratos.common.packages.stub.PackageInfo;
+
+/**
+ * PackageInfoService client
+ */
+public class PackageInfoServiceClient {
+
+    private static Log log = LogFactory.getLog(PackageInfoServiceClient.class);
+
+    private PackageInfoServiceStub stub;
+    private String epr;
+
+    public PackageInfoServiceClient(
+            String cookie, String backendServerURL, ConfigurationContext configContext)
+            throws Exception {
+
+        epr = backendServerURL + "PackageInfoService";
+
+        try {
+            stub = new PackageInfoServiceStub(configContext, epr);
+
+            ServiceClient client = stub._getServiceClient();
+            Options option = client.getOptions();
+            option.setManageSession(true);
+            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate PackageInfoService client. " + axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new RegistryException(msg, axisFault);
+        }
+    }
+
+    public PackageInfo[] getBillingPackages() throws Exception{
+
+        try {
+            return stub.getPackageInfos();
+        } catch (Exception e) {
+            String msg = "Failed to get package information: " + e.getMessage();
+            log.error(msg, e);
+            throw new Exception(msg,e);
+        }
+    }
+
+    public JSONArray getBillingPackagesJsonArray() throws Exception{
+
+        try{
+            PackageInfo[] packageInfoArray = stub.getPackageInfos();
+            JSONArray jsonPackageInfoArray = new JSONArray();
+            for(PackageInfo packageInfo : packageInfoArray){
+                JSONObject packageInfoObj = new JSONObject();
+                packageInfoObj.put("name", packageInfo.getName());
+                int subscriptionCharge = packageInfo.getSubscriptionCharge();
+                //TODO https://wso2.org/jira/browse/STRATOS-1819
+                StringBuffer charge = new StringBuffer("$" + subscriptionCharge );
+                packageInfoObj.put("subscriptionCharge", charge.toString());
+                jsonPackageInfoArray.put(packageInfoObj);
+            }
+            return jsonPackageInfoArray;
+        }catch(Exception e){
+            String msg = "Failed to get package information: " + e.getMessage();
+            log.error(msg, e);
+            throw new Exception(msg,e);
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/clients/TenantServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/clients/TenantServiceClient.java b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/clients/TenantServiceClient.java
new file mode 100644
index 0000000..2801b08
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/clients/TenantServiceClient.java
@@ -0,0 +1,120 @@
+/*
+*  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.ui.clients;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.CarbonConstants;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.tenant.mgt.stub.TenantMgtAdminServiceStub;
+import org.wso2.carbon.tenant.mgt.stub.beans.xsd.PaginatedTenantInfoBean;
+import org.wso2.carbon.tenant.mgt.stub.beans.xsd.TenantInfoBean;
+import org.wso2.carbon.ui.CarbonUIUtil;
+import org.wso2.carbon.utils.ServerConstants;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpSession;
+
+/**
+ * Tenant Service Client of tenant.mgt.ui
+ */
+public class TenantServiceClient {
+    private static final Log log = LogFactory.getLog(TenantServiceClient.class);
+
+    private TenantMgtAdminServiceStub stub;
+
+    public TenantServiceClient(String cookie, String backendServerURL,
+                               ConfigurationContext configContext) throws RegistryException {
+
+        String epr = backendServerURL + "TenantMgtAdminService";
+
+        try {
+            stub = new TenantMgtAdminServiceStub(configContext, epr);
+
+            ServiceClient client = stub._getServiceClient();
+            Options option = client.getOptions();
+            option.setManageSession(true);
+            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate AddServices service client. " + axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new RegistryException(msg, axisFault);
+        }
+    }
+
+    public TenantServiceClient(ServletConfig config, HttpSession session)
+            throws RegistryException {
+
+        String cookie = (String)session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
+        String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
+        ConfigurationContext configContext = (ConfigurationContext) config.
+                getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
+        String epr = backendServerURL + "TenantMgtAdminService";
+
+        try {
+            stub = new TenantMgtAdminServiceStub(configContext, epr);
+
+            ServiceClient client = stub._getServiceClient();
+            Options option = client.getOptions();
+            option.setManageSession(true);
+            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate Add Services service client. " + axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new RegistryException(msg, axisFault);
+        }
+    }
+
+    public void addTenant(TenantInfoBean tenantInfoBean) throws Exception {
+        stub.addTenant(tenantInfoBean);
+    }
+
+    public TenantInfoBean[] retrieveTenants() throws Exception {
+        return stub.retrieveTenants();
+    }
+
+    public PaginatedTenantInfoBean retrievePaginatedTenants(int pageNumber) throws Exception {
+        return stub.retrievePaginatedTenants(pageNumber);
+    }
+    
+    public PaginatedTenantInfoBean retrievePaginatedPartialSearchTenants(String domain,int pageNumber) throws Exception {
+        return stub.retrievePaginatedPartialSearchTenants(domain,pageNumber);
+    }
+    
+    public TenantInfoBean getTenant(String domainName) throws Exception {
+        return stub.getTenant(domainName);
+    }
+
+    public void updateTenant(TenantInfoBean tenantInfoBean) throws Exception {
+        stub.updateTenant(tenantInfoBean);
+    }
+
+    public void activateTenant(String domainName) throws Exception {
+        stub.activateTenant(domainName);
+    }
+
+    public void deactivateTenant(String domainName) throws Exception {
+        stub.deactivateTenant(domainName);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/utils/TenantMgtUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/utils/TenantMgtUtil.java b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/utils/TenantMgtUtil.java
new file mode 100644
index 0000000..7d06f16
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/ui/utils/TenantMgtUtil.java
@@ -0,0 +1,217 @@
+/*
+ *  Copyright (c) 2005-2008, 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.ui.utils;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.tenant.mgt.stub.beans.xsd.TenantInfoBean;
+import org.apache.stratos.tenant.mgt.ui.clients.TenantServiceClient;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.util.Calendar;
+
+/**
+ * Utility methods for tenant.mgt.ui
+ */
+public class TenantMgtUtil {
+    private static final Log log = LogFactory.getLog(TenantMgtUtil.class);
+
+    /**
+     * Super admin Adds a tenant
+     *
+     * @param request HttpServletRequest
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @throws Exception , if error in adding the tenant
+     */
+    public static void addTenantConfigBean(HttpServletRequest request, ServletConfig config,
+                                           HttpSession session) throws Exception {
+        TenantInfoBean tenantInfoBean = new TenantInfoBean();
+
+        try {
+            tenantInfoBean.setAdmin(request.getParameter("admin"));
+            tenantInfoBean.setFirstname(request.getParameter("admin-firstname"));
+            tenantInfoBean.setLastname(request.getParameter("admin-lastname"));
+            tenantInfoBean.setAdminPassword(request.getParameter("admin-password"));
+            tenantInfoBean.setTenantDomain(request.getParameter("domain"));
+            tenantInfoBean.setEmail(request.getParameter("admin-email"));
+            tenantInfoBean.setUsagePlan(request.getParameter("usage-plan-name"));
+            tenantInfoBean.setCreatedDate(Calendar.getInstance());
+            TenantServiceClient serviceClient = new TenantServiceClient(config, session);
+            serviceClient.addTenant(tenantInfoBean);
+            
+        } catch (Exception e) {
+            String msg = "Failed to add tenant config. tenant-domain: "
+                    + tenantInfoBean.getTenantDomain() + ", " + "tenant-admin: "
+                    + tenantInfoBean.getAdmin() + ".";
+            log.error(msg, e);
+            throw new Exception(msg, e);
+        }
+    }
+
+    /**
+     * Super admin Updates a tenant
+     *
+     * @param request HttpServletRequest
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @throws Exception , if error in updating the tenant
+     */
+    public static void updateTenantConfigBean(HttpServletRequest request, ServletConfig config,
+                                              HttpSession session) throws Exception {
+        TenantInfoBean tenantInfoBean = new TenantInfoBean();
+
+        try {
+            String tenantIdStr = request.getParameter("tenantId");
+            int tenantId;
+            try {
+                tenantId = Integer.parseInt(tenantIdStr);
+            } catch (Exception e) {
+                String msg = "Error in converting tenant id: " + tenantIdStr + " to a number.";
+                log.error(msg);
+                throw new Exception(msg, e);
+            }
+            tenantInfoBean.setTenantId(tenantId);
+            tenantInfoBean.setAdmin(request.getParameter("admin"));
+            tenantInfoBean.setFirstname(request.getParameter("admin-firstname"));
+            tenantInfoBean.setLastname(request.getParameter("admin-lastname"));
+            tenantInfoBean.setAdminPassword(request.getParameter("admin-password"));
+            tenantInfoBean.setTenantDomain(request.getParameter("domain"));
+            tenantInfoBean.setEmail(request.getParameter("admin-email"));
+            tenantInfoBean.setUsagePlan(request.getParameter("usage-plan-name"));
+            TenantServiceClient serviceClient = new TenantServiceClient(config, session);
+            serviceClient.updateTenant(tenantInfoBean);
+            //UsagePlanClient usagePlanClient = new UsagePlanClient(config, session);
+            //update usage plan(subscription) per tenant
+            //usagePlanClient.updateUsagePlan(tenantInfoBean);
+        } catch (Exception e) {
+            String msg = "Failed to update the tenant config. tenant-domain: "
+                    + tenantInfoBean.getTenantDomain() + ", " + "tenant-admin: "
+                    + tenantInfoBean.getAdmin() + ".";
+            log.error(msg, e);
+            throw new Exception(msg, e);
+        }
+    }
+
+    /**
+     * Super admin gets all the tenant
+     *
+     * @param request HttpServletRequest
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @return TenantInfoBean[] - Array of tenants
+     * @throws Exception , if getting the tenant information failed.
+     */
+    public static TenantInfoBean[] getTenants(HttpServletRequest request, ServletConfig config,
+                                              HttpSession session) throws Exception {
+
+        try {
+
+            TenantServiceClient serviceClient = new TenantServiceClient(config, session);
+            return serviceClient.retrieveTenants();
+        } catch (Exception e) {
+            String msg = "Failed to get the minimum information bean of tenants. ";
+            log.error(msg, e);
+            throw new Exception(msg, e);
+        }
+    }
+
+    /**
+     * Super admin gets a particular tenant
+     *
+     * @param request HttpServletRequest
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @return TenantInfoBean - for a tenant
+     * @throws Exception , if error in getting the tenant
+     */
+    public static TenantInfoBean getTenant(HttpServletRequest request, ServletConfig config,
+                                           HttpSession session) throws Exception {
+        String tenantDomain = "";
+        try {
+            tenantDomain = request.getParameter("domain");
+            TenantServiceClient serviceClient = new TenantServiceClient(config, session);
+            TenantInfoBean tenantBean=serviceClient.getTenant(tenantDomain);
+            return tenantBean;
+        } catch (Exception e) {
+            String msg = "Failed to get existing details of the tenant:" + tenantDomain;
+            log.error(msg, e);
+            throw new Exception(msg, e);
+        }
+    }
+
+    /**
+     * Super admin activates a tenant
+     *
+     * @param request HttpServletRequest
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @throws Exception , if failed to activate the tenant.
+     */
+    public static void activateTenant(HttpServletRequest request, ServletConfig config,
+                                      HttpSession session) throws Exception {
+        String tenantDomain = "";
+        try {
+            tenantDomain = request.getParameter("activate.domain");
+            TenantServiceClient serviceClient = new TenantServiceClient(config, session);
+            serviceClient.activateTenant(tenantDomain);
+        } catch (Exception e) {
+            String msg = "Failed to activate the tenant:" + tenantDomain;
+            log.error(msg, e);
+            throw new Exception(msg, e);
+        }
+    }
+
+    /**
+     * Super admin deactivates a tenant
+     *
+     * @param request HttpServletRequest
+     * @param config  ServletConfig
+     * @param session HttpSession
+     * @throws Exception , if failed to deactivate the tenant
+     */
+    public static void deactivateTenant(HttpServletRequest request, ServletConfig config,
+                                        HttpSession session) throws Exception {
+        String tenantDomain = "";
+        try {
+            tenantDomain = request.getParameter("activate.domain");
+            TenantServiceClient serviceClient = new TenantServiceClient(config, session);
+            serviceClient.deactivateTenant(tenantDomain);
+        } catch (Exception e) {
+            String msg = "Failed to deactivate the tenant:" + tenantDomain;
+            log.error(msg, e);
+            throw new Exception(msg, e);
+        }
+    }
+
+    /**
+     * This is used to avoid xss attacks
+     *
+     * @param text the text
+     * @return the text encoding '<' and '>' elements
+     */
+    public static String removeHtmlElements(String text) {
+        if (text == null) {
+            return null;
+        }
+        return text.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/META-INF/component.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/META-INF/component.xml b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/META-INF/component.xml
new file mode 100644
index 0000000..87fc5af
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/META-INF/component.xml
@@ -0,0 +1,61 @@
+<!--
+ ~ 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.
+ -->
+<component xmlns="http://products.wso2.org/carbon">
+    <!-- sample menu configuration -->
+    <menus>
+        <menu>
+            <id>multitenancy_menu</id>
+            <i18n-key>multitenancy</i18n-key>
+            <i18n-bundle>org.wso2.carbon.tenant.mgt.ui.i18n.Resources</i18n-bundle>
+            <parent-menu>configure_menu</parent-menu>
+            <link>#</link>
+            <region>region1</region>
+            <order>60</order>
+            <style-class>home</style-class>
+            <icon>../tenant-mgt/images/multi_tenancy.png</icon>
+            <require-super-tenant>true</require-super-tenant>
+        </menu>
+        <menu>
+            <id>govern_add_tenants_menu</id>
+            <i18n-key>govern.add_tenants.menu</i18n-key>
+            <i18n-bundle>org.wso2.carbon.tenant.mgt.ui.i18n.Resources</i18n-bundle>
+            <parent-menu>multitenancy_menu</parent-menu>
+            <link>../tenant-mgt/add_tenant.jsp</link>
+            <region>region1</region>
+            <order>1</order>
+            <style-class>manage-configuration</style-class>
+            <icon>../tenant-mgt/images/services.gif</icon>
+            <require-permission>/permission/protected/manage/modify/tenants</require-permission>
+            <require-super-tenant>true</require-super-tenant>
+        </menu>
+        <menu>
+            <id>govern_view_tenants_menu</id>
+            <i18n-key>govern.view_tenants.menu</i18n-key>
+            <i18n-bundle>org.wso2.carbon.tenant.mgt.ui.i18n.Resources</i18n-bundle>
+            <parent-menu>multitenancy_menu</parent-menu>
+            <link>../tenant-mgt/view_tenants.jsp</link>
+            <region>region1</region>
+            <order>2</order>
+            <style-class>manage</style-class>
+            <icon>../tenant-mgt/images/services1.gif</icon>
+            <require-permission>/permission/protected/manage/monitor/tenants</require-permission>
+            <require-super-tenant>true</require-super-tenant>
+        </menu>
+    </menus>
+
+</component>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/org/apache/stratos/tenant/mgt/ui/i18n/JSResources.properties
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/org/apache/stratos/tenant/mgt/ui/i18n/JSResources.properties b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/org/apache/stratos/tenant/mgt/ui/i18n/JSResources.properties
new file mode 100644
index 0000000..05d7817
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/org/apache/stratos/tenant/mgt/ui/i18n/JSResources.properties
@@ -0,0 +1,4 @@
+password.mismatched=Passwords do not match.
+email.mismatched=The emails are mismatching.
+current.password.should.provided=You should provide the current password in order to change the password.
+password.length=Your password must be at least 6 characters long. Try again.
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/org/apache/stratos/tenant/mgt/ui/i18n/Resources.properties
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/org/apache/stratos/tenant/mgt/ui/i18n/Resources.properties b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/org/apache/stratos/tenant/mgt/ui/i18n/Resources.properties
new file mode 100644
index 0000000..afb8d02
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/org/apache/stratos/tenant/mgt/ui/i18n/Resources.properties
@@ -0,0 +1,56 @@
+submit.tenant=Submit Tenant
+domain=Domain
+tenant.id=Tenant ID
+activate.deactivate=Activation Status
+deactivate.account.msg=This tenant is active. You can deactivate this tenant from here.
+activate.account.msg=This tenant is inactive. You can activate this tenant from here.
+deactivate.account.btn=Deactivate
+activate.account.btn=Activate
+error.deactivating.activating.tenant=Error occurred in changing the activation status of the tenant.
+domain.information=Domain Information
+contact.details=Contact Details
+admin.username=Admin Username
+current.admin.password=Current Admin Password
+new.admin.password=New Admin Password
+new.admin.password.repeat=New Admin Password (Repeat)
+admin.password=Admin Password
+admin.password.repeat=Admin Password (Repeat)
+govern.add_tenants.menu=Add New Tenant
+govern.view_tenants.menu=View Tenants
+overview=Overview
+tenants.list=Tenants List
+company.organization=Company/Organization
+admin.contact=Admin Contact
+edit=Edit
+multitenancy=Multitenancy
+added.successfully=You have successfully added a new tenant with domain:
+updated.successfully=You have successfully updated the tenant with domain:
+update.added.tenant=Update the just added/updated tenant
+update.tenant=Update Tenant
+add.new.tenant=Add a new tenant
+register.new.organization=Register A New Organization
+view.all.tenants=View all tenants
+tenant.admin=Tenant Admin
+tenant.description=Tenant Description
+admin.fullname=Full Name
+admin.firstname=First Name
+admin.lastname=Last Name
+admin.address=Address
+admin.email=Email
+admin.telephone=Telephone
+admin.im=IM
+admin.url=URL
+self.registration=Registry Tenant
+gaas=GaaS
+gaas.register.a.new.tenant=Register A New Tenant
+active=Active
+theme.management=Theme Management
+word.verification=Word Verification
+captcha.message=Type the characters you see in the picture below.
+created.date=Created Date
+enter.tenant.domain=Enter the Tenant Domain
+accept.eula=I have read and accepted the terms in the license agreement above.
+usage.plan.information= Usage Plan Information
+select.usage.plan.for.tenant=Select Usage Plan For Tenant
+select.package.message=According to the selected plan, resources will be allocated to you.\n You can update or downgrade your plan later \n according to your requirements.
+no.tenants.available=There are no tenants available
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/activate_tenant_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/activate_tenant_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/activate_tenant_ajaxprocessor.jsp
new file mode 100644
index 0000000..325474b
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/activate_tenant_ajaxprocessor.jsp
@@ -0,0 +1,57 @@
+<!--
+ ~ Copyright (c) 2005-2011, 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.
+ -->
+<%@ page import="org.wso2.carbon.tenant.mgt.ui.clients.TenantServiceClient" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<script type="text/javascript" src="../admin/js/jquery.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.form.js"></script>
+<script type="text/javascript" src="../dialog/js/jqueryui/jquery-ui.min.js"></script>
+
+<%--<carbon:jsi18n--%>
+		<%--resourceBundle="org.wso2.carbon.tenant.mgt.ui.i18n.JSResources"--%>
+		<%--request="<%=request%>" />--%>
+
+<div id="middle">
+<%
+    String error = "Error in updating the tenant activation status.";
+    String tenantDomain = "";
+    Boolean activated = (Boolean)session.getAttribute("isActivatedTenant");
+
+    TenantServiceClient serviceClient = new TenantServiceClient(config, session);
+
+    try {
+        tenantDomain = request.getParameter("activatingDomain");
+
+        if(activated){
+            serviceClient.deactivateTenant(tenantDomain);
+        } else if (!activated){
+            serviceClient.activateTenant(tenantDomain);
+        }
+
+        response.sendRedirect("../tenant-mgt/view_tenants.jsp");
+
+    } catch (Exception e) {
+            CarbonUIMessage uiMsg = new CarbonUIMessage(CarbonUIMessage.ERROR, e.getMessage(), e);
+            request.setAttribute(CarbonUIMessage.ID, uiMsg);
+                 %>
+                <jsp:forward page="../admin/error.jsp"/>
+                 <%
+             return;
+    }
+%>
+    </div>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/add_tenant.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/add_tenant.jsp b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/add_tenant.jsp
new file mode 100644
index 0000000..c01d47a
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/add_tenant.jsp
@@ -0,0 +1,386 @@
+<!--
+~ 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.
+-->
+<%@ page import="org.wso2.carbon.stratos.common.util.CommonUtil" %>
+<%@ page import="org.wso2.carbon.tenant.mgt.stub.beans.xsd.TenantInfoBean" %>
+<%@ page import="org.wso2.carbon.tenant.mgt.ui.utils.TenantMgtUtil" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
+<%@ page import="org.wso2.carbon.base.ServerConfiguration" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<carbon:jsi18n
+        resourceBundle="org.wso2.carbon.tenant.mgt.ui.i18n.JSResources"
+        request="<%=request%>"/>
+<%
+    String domainName = request.getParameter("domain");
+    String firstname = "";
+    String lastname = "";
+    String admin = "";
+    String usagePlan = "";
+    boolean isActive = false;
+    int tenantId = -1;
+    String error1 = "Tenant with the domain : " + domainName + " doesn't exist.";
+    boolean isUpdating = false;
+    boolean isPublicCloud = CommonUtil.isPublicCloudSetup();
+    String isCloudDeployment =  ServerConfiguration.getInstance().getFirstProperty("IsCloudDeployment");
+    String email = "";
+    if (domainName != null && !domainName.equals("")) {
+        try {
+            TenantInfoBean infoBean = TenantMgtUtil.getTenant(request, config, session);
+            admin = infoBean.getAdmin();
+            tenantId = infoBean.getTenantId();
+            email = infoBean.getEmail();
+            firstname = infoBean.getFirstname();
+            lastname = infoBean.getLastname();
+            isActive = infoBean.getActive();
+            usagePlan = infoBean.getUsagePlan();
+            isUpdating = true;
+            session.setAttribute("isActivatedTenant", isActive);
+        } catch (Exception e) {
+            CarbonUIMessage uiMsg = new CarbonUIMessage(CarbonUIMessage.ERROR, e.getMessage(), e);
+            request.setAttribute(CarbonUIMessage.ID, uiMsg);
+%>
+<jsp:forward page="../admin/error.jsp"/>
+<%
+            return;
+        }
+    }
+
+    if (domainName == null) {
+        domainName = "";
+    }
+    if (firstname == null) {
+        firstname = admin;
+    }
+    if (lastname == null) {
+        lastname = "";
+    }
+%>
+
+<fmt:bundle basename="org.wso2.carbon.tenant.mgt.ui.i18n.Resources">
+<carbon:breadcrumb
+        label="govern.add_tenants.menu"
+        resourceBundle="org.wso2.carbon.tenant.mgt.ui.i18n.Resources"
+        topPage="true"
+        request="<%=request%>"/>
+<jsp:include page="../registry_common/registry_common-i18n-ajaxprocessor.jsp"/>
+<script type="text/javascript" src="../registry_common/js/registry_validation.js"></script>
+<script type="text/javascript" src="../registry_common/js/registry_common.js"></script>
+<script type="text/javascript" src="../ajax/js/prototype.js"></script>
+<script type="text/javascript" src="js/tenant_config.js"></script>
+
+<div id="middle">
+<%if (tenantId != 0) {%>
+<h2><%if (isUpdating) {%><fmt:message key="update.tenant"/>
+
+    <%} else {%> <fmt:message
+            key="register.new.organization"/><%}%></h2>
+
+<div id="workArea">
+
+<div id="activityReason" style="display: none;"></div>
+<form id="addTenantForm" action="submit_tenant_ajaxprocessor.jsp" method="post">
+    <input type="hidden" name="isUpdating" id="isUpdating" value="false">
+    <table class="styledLeft">
+        <thead>
+        <tr>
+            <th>
+                <fmt:message key="domain.information"/>
+            </th>
+        </tr>
+        </thead>
+        <tbody>
+        <tr>
+            <td class="nopadding">
+                <table class="normal-nopadding" cellspacing="0">
+                    <tbody>
+                    <tr>
+                        <td><fmt:message key="domain"/>
+                            <%if (!isUpdating) { %> <span class="required">*</span> <% }%>
+                        </td>
+                        <td colspan="2"><input
+                                onchange="fillAdminValue();" <%if (isUpdating) { %>
+                                readonly="true" <% }%> type="text" name="domain"
+                                id="domain" style="width:400px"
+                                value="<%=domainName%>"/>
+                        </td>
+                    </tr>
+                    <%if (!isUpdating) { %>
+                    <tr>
+                        <td></td>
+                        <td colspan="2">Use a domain for your organization,in the format
+                            "example.com",This domain should be unique.
+                        </td>
+                    </tr>
+                    <% }%>
+
+                    <%if (isUpdating) { %>
+                    <tr>
+                        <td><fmt:message key="tenant.id"/>
+                        </td>
+                        <td colspan="2"><input
+                                onchange="fillAdminValue();"
+                                readonly="true" type="text" name="tenantId"
+                                id="tenantId" style="width:400px"
+                                value="<%=tenantId%>"/>
+                        </td>
+                    </tr>
+                    <% }
+
+                    %>
+
+                    <tr>
+                        <td colspan="3" class="middle-header"><fmt:message
+                                key="usage.plan.information"/></td>
+
+                    </tr>
+                    <tr>
+                        <td>
+                            <fmt:message key="select.usage.plan.for.tenant"/><span
+                                class="required">*</span>
+                        </td>
+                        <td>
+                            <select name="usage-plan-name" id="usage-plan-name">
+                            </select>
+                            <%
+                                if (!CommonUtil.getStratosConfig().getUsagePlanURL().equals("")) {
+                            %>
+                            <a href=<%=CommonUtil.getStratosConfig().getUsagePlanURL()%>
+                                       target=<%=CommonUtil.getStratosConfig().getUsagePlanURL()%>>
+                                <b>More info</b></a>
+                            <% } %>
+                        </td>
+                        <td>
+                            <% if (usagePlan.length() > 2) {
+                            %>
+                            Your Current Usage Plan is : <%=usagePlan%>
+                            <%}%>
+                        </td>
+                    <tr>
+                        <td></td>
+                        <td colspan="2"><fmt:message key="select.package.message"/>
+                        </td>
+                    </tr>
+
+
+                    <tr>
+                        <td colspan="3" class="middle-header"><fmt:message
+                                key="tenant.admin"/></td>
+                    </tr>
+                    <tr>
+                        <td><fmt:message key="admin.firstname"/><span
+                                class="required">*</span></td>
+                        <td colspan="2"><input type="text" name="admin-firstname"
+                                               id="admin-firstname" style="width:400px"
+                                               value="<%=firstname%>"/></td>
+                    </tr>
+                    <tr>
+                        <td><fmt:message key="admin.lastname"/><span
+                                class="required">*</span></td>
+                        <td colspan="2"><input type="text" name="admin-lastname"
+                                               id="admin-lastname" style="width:400px"
+                                               value="<%=lastname%>"/></td>
+                    </tr>
+
+
+                    <tr>
+                        <td><fmt:message key="admin.username"/>
+                            <%if (!isUpdating) { %>
+                            <span class="required">*</span></td>
+                        <%}%>
+                        <td colspan="2"><input <%if (isUpdating) {%>
+                                readonly="true" <%}%> type="text" name="admin"
+                                id="admin" style="width:400px" value="<%=admin%>"
+                                onchange="isDomainNameAvailable();"/><span
+                                id="adminValue"></span></td>
+                    </tr>
+
+                    <tr>
+                        <td><%if (isUpdating) {%><fmt:message
+                                key="new.admin.password"/><%} else {%><fmt:message
+                                key="admin.password"/><%}%>
+                            <%if (!isUpdating) {%><span class="required">*</span></td>
+                        <%}%>
+                        <td colspan="2"><input type="password" name="admin-password"
+                                               id="admin-password" style="width:400px"/>
+                        </td>
+                    </tr>
+                    <tr>
+                        <td><%if (isUpdating) {%><fmt:message
+                                key="new.admin.password.repeat"/><%} else {%><fmt:message
+                                key="admin.password.repeat"/><%}%>
+                            <%if (!isUpdating) {%><span class="required">*</span></td>
+                        <%}%>
+                        <td colspan="2"><input type="password"
+                                               name="admin-password-repeat"
+                                               id="admin-password-repeat"
+                                               style="width:400px"/></td>
+                    </tr>
+                    <tr>
+                        <td colspan="3" class="middle-header"><fmt:message
+                                key="contact.details"/></td>
+                    </tr>
+                    <tr>
+                        <td><fmt:message key="admin.email"/><span
+                                class="required">*</span></td>
+                        <td colspan="2"><input type="text" name="admin-email"
+                                               id="admin-email" style="width:400px"
+                                               value="<%=email%>"/></td>
+                    </tr>
+                    </tbody>
+                </table>
+            </td>
+        </tr>
+        <tr id="buttonRow">
+            <td class="buttonRow">
+                <input class="button" type="button"
+                        <% if (isUpdating) { %> value="Update" <% } else { %>
+                       value="Save" <% }%>
+                       onclick="addTenant(<%=isUpdating?"true":"false"%>, <%=isPublicCloud?"true":"false"%>)"/>
+            </td>
+        </tr>
+        <tr id="waitMessage" style="display:none">
+            <td>
+                <div style="font-size:13px !important;margin-top:10px;margin-bottom:10px;">
+                    <img
+                            src="images/ajax-loader.gif" align="left" hspace="20"/>Please
+                    wait until the Service is
+                    importing to the Registry...
+                </div>
+            </td>
+        </tr>
+        </tbody>
+    </table>
+    <%
+        // the tenantId field appears only for an update of existing tenant
+        if (isUpdating) {
+    %>
+    <input name="tenantId" type="hidden" value="<%=tenantId%>"/>
+    <%
+        }
+    %>
+    <%} else {%>
+    <tr>
+        <th>
+            <%=error1 %>
+        </th>
+    </tr>
+    <%}%>
+</form>
+
+<form id="activateTenantForm" action="activate_tenant_ajaxprocessor.jsp" method="post">
+    <%if ((isUpdating) && (tenantId > 0)) {%>
+    <table class="styledLeft">
+        <thead>
+        <tr>
+            <th>
+                <fmt:message key="activate.deactivate"/>
+            </th>
+        </tr>
+        </thead>
+        <tbody>
+
+            <% if (isActive) { %>
+        <tr>
+            <td colspan="3"><fmt:message key="deactivate.account.msg"/></td>
+        </tr>
+            <% } else {%>
+        <tr>
+            <td colspan="3"><fmt:message key="activate.account.msg"/></td>
+        </tr>
+            <% }%>
+
+        <tr id="buttonRow2">
+            <td class="buttonRow">
+                <input class="button" type="button" name="activateButton" id="activateButton"
+                       onclick="return activateDeactivate('<%=domainName%>','<%=isActive%>');"
+                        <% if (isActive) { %> value="<fmt:message key="deactivate.account.btn"/>"
+                <% } else { %> value="<fmt:message key="activate.account.btn"/>" <% } %>/>
+            </td>
+
+            <input type="hidden" name="activatingDomain" id="activatingDomain" value="<%=domainName%>"/>
+
+        </tr>
+        </tbody>
+    </table>
+    <%
+        }
+    %>
+</form>
+
+<br/>
+<script type="text/javascript">refreshFillAdminValue()</script>
+
+</div>
+</div>
+</fmt:bundle>
+<script type="text/javascript">
+    var packageInfo;
+    jQuery(document).ready(
+                          function() {
+                              jQuery.ajax({
+                                  type: 'POST',
+                                  url: 'get_package_info_ajaxprocessor.jsp',
+                                  dataType: 'json',
+                                  data: 'plan=0',
+                                  async: false,
+                                  success: function(data) {
+                                      packageInfo = data;
+                                  },
+                                  error:function (xhr, ajaxOptions, thrownError) {
+                                      CARBON.showErrorDialog('Could not get package information.');
+                                  }
+                              });
+
+                              var charge;
+                              var name;
+                              var isCloud = <%= isCloudDeployment %>;
+
+                              if (!isCloud) {
+                                  String
+                                  demoOption = "Demo"
+                                  option = document.createElement("option");
+                                  option.value = demoOption;
+                                  option.selected = demoOption;
+                                  option.innerHTML = demoOption;
+                                  document.getElementById('usage-plan-name').appendChild(option);
+
+                              } else {
+                                  for (var i = 0; i < packageInfo.length; i++) {
+                                      charge = packageInfo[i].subscriptionCharge;
+                                      name = packageInfo[i].name;
+                                      if (name == '<%=usagePlan%>') {
+                                          option = document.createElement("option");
+                                          option.value = name;
+                                          option.selected = name;
+                                          option.innerHTML = name;
+                                          document.getElementById('usage-plan-name').appendChild(option);
+
+                                      }
+                                      else {
+                                          option = document.createElement("option");
+                                          option.value = name;
+                                          option.innerHTML = name
+                                          document.getElementById('usage-plan-name').appendChild(option);
+                                      }
+                                  }
+                              }
+                          }
+            );
+</script>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/check_domain_availability_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/check_domain_availability_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/check_domain_availability_ajaxprocessor.jsp
new file mode 100644
index 0000000..284f212
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/check_domain_availability_ajaxprocessor.jsp
@@ -0,0 +1,19 @@
+<%@ page import="org.apache.axis2.AxisFault" %>
+<%@ page import="org.wso2.carbon.stratos.common.util.CommonUtil" %>
+<%@ page import="org.json.JSONException" %>
+<%@ page import="org.json.JSONObject" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%
+    String tenantDomain = request.getParameter("domain");
+    boolean isDomainAvailable = CommonUtil.isDomainNameAvailable(tenantDomain);
+    JSONObject jsonObject = new JSONObject();
+
+    if (isDomainAvailable) {
+        jsonObject.put("available", "true");
+
+    } else {
+        jsonObject.put("available", "false");
+    }
+    out.println(jsonObject);
+
+%>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/css/tenant.css
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/css/tenant.css b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/css/tenant.css
new file mode 100644
index 0000000..26d0e28
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/css/tenant.css
@@ -0,0 +1,62 @@
+/*css editor styles */
+.csseditor-top-line{
+    background-color:black;
+    height:5px;
+}
+.csseditor-leftbox{
+    background-color:#9a9a9a;
+    padding-left:5px;
+    padding-right:5px;
+    padding-bottom:5px;
+    padding-top:15px;
+   height:380px;
+}
+.csseditor-leftbox-top{
+    color:#ffffff;
+    font-size:18px;
+    height:30px;
+}
+.csseditor-textbox{
+    background-color:#dfe7ed;
+    border:solid 1px #ffffff;
+    width:100%;
+}
+.csseditor-rightbox{
+    background-color:#c9c9c9;
+    border:solid 1px #ffffff;
+    height:400px;
+}
+.csseditor-rightbox-title{
+    background-color:#9a9a9a;
+    height:25px;
+    color:#ffffff;
+    padding-left:10px;
+    padding-top:5px;
+}
+.csseditor-searchbox{
+    padding-left:10px;
+    padding-top:10px;
+}
+#flickr_results{
+    height:300px;
+    overflow-y:auto;
+    overflow-x:hidden;
+    margin-left:5px;
+    margin-right:5px;
+    border:solid 1px #ffffff;
+}
+.imageList{
+}
+.imageList li {
+    padding-top: 3px !important;
+    padding-left: 5px !important;
+    background-color: #e1e9ec;
+    border: solid 1px #b5bdc1;
+}
+
+.imageList li a {
+    background-image: url(../images/images.gif);
+    background-repeat: no-repeat;
+    padding-left: 20px;
+    text-indent: 50px;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/aboutUsagePlans.html
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/aboutUsagePlans.html b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/aboutUsagePlans.html
new file mode 100644
index 0000000..791b867
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/aboutUsagePlans.html
@@ -0,0 +1,104 @@
+<!--
+ ~ 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.
+ -->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <title>Select Usage Plan For Tenant - User Guide</title>
+  <link href="../../admin/css/documentation.css" rel="stylesheet" type="text/css" media="all" />
+</head>
+
+<body>
+
+
+ <h1>Select Usage Plan For Tenant</h1>
+
+
+ <h2> <b> Usage Plans(Subscriptions)</b></h2>
+
+<p>
+    According to the usage plan that you selected you will get different volume of service and registry
+    bandwidths other services that available for tenants.By selecting right usage plan that suits
+    your requirements you can get maximum profit
+</p>
+
+
+<h2><b>Multitenancy Free</b></h2>
+<p>
+  This is the free usage plan.You will get limited amount of resources.This package is
+  best suite for evaluation and tests.
+</p>
+ <h2><b>Multitenancy Small</b></h2>
+<p>
+   This package is best suite for small business.
+</p>
+<h2><b>Multitenancy Medium</b></h2>
+<p>
+   This usage plan suites for medium scale business.You will get average amount of resources
+    with this package.
+</p>
+<h2><b>Multitenancy Large</b></h2>
+<p>
+   This is the premium usage plan.You will get maximum resources form this plan.
+   This is best suite to large scale business.
+</p>
+
+<p>
+
+   Usage Plan summery
+<table border="1">
+<tr>
+<td>Usage Plan Name</td>
+<td>Number Of Users</td>
+<td>Registry Bandwidth (Mb) </td>
+<td>Service BandWidth (Mb) </td>
+<td>Cost Per Month ($)</td>
+</tr>
+<tr>
+<td>Multitenancy Free</td>
+<td>5</td>
+<td>10</td>
+<td>10</td>
+<td>10</td>
+</tr>
+<tr>
+<td>Multitenancy Small</td>
+<td>10</td>
+<td>25</td>
+<td>25</td>
+<td>25</td>
+</tr>
+<tr>
+<td>Multitenancy Medium</td>
+<td>20</td>
+<td>100</td>
+<td>100</td>
+<td>100</td>
+</tr>
+<tr>
+<td>Multitenancy Large</td>
+<td>50</td>
+<td>200</td>
+<td>200</td>
+<td>200</td>
+</tr>
+</table> 
+<div><strong>Figure1: Usage Plan Summery Table</strong></div>
+</p>
+</body>
+
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/add-org.png
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/add-org.png b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/add-org.png
new file mode 100644
index 0000000..fc710f8
Binary files /dev/null and b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/add-org.png differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/add-tenant.png
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/add-tenant.png b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/add-tenant.png
new file mode 100644
index 0000000..7fbb894
Binary files /dev/null and b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/add-tenant.png differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/view-tenants.png
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/view-tenants.png b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/view-tenants.png
new file mode 100644
index 0000000..03c4e83
Binary files /dev/null and b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/images/view-tenants.png differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/userguide.html
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/userguide.html b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/userguide.html
new file mode 100644
index 0000000..cd666b3
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/docs/userguide.html
@@ -0,0 +1,56 @@
+<!--
+ ~ 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.
+ -->
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <title>Multitenancy Registry Tenant Configuration - User Guide</title>
+  <link href="../../admin/css/documentation.css" rel="stylesheet" type="text/css" media="all" />
+</head>
+
+<body>
+
+
+ <h1>Multitenancy Add new Tenants and View Tenants</h1>
+
+
+ <h2> <b> Add New Tenants</b></h2>
+
+<p>
+    Following form can be used to add new tenants.You are required to fill all the requested details.
+    <img src="images/add-tenant.png" alt="Add new tenant form"/>
+    <div><strong>Figure1: Add New Tenants Form</strong></div>
+
+ 
+</p>
+
+
+<h2><b>Multitenancy View Tenants</b></h2>
+
+
+<p>
+
+   You can view a list of available tenants from this page.
+
+<img src="images/view-tenants.png" alt="Register New Organization Form"/>
+<div><strong>Figure2: View tenants Form</strong></div>
+</p>
+
+
+</body>
+
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/get_package_info_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/get_package_info_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/get_package_info_ajaxprocessor.jsp
new file mode 100644
index 0000000..0543235
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/get_package_info_ajaxprocessor.jsp
@@ -0,0 +1,39 @@
+<%--
+~ 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.
+--%>
+<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
+<%@ page import="org.json.JSONArray" %>
+<%@ page import="org.wso2.carbon.tenant.mgt.ui.clients.PackageInfoServiceClient" %>
+<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
+<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
+<%@ page import="org.wso2.carbon.CarbonConstants" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<%
+
+    String backendServerUrl = CarbonUIUtil.getServerURL(config.getServletContext(), session);
+    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
+    ConfigurationContext configContext =
+            (ConfigurationContext)config.getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
+
+    PackageInfoServiceClient client = new PackageInfoServiceClient(cookie, backendServerUrl,configContext);
+    JSONArray packageInfoArray = client.getBillingPackagesJsonArray();
+
+    out.write(packageInfoArray.toString());
+%>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/multi_tenancy.png
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/multi_tenancy.png b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/multi_tenancy.png
new file mode 100644
index 0000000..9e186e2
Binary files /dev/null and b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/multi_tenancy.png differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/services.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/services.gif b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/services.gif
new file mode 100755
index 0000000..9883116
Binary files /dev/null and b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/services.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/services1.gif
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/services1.gif b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/services1.gif
new file mode 100644
index 0000000..d40a7a3
Binary files /dev/null and b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/images/services1.gif differ

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/js/tenant_config.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/js/tenant_config.js b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/js/tenant_config.js
new file mode 100644
index 0000000..d00a81f
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/js/tenant_config.js
@@ -0,0 +1,218 @@
+function addTenant(isUpdating, isPublicCloud) {
+    
+    var reason = "";
+    var addTenantForm = document.getElementById('addTenantForm');
+    var adminPassword = document.getElementById('admin-password');
+    var adminPasswordRepeat = document.getElementById('admin-password-repeat');
+    var email = document.getElementById('admin-email');
+    var firstname = document.getElementById('admin-firstname');
+    var lastname = document.getElementById('admin-lastname');
+
+    if (isUpdating) {
+
+        // only the given values will be updated, so no need to fill all the values.
+        if (reason == "") {
+            reason += validateEmpty(firstname, "First Name");
+        }
+        if (reason == "") {
+            reason += validateIllegal(firstname, "First Name");
+        }
+        if (reason == "") {
+            reason += validateEmpty(lastname, "Last Name");
+        }
+        if (reason == "") {
+            reason += validateIllegal(lastname, "Last Name");
+        }
+        if (adminPassword.value != null && adminPassword.value != "") {
+            if (adminPassword.value != adminPasswordRepeat.value) {
+                reason += jsi18n["password.mismatched"];
+            }
+        }
+    }
+    else {
+        var domain = document.getElementById('domain');
+        var adminName = document.getElementById('admin');
+
+        if (reason == "") {
+            reason += validateEmpty(domain, "Domain");
+        }
+        if (reason == "") {
+            reason += validateDomain(domain, isPublicCloud);
+        }
+
+        if (reason == "") {
+             reason +=domainAvailability(domain);
+         }
+
+        if (reason == "") {
+            reason += validateEmpty(firstname, "First Name");
+        }
+        if (reason == "") {
+            reason += validateIllegal(firstname, "First Name");
+        }
+        if (reason == "") {
+            reason += validateEmpty(lastname, "Last Name");
+        }
+        if (reason == "") {
+            reason += validateIllegal(lastname, "Last Name");
+        }
+        if (reason == "") {
+            reason += validateEmpty(adminName, "Admin Name");
+        }
+        if (reason == "") {
+            reason += validateIllegal(adminName, "Admin Name");
+        }
+        if (reason == "") {
+            reason += validateUsername(adminName);
+        }
+        if (reason == "") {
+            reason += validateEmpty(adminPassword, "AdminPassword");
+        }
+        if (reason == "") {
+            reason += validateEmpty(adminPasswordRepeat, "AdminPasswordRepeat");
+        }
+        if (reason == "") {
+            reason += validateEmpty(email, "Email");
+        }
+        if (reason == "") {
+            reason += validateEmail(email);
+        }
+
+        if (reason == "") {
+            if (adminPassword.value != adminPasswordRepeat.value) {
+                reason += jsi18n["password.mismatched"];
+            }
+            if (adminPassword.value.length < 6) {
+                reason += jsi18n["password.length"];
+            }
+        }
+    }
+
+    if (reason != "") {
+        CARBON.showErrorDialog(reason);
+        return;
+    }
+    document.getElementById("isUpdating").value=isUpdating;
+    addTenantForm.submit();
+}
+function showSuccessRegisterMessage() {
+    var message = "You have registered the Organization Successfully";
+    CARBON.showInfoDialog(message);
+    return;
+}
+function showSuccessUpdateMessage() {
+    var message = "Your changes saved Successfully!";
+    CARBON.showInfoDialog(message);
+    return;
+}
+function activationChanged(cbox, domain) {
+    if (!cbox.checked) {
+        CARBON.showConfirmationDialog("Are you sure you want to deactivate the domain: " +
+                domain + ".", function() {
+            var submitForm = document.getElementById(domain + "_form");
+            submitForm.submit();
+        }, function() {
+            cbox.checked = "on";
+        });
+    } else {
+        var submitForm = document.getElementById(domain + "_form");
+        submitForm.submit();
+    }
+}
+
+function fillAdminValue() {
+    var adminValue = $('adminValue');
+    var domain = $('domain');
+
+    var reason = validateIllegal(domain, "Domain");
+    if (reason != "") {
+        CARBON.showErrorDialog(reason);
+        adminValue.innerHTML = '';
+        return;
+    }
+
+
+    if (domain.value == "") {
+        adminValue.innerHTML = '' + domain.value;
+    }
+    else {
+        adminValue.innerHTML = '@' + domain.value;
+    }
+}
+function refreshFillAdminValue() {
+    //Call this method at loading time
+    fillAdminValue();
+}
+
+function validateDomain(fld, isPublicCloudSetup) {
+    var error = "";
+    var domain = fld.value;
+    var lastIndexOfDot = domain.lastIndexOf(".");
+    var indexOfDot = domain.indexOf(".");
+    var extension = domain.substring(lastIndexOfDot, domain.length);
+
+    var illegalChars = /([^a-zA-Z0-9\._\-])/; // allow only letters and numbers . - _and period
+    if (extension.indexOf("-trial") >= 0 || extension.indexOf("-unverified") >= 0) {
+        // we are not allowing to create a domain with -trial or -unverified is in the extension
+        error = "The domain name you entered is not valid. Please enter a valid domain name.";
+    }
+    else if (isPublicCloudSetup && (lastIndexOfDot <= 0)) {
+        error = "Invalid domain: " + domain + ". You should have an extension to your domain.";
+    }
+    else if (indexOfDot == 0) {
+        error = "Invalid domain, starting with '.'";
+    }
+    else if (illegalChars.test(fld.value)) {
+        error = "The domain only allows letters, numbers, '.', '-' and '_'. <br />";
+    } else {
+        fld.style.background = 'White';
+    }
+    return error;
+}
+
+function domainSelected() {
+    var findDomainForm = document.getElementById('findTenantForm');
+    findDomainForm.submit();
+}
+
+
+function domainAvailability(domain) {
+    var error = "";
+    jQuery.ajax({
+        type: 'POST',
+        url: 'check_domain_availability_ajaxprocessor.jsp?',
+        dataType: 'json',
+        data: 'domain=' + domain.value,
+        success: function(result) {
+            var available = result.available;
+            if (available == 'false') {
+                error = "Sorry!. The Domain is already registered. Please choose a different domain.";
+                return error;
+            }else{
+               error ="";
+            }
+
+        },
+        error:function (xhr, ajaxOptions, thrownError) {
+             error = "Error in checking domain availability";
+
+        },
+        async: false        
+    });
+
+    return error;
+}
+
+function activateDeactivate(domain, isActive) {
+    if (isActive == 'true') {
+        CARBON.showConfirmationDialog("Are you sure you want to deactivate the domain: " +
+                domain + "?", function() {
+            var submitForm = document.getElementById("activateTenantForm");
+            submitForm.submit();
+        }, function() {
+        });
+    } else {
+        var submitForm = document.getElementById("activateTenantForm");
+        submitForm.submit();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/js/theme_resource_util.js
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/js/theme_resource_util.js b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/js/theme_resource_util.js
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/submit_tenant_ajaxprocessor.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/submit_tenant_ajaxprocessor.jsp b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/submit_tenant_ajaxprocessor.jsp
new file mode 100644
index 0000000..829328e
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/submit_tenant_ajaxprocessor.jsp
@@ -0,0 +1,84 @@
+<!--
+ ~ 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.
+ -->
+
+<%@ page import="org.wso2.carbon.stratos.common.util.CommonUtil" %>
+<%@ page import="org.wso2.carbon.tenant.mgt.ui.utils.TenantMgtUtil" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<script type="text/javascript" src="../admin/js/jquery.js"></script>
+<script type="text/javascript" src="../admin/js/jquery.form.js"></script>
+<script type="text/javascript" src="../dialog/js/jqueryui/jquery-ui.min.js"></script>
+
+<%--<carbon:jsi18n--%>
+		<%--resourceBundle="org.wso2.carbon.tenant.mgt.ui.i18n.JSResources"--%>
+		<%--request="<%=request%>" />--%>
+
+<div id="middle">
+<%
+//    First remove captcha images first stored in webapps
+    String error1 = "Error in adding the tenant.";
+    String error2 = "Error in updating the tenant.";
+    boolean isUpdating = false;
+    String tenantId = "";
+    String tenantDomain = "";
+    String paramvalue = "addTenant=Success";
+    try {
+        tenantId = request.getParameter("tenantId");
+        tenantDomain = request.getParameter("domain");
+        isUpdating = Boolean.parseBoolean(request.getParameter("isUpdating"));
+
+        boolean isDomainAvailable=false;
+        if(!isUpdating){
+            isDomainAvailable = CommonUtil.isDomainNameAvailable(tenantDomain);
+        }
+
+    //if the request is for creating a new tenant and if the domain name is not available, show a warning
+
+    if(tenantId == null && !isDomainAvailable){
+
+%>
+    <script type="text/javascript">
+        jQuery(document).ready(function() {
+             CARBON.showErrorDialog("Sorry!. The Domain '<%=tenantDomain%>'is already registered. Please choose a different domain.");
+        });
+    </script>
+
+<%
+    }else if (tenantId == null && isDomainAvailable) {
+
+     // if the request is for creating a new tenant and if th domain name is available. add the tenant
+            TenantMgtUtil.addTenantConfigBean(request,config,session);
+              response.sendRedirect("../tenant-mgt/view_tenants.jsp?region=region3&item=govern_view_tenants_menu&"+paramvalue);
+     }else if (tenantId !=null){
+     //if the tenant id is given, it is a request to update.hence update the tenant info
+            TenantMgtUtil.updateTenantConfigBean(request,config,session);
+            isUpdating = true;
+            paramvalue = "addTenant=SuccessUpdate";
+          response.sendRedirect("../tenant-mgt/view_tenants.jsp?region=region3&item=govern_view_tenants_menu&"+paramvalue);
+        }
+
+    } catch (Exception e) {
+        CarbonUIMessage uiMsg = new CarbonUIMessage(CarbonUIMessage.ERROR, e.getMessage(), e);
+        request.setAttribute(CarbonUIMessage.ID, uiMsg);
+             %>
+            <jsp:forward page="../admin/error.jsp"/>
+             <%
+         return;
+    }
+%>
+    </div>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/view_tenants.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/view_tenants.jsp b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/view_tenants.jsp
new file mode 100644
index 0000000..f04efdb
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt.ui/2.1.0/src/main/resources/web/tenant-mgt/view_tenants.jsp
@@ -0,0 +1,236 @@
+<!--
+~ 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.
+-->
+<%@ page import="org.apache.axis2.context.ConfigurationContext" %>
+<%@ page import="org.wso2.carbon.CarbonConstants" %>
+<%@ page import="org.wso2.carbon.tenant.mgt.stub.beans.xsd.PaginatedTenantInfoBean" %>
+<%@ page import="org.wso2.carbon.tenant.mgt.stub.beans.xsd.TenantInfoBean" %>
+<%@ page import="org.wso2.carbon.tenant.mgt.ui.clients.TenantServiceClient" %>
+<%@ page import="org.wso2.carbon.tenant.mgt.ui.utils.TenantMgtUtil" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIMessage" %>
+<%@ page import="org.wso2.carbon.ui.CarbonUIUtil" %>
+<%@ page import="org.wso2.carbon.utils.ServerConstants" %>
+<%@ page import="java.text.SimpleDateFormat" %>
+<%@ page import="java.util.Calendar" %>
+<%@ page import="java.util.Date" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+<jsp:include page="../registry_common/registry_common-i18n-ajaxprocessor.jsp"/>
+<script type="text/javascript" src="../registry_common/js/registry_validation.js"></script>
+<script type="text/javascript" src="../registry_common/js/registry_common.js"></script>
+<script type="text/javascript" src="../ajax/js/prototype.js"></script>
+<script type="text/javascript" src="js/tenant_config.js"></script>
+
+
+<%
+    if ("Success".equals(request.getParameter("addTenant"))) {
+%>
+<script type="text/javascript">showSuccessRegisterMessage()</script>
+<%
+    }
+    if ("SuccessUpdate".equals(request.getParameter("addTenant"))) {
+%>
+<script type="text/javascript">showSuccessUpdateMessage()</script>
+<%
+    }
+
+%>
+<carbon:jsi18n
+        resourceBundle="org.wso2.carbon.tenant.mgt.ui.i18n.JSResources"
+        request="<%=request%>"/>
+
+<fmt:bundle basename="org.wso2.carbon.tenant.mgt.ui.i18n.Resources">
+    <carbon:breadcrumb
+            label="govern.view_tenants.menu"
+            resourceBundle="org.wso2.carbon.tenant.mgt.ui.i18n.Resources"
+            topPage="true"
+            request="<%=request%>"/>
+
+    <div id="top">
+        <form id="findTenantForm" action="view_tenants.jsp?action=search" method="post">
+            <table class="normal-nopadding" cellspacing="0">
+                <tbody>
+                <tr>
+                    <td><fmt:message key="enter.tenant.domain"/></td>
+                    <td colspan="2"><input type="text" name="domain" id="domain"
+                                           style="width:400px"/>
+                        <input type="button" onclick="domainSelected()" value="Find"/>
+                    </td>
+                </tr>
+                </tbody>
+            </table>
+        </form>
+    </div>
+
+    <br/>
+
+    <div id="middle">
+
+        <%
+            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+            String activatingDomain = request.getParameter("activate.domain");
+            String action = request.getParameter("action");
+            String domainName = request.getParameter("domain");
+            if (activatingDomain != null) {
+                // try to activate deactive the tenant
+                String activate = request.getParameter("activate");
+                try {
+                    if (activate != null && activate.equalsIgnoreCase("on")) {
+                        TenantMgtUtil.activateTenant(request, config, session);
+                    } else {
+                        TenantMgtUtil.deactivateTenant(request, config, session);
+                    }
+                } catch (Exception e) {
+                    String error1 = "Error in activating/deactivating tenant";
+                    request.setAttribute(CarbonUIMessage.ID,
+                            new CarbonUIMessage(error1, error1, null));
+
+        %>
+
+        <jsp:forward page="../admin/error.jsp?<%=error1%>"/>
+
+        <%
+                    return;
+                }
+            }
+
+            String pageNumberStr = request.getParameter("pageNumber");
+            if (pageNumberStr == null) {
+                pageNumberStr = "0";
+            }
+            int pageNumber = 0;
+            try {
+                pageNumber = Integer.parseInt(pageNumberStr);
+            } catch (NumberFormatException ignored) {
+                // page number format exception
+            }
+            int numberOfPages;
+            int noOfPageLinksToDisplay = 5;  //default value is set to 5
+
+            String backendServerURL = CarbonUIUtil.getServerURL(
+                    config.getServletContext(), session);
+            ConfigurationContext configContext = (ConfigurationContext) config
+                    .getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
+
+            String cookie = (String) session.getAttribute
+                    (ServerConstants.ADMIN_SERVICE_COOKIE);
+            TenantServiceClient client;
+            PaginatedTenantInfoBean tenantsInfo;
+            TenantInfoBean[] tenantInfoArr;
+            try {
+                client = new TenantServiceClient(cookie, backendServerURL, configContext);
+                if (action != null && action.equals("search")) {
+                	   tenantsInfo = client.retrievePaginatedPartialSearchTenants(domainName,pageNumber);
+                } else {
+                	   tenantsInfo = client.retrievePaginatedTenants(pageNumber);
+                }
+             
+
+                tenantInfoArr = tenantsInfo.getTenantInfoBeans();
+                numberOfPages = tenantsInfo.getNumberOfPages();
+
+            } catch (Exception e) {
+                String error1 = "Error in retrieving tenants";
+                request.setAttribute(CarbonUIMessage.ID, new CarbonUIMessage(error1, error1, null));
+        %>
+
+        <jsp:forward page="../admin/error.jsp"/>
+
+        <%
+                return;
+            }
+        %>
+
+        <h2><fmt:message key="tenants.list"/></h2>
+        <br/>
+        <carbon:paginator pageNumber="<%=pageNumber%>" numberOfPages="<%=numberOfPages%>"
+                          noOfPageLinksToDisplay="<%=noOfPageLinksToDisplay%>"
+                          page="view_tenants.jsp" pageNumberParameterName="pageNumber"/>
+
+        <div id="workArea">
+
+
+                <%
+                    if (tenantInfoArr != null && tenantInfoArr.length>0 && tenantInfoArr[0]!=null) {
+                %>
+
+                <table cellpadding="0" cellspacing="0" border="0" style="width:100%" class="styledLeft">
+                    <thead>
+                    <tr>
+                        <th style="padding-left:5px;text-align:left;"><fmt:message key="domain"/></th>
+                        <th style="padding-left:5px;text-align:left;"><fmt:message
+                                key="admin.email"/></th>
+                        <th style="padding-left:5px;text-align:left;"><fmt:message
+                                key="created.date"/></th>
+                        <th style="padding-left:5px;text-align:left;"><fmt:message key="active"/></th>
+                        <th style="padding-left:5px;text-align:left;"><fmt:message key="edit"/></th>
+                    </tr>
+                    </thead>
+                    <tbody>
+
+                <%
+                        for (TenantInfoBean tenantInfo : tenantInfoArr) {
+                            if (tenantInfo == null) {
+                                continue;
+                            }
+                            String tenantDomain = TenantMgtUtil.removeHtmlElements(
+                                    tenantInfo.getTenantDomain());
+                            String email = TenantMgtUtil.removeHtmlElements(tenantInfo.getEmail());
+                            boolean isActive = tenantInfo.getActive();
+                            Calendar createdDateCal = tenantInfo.getCreatedDate();
+                            Date createdDate = new Date(createdDateCal.getTimeInMillis());
+                            String createdDateStr = dateFormat.format(createdDate);
+                %>
+
+                <tr id="1">
+                    <td style="padding-left:5px;padding-top:3px;text-align:left;"><%=tenantDomain%>
+                    </td>
+                    <td style="padding-left:5px;padding-top:3px;text-align:left;"><%=email%>
+                    </td>
+                    <td style="padding-left:5px;padding-top:3px;text-align:left;"><%=createdDateStr%>
+                    </td>
+                    <td style="padding-left:5px;padding-top:3px;text-align:left;">
+                        <form id="<%=tenantDomain%>_form" action="view_tenants.jsp" method="post">
+                            <input type="checkbox" name="activate"
+                                   onchange="javascript:activationChanged(this, '<%=tenantDomain%>')"
+                                   <%if (isActive) {%>checked="true"<%}%>/>
+                            <input type="hidden" name="activate.domain" value="<%=tenantDomain%>"/>
+                        </form>
+                    </td>
+                    <td style="padding-left:5px;padding-top:3px;text-align:left;"><a
+                            href="add_tenant.jsp?domain=<%=tenantInfo.getTenantDomain()%>">Edit</a>
+                    </td>
+                </tr>
+                <% }
+                %>
+                    </tbody>
+                </table>
+                <%
+                }else{
+                %>
+            <div><fmt:message key="no.tenants.available"/></div>
+            <%
+                }
+            %>
+
+        </div>
+                <carbon:paginator pageNumber="<%=pageNumber%>" numberOfPages="<%=numberOfPages%>"
+                                  noOfPageLinksToDisplay="<%=noOfPageLinksToDisplay%>"
+                                  page="view_tenants.jsp" pageNumberParameterName="pageNumber"/>
+    </div>
+</fmt:bundle>
\ No newline at end of file


[5/7] Tenat-mgt refactoring

Posted by is...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt/2.1.0/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/pom.xml b/components/org.apache.stratos.tenant.mgt/2.1.0/pom.xml
new file mode 100644
index 0000000..9d366d2
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/2.1.0/pom.xml
@@ -0,0 +1,125 @@
+<!--
+# 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</artifactId>
+    <version>2.1.0</version>
+    <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>${carbon.platform.version}</version>
+        </dependency>
+        <dependency>
+           <groupId>org.wso2.carbon</groupId>
+           <artifactId>org.wso2.carbon.tenant.mgt.core</artifactId>
+	   <version>2.1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.registry.core</artifactId>
+            <version>${carbon.platform.version}</version>
+        </dependency>
+        <dependency>
+           <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.um.ws.api</artifactId>
+            <version>${carbon.platform.version}</version>
+        </dependency>
+        <dependency>
+           <groupId>org.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.captcha.mgt</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.wso2.carbon</groupId>
+            <artifactId>org.wso2.carbon.admin.mgt</artifactId>
+	    <version>4.1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.rampart.wso2</groupId>
+            <artifactId>rampart-policy</artifactId>
+	    <version>1.6.1.wso2v8</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.rampart.wso2</groupId>
+            <artifactId>rampart-core</artifactId>
+	    <version>1.6.1.wso2v8</version>
+        </dependency>
+    </dependencies>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/beans/PaginatedTenantInfoBean.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/beans/PaginatedTenantInfoBean.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/beans/PaginatedTenantInfoBean.java
new file mode 100644
index 0000000..3a55df6
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/2.1.0/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.wso2.carbon.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/8c3796dc/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/exception/TenantManagementException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/exception/TenantManagementException.java b/components/org.apache.stratos.tenant.mgt/2.1.0/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/2.1.0/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/8c3796dc/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/internal/TenantMgtServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/internal/TenantMgtServiceComponent.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/internal/TenantMgtServiceComponent.java
new file mode 100644
index 0000000..ae8411b
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/2.1.0/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.wso2.carbon.stratos.common.TenantBillingService;
+import org.wso2.carbon.stratos.common.listeners.TenantMgtListener;
+import org.wso2.carbon.stratos.common.util.CommonUtil;
+import org.wso2.carbon.stratos.common.util.StratosConfiguration;
+import org.apache.stratos.tenant.mgt.internal.util.TenantMgtRampartUtil;
+import org.wso2.carbon.user.api.RealmConfiguration;
+import org.wso2.carbon.user.core.service.RealmService;
+import org.wso2.carbon.user.core.tenant.TenantManager;
+import org.wso2.carbon.utils.ConfigurationContextService;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.neethi.Policy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.osgi.service.component.ComponentContext;
+
+/**
+ * @scr.component name="org.wso2.carbon.tenant.mgt" immediate="true"
+ * @scr.reference name="registry.service"
+ *                interface="org.wso2.carbon.registry.core.service.RegistryService"
+ *                cardinality="1..1" policy="dynamic" bind="setRegistryService"
+ *                unbind="unsetRegistryService"
+ * @scr.reference name="user.realmservice.default"
+ *                interface="org.wso2.carbon.user.core.service.RealmService"
+ *                cardinality="1..1" policy="dynamic" bind="setRealmService"
+ *                unbind="unsetRealmService"
+ * @scr.reference name="configuration.context.service"
+ *                interface="org.wso2.carbon.utils.ConfigurationContextService"
+ *                cardinality="1..1" policy="dynamic"
+ *                bind="setConfigurationContextService"
+ *                unbind="unsetConfigurationContextService"
+ * @scr.reference name="org.wso2.carbon.tenant.mgt.listener.service"
+ *                interface="org.wso2.carbon.stratos.common.listeners.TenantMgtListener"
+ *                cardinality="0..n" policy="dynamic"
+ *                bind="setTenantMgtListenerService"
+ *                unbind="unsetTenantMgtListenerService"
+ * @scr.reference name="default.tenant.billing.service"
+ *                interface="org.wso2.carbon.stratos.common.TenantBillingService"
+ *                cardinality="0..1" policy="dynamic"
+ *                bind="setTenantBillingService"
+ *                unbind="unsetTenantBillingService"
+ * @scr.reference name="default.tenant.persistor"
+ *                interface="org.wso2.carbon.core.multitenancy.persistence.TenantPersistor"
+ *                cardinality="1..1" policy="dynamic"
+ *                bind="setTenantPersistor"
+ *                unbind="unsetTenantPersistor"
+ */
+public class TenantMgtServiceComponent {
+    private static Log log = LogFactory.getLog(TenantMgtServiceComponent.class);
+
+    private static final String GAPP_TENANT_REG_SERVICE_NAME = "GAppTenantRegistrationService";
+
+    private static RealmService realmService;
+    private static RegistryService registryService;
+    
+    private static ConfigurationContextService configurationContextService;
+    
+    private static List<TenantMgtListener> tenantMgtListeners = new ArrayList<TenantMgtListener>();
+    private static TenantPersistor tenantPersistor = null;
+    private static TenantBillingService billingService = null;
+
+    protected void activate(ComponentContext context) {
+        try {
+
+            // Loading the stratos configurations from Stratos.xml
+            if (CommonUtil.getStratosConfig() == null) {
+                StratosConfiguration stratosConfig = CommonUtil.loadStratosConfiguration();
+                CommonUtil.setStratosConfig(stratosConfig);
+            }
+
+            // Loading the EULA
+            if (CommonUtil.getEula() == null) {
+                String eula = CommonUtil.loadTermsOfUsage();
+                CommonUtil.setEula(eula);
+            }
+            
+            populateRampartConfig(configurationContextService.
+					              getServerConfigContext().getAxisConfiguration());
+
+            log.debug("******* Tenant Config bundle is activated ******* ");
+        } catch (Exception e) {
+            log.error("******* Tenant Config bundle failed activating ****", e);
+        }
+    }
+
+    protected void setTenantMgtListenerService(TenantMgtListener tenantMgtListener) {
+        addTenantMgtListener(tenantMgtListener);
+    }
+
+    protected void unsetTenantMgtListenerService(TenantMgtListener tenantMgtListener) {
+        removeTenantMgtListener(tenantMgtListener);
+    }
+
+    protected void deactivate(ComponentContext context) {
+        log.debug("******* Governance Tenant Config bundle is deactivated ******* ");
+    }
+
+    protected void setRegistryService(RegistryService registryService) {
+        TenantMgtServiceComponent.registryService = registryService;
+    }
+
+    protected void unsetRegistryService(RegistryService registryService) {
+        setRegistryService(null);
+    }
+
+    protected void setRealmService(RealmService realmService) {
+        TenantMgtServiceComponent.realmService = realmService;
+    }
+
+    protected void unsetRealmService(RealmService realmService) {
+        setRealmService(null);
+    }
+
+    protected void setConfigurationContextService(ConfigurationContextService configurationContextService) {
+        log.debug("Receiving ConfigurationContext Service");
+        TenantMgtServiceComponent.configurationContextService = configurationContextService;
+
+    }
+
+    protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService) {
+        log.debug("Unsetting ConfigurationContext Service");
+        setConfigurationContextService(null);
+    }
+
+    public static void addTenantMgtListener(TenantMgtListener tenantMgtListener) {
+        tenantMgtListeners.add(tenantMgtListener);
+        sortTenantMgtListeners();
+    }
+
+    public static void removeTenantMgtListener(TenantMgtListener tenantMgtListener) {
+        tenantMgtListeners.remove(tenantMgtListener);
+        sortTenantMgtListeners();
+    }
+
+    public static void sortTenantMgtListeners() {
+        Collections.sort(tenantMgtListeners, new Comparator<TenantMgtListener>() {
+            public int compare(TenantMgtListener o1, TenantMgtListener o2) {
+                return o1.getListenerOrder() - o2.getListenerOrder();
+            }
+        });
+    }
+
+    public static List<TenantMgtListener> getTenantMgtListeners() {
+        return tenantMgtListeners;
+    }
+
+    public static ConfigurationContextService getConfigurationContextService() {
+        return configurationContextService;
+    }
+
+    public static ConfigurationContext getConfigurationContext() {
+        if (configurationContextService.getServerConfigContext() == null) {
+            return null;
+        }
+        return configurationContextService.getServerConfigContext();
+    }
+
+    public static RegistryService getRegistryService() {
+        return registryService;
+    }
+
+
+    public static RealmService getRealmService() {
+        return realmService;
+    }
+
+    public static TenantManager getTenantManager() {
+        return realmService.getTenantManager();
+    }
+
+    public static RealmConfiguration getBootstrapRealmConfiguration() {
+        return realmService.getBootstrapRealmConfiguration();
+    }
+
+    public static UserRegistry getGovernanceSystemRegistry(int tenantId) throws RegistryException {
+        return registryService.getGovernanceSystemRegistry(tenantId);
+    }
+
+    public static UserRegistry getConfigSystemRegistry(int tenantId) throws RegistryException {
+        return registryService.getConfigSystemRegistry(tenantId);
+    }
+
+    public static TenantPersistor getTenantPersistor() {
+        return tenantPersistor;
+    }
+
+    protected void setTenantPersistor(TenantPersistor defaultTenantPersistor) {
+        tenantPersistor = defaultTenantPersistor;
+    }
+
+    public void unsetTenantPersistor(TenantPersistor defaultTenantPersistor) {
+        tenantPersistor = null;
+    }
+
+    
+   /** Updates RelyingPartyService with Crypto information
+    *
+    * @param config AxisConfiguration
+    * @throws Exception
+    */
+   private void populateRampartConfig(AxisConfiguration config) throws Exception {
+       AxisService service;
+       // Get the RelyingParty Service to update security policy with keystore information
+       service = config.getService(GAPP_TENANT_REG_SERVICE_NAME);
+       if (service == null) {
+           String msg = GAPP_TENANT_REG_SERVICE_NAME + " is not available in the Configuration Context";
+           log.error(msg);
+           throw new Exception(msg);
+       }
+       // Create a Rampart Config with default crypto information
+       Policy rampartConfig = TenantMgtRampartUtil.getDefaultRampartConfig();
+       // Add the RampartConfig to service policy
+       service.getPolicySubject().attachPolicy(rampartConfig);
+
+   }
+   
+   protected void setTenantBillingService(TenantBillingService tenantBillingService) {
+       billingService = tenantBillingService;
+   }
+   
+   protected void unsetTenantBillingService(TenantBillingService tenantBilling) {
+       setTenantBillingService(null);
+   }
+   
+   public static TenantBillingService getBillingService() {
+       return billingService;
+   }
+   
+   
+}

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

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

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/8c3796dc/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java
new file mode 100644
index 0000000..d6243df
--- /dev/null
+++ b/components/org.apache.stratos.tenant.mgt/2.1.0/src/main/java/org/apache/stratos/tenant/mgt/services/TenantSelfRegistrationService.java
@@ -0,0 +1,193 @@
+/*
+ *  Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ *  WSO2 Inc. licenses this file to you under the Apache License,
+ *  Version 2.0 (the "License"); you may not use this file except
+ *  in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.tenant.mgt.services;
+
+import org.wso2.carbon.captcha.mgt.beans.CaptchaInfoBean;
+import org.wso2.carbon.captcha.mgt.constants.CaptchaMgtConstants;
+import org.wso2.carbon.captcha.mgt.util.CaptchaUtil;
+import org.wso2.carbon.core.multitenancy.persistence.TenantPersistor;
+import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
+import org.wso2.carbon.stratos.common.exception.StratosException;
+import org.wso2.carbon.stratos.common.util.CommonUtil;
+import org.apache.stratos.tenant.mgt.internal.TenantMgtServiceComponent;
+import org.apache.stratos.tenant.mgt.util.TenantMgtUtil;
+import org.wso2.carbon.user.core.tenant.Tenant;
+import org.wso2.carbon.user.core.tenant.TenantManager;
+import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
+
+import org.apache.axis2.AxisFault;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * TenantSelfRegistration - This is the Web service that will be called when
+ * tenants register themselves
+ */
+public class TenantSelfRegistrationService {
+    private static final Log log = LogFactory.getLog(TenantSelfRegistrationService.class);
+
+    /**
+     * Registers a tenant - Tenant Self Registration
+     *
+     * @param tenantInfoBean  - tenantInformation
+     * @param captchaInfoBean - captchaInformation
+     * @return String UUID
+     * @throws Exception if the tenant registration fails.
+     */
+    public String registerTenant(TenantInfoBean tenantInfoBean, CaptchaInfoBean captchaInfoBean)
+            throws Exception {
+        // validate the email
+        try {
+            CommonUtil.validateEmail(tenantInfoBean.getEmail());
+        } catch (Exception e) {
+            String msg = "Invalid email is provided.";
+            log.error(msg, e);
+            throw new AxisFault(msg);
+        }
+        // validate the domain
+        String domainName = tenantInfoBean.getTenantDomain();
+        try {
+            TenantMgtUtil.validateDomain(domainName);
+        } catch (Exception e) {
+            String msg = "Domain Validation Failed.";
+            log.error(msg, e);
+            throw new AxisFault(msg);
+        }
+        // validate the first/last names
+        String firstname = tenantInfoBean.getFirstname();
+        String lastname = tenantInfoBean.getLastname();
+        try {
+            CommonUtil.validateName(firstname, "First Name");
+            CommonUtil.validateName(lastname, "Last Name");
+        } catch (Exception e) {
+            String msg = "First/Last Name Validation Failed.";
+            log.error(msg, e);
+            throw new AxisFault(msg);
+        } // now validate the captcha
+        try {
+            CaptchaUtil.validateCaptcha(captchaInfoBean);
+            if (log.isDebugEnabled()) {
+                log.debug("Captcha Successfully Validated.");
+            }
+        } catch (Exception e) {
+            String msg = CaptchaMgtConstants.CAPTCHA_ERROR_MSG;
+            log.error(msg, e);
+            throw new AxisFault(msg);
+        } finally {
+            try {
+                CaptchaUtil.cleanCaptcha(captchaInfoBean.getSecretKey());
+            } catch (Exception e) {
+                String msg = "Error in cleaning captcha. ";
+                log.error(msg, e);
+                // not throwing the exception in finally more up.
+            }
+        }
+        // persists the tenant.
+        Tenant tenant = TenantMgtUtil.initializeTenant(tenantInfoBean);
+        TenantPersistor persistor = TenantMgtServiceComponent.getTenantPersistor();
+        int tenantId = persistor.persistTenant(tenant, true, tenantInfoBean.getSuccessKey(), 
+                tenantInfoBean.getOriginatedService());
+        tenantInfoBean.setTenantId(tenantId);
+        TenantMgtUtil.addClaimsToUserStoreManager(tenant);
+        
+        //Notify tenant addition
+        try {
+            TenantMgtUtil.triggerAddTenant(tenantInfoBean);
+        } catch (StratosException e) {
+            String msg = "Error in notifying tenant addition.";
+            log.error(msg, e);
+            throw new Exception(msg, e);
+        }
+
+        //adding the subscription entry
+        try {
+            if (TenantMgtServiceComponent.getBillingService() != null) {
+                TenantMgtServiceComponent.getBillingService().addUsagePlan(tenant,
+                        tenantInfoBean.getUsagePlan());
+                if (log.isDebugEnabled()) {
+                    log.debug("Subscription added successfully for the tenant: " +
+                              tenantInfoBean.getTenantDomain());
+                }
+            }
+        } catch (Exception e) {
+            String msg = "Error occurred while adding the subscription for tenant: " + domainName;
+            log.error(msg, e);
+        }
+
+        // If Email Validation is made optional, tenant will be activated now.
+        if (CommonUtil.isTenantManagementEmailsDisabled() ||
+                !CommonUtil.isEmailValidationMandatory()) {
+            TenantMgtUtil.activateTenantInitially(tenantInfoBean, tenantId);
+        }
+        return TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
+    }
+
+    /**
+     * Check if the selected domain is available to register
+     *
+     * @param domainName domain name
+     * @return true, if the domain is available to register
+     * @throws Exception, if unable to get the tenant manager, or get the tenant id
+     *                    from manager.
+     */
+    public boolean checkDomainAvailability(String domainName) throws Exception {
+        TenantManager tenantManager = TenantMgtServiceComponent.getTenantManager();
+        int tenantId = tenantManager.getTenantId(domainName);
+        if (log.isDebugEnabled()) {
+            log.debug("Tenant Domain is available to register.");
+        }
+        return tenantId < 0; // no tenant exists with the same tenant domain
+    }
+
+    // use a boolean instead of string.
+
+    /**
+     * Validates or Suggests a domain.
+     *
+     * @param domain     tenant domain
+     * @param successKey success key
+     * @return domain name
+     * @throws Exception if exception in validating or suggesting the tenant domain.
+     */
+    public String validateOrSuggestDomain(String domain, String successKey) throws Exception {
+        if (successKey != null && !successKey.equals("")) {
+            if (CommonUtil.validateDomainFromSuccessKey(
+                    TenantMgtServiceComponent.getGovernanceSystemRegistry(
+                            MultitenantConstants.SUPER_TENANT_ID), domain, successKey)) {
+                return domain;
+            }
+        }
+        // otherwise domain is not correct
+
+        return "null";
+    }
+
+    /**
+     * Generates a random Captcha
+     *
+     * @return captchaInfoBean
+     * @throws Exception, if exception in cleaning old captchas or generating new
+     *                    captcha image.
+     */
+    public CaptchaInfoBean generateRandomCaptcha() throws Exception {
+        // we will clean the old captchas asynchronously
+        CaptchaUtil.cleanOldCaptchas();
+        return CaptchaUtil.generateCaptchaImage();
+    }
+}