You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stratos.apache.org by anuruddhal <gi...@git.apache.org> on 2015/04/22 08:23:50 UTC

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

GitHub user anuruddhal opened a pull request:

    https://github.com/apache/stratos/pull/287

    Moving non-API methods to StratosApiV41Utils class from StratosApiV41 class

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/anuruddhal/stratos master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/stratos/pull/287.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #287
    
----
commit f251849a99d8571f0b252a1f42c7cc4231ec0a7b
Author: anuruddhal <an...@gmail.com>
Date:   2015-04-22T06:20:50Z

    Moving non-API methods to StratosApiV41Utils class from StratosApiV41 class

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by prabathabey <gi...@git.apache.org>.
Github user prabathabey commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35573073
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    --- End diff --
    
    It's generally not acceptable to catch generic exceptions. If done intentionally, might be good to add a comment explaining the reason why it was done this way.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by anuruddhal <gi...@git.apache.org>.
Github user anuruddhal commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35632867
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    +            String msg = "Invalid email is provided";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        String tenantDomain = tenantInfoBean.getTenantDomain();
    +        try {
    +            TenantMgtUtil.validateDomain(tenantDomain);
    +        } catch (Exception e) {
    +            String msg = "Tenant domain validation error for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
    +                getRegistry(RegistryType.USER_GOVERNANCE);
    +        if (userRegistry == null) {
    +            log.error("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +            throw new RestAPIException("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +        }
    +
    +        if (userRegistry.getTenantId() != MultitenantConstants.SUPER_TENANT_ID) {
    +            log.error("Security alert! None super tenant trying to create a tenant.");
    +            throw new RestAPIException("Security alert! None super tenant trying to create a tenant.");
    +        }
    +
    +        Tenant tenant = TenantMgtUtil
    +                .initializeTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        TenantPersistor persistor = ServiceHolder.getTenantPersistor();
    +        // not validating the domain ownership, since created by super tenant
    +        int tenantId; //TODO verify whether this is the correct approach (isSkeleton)
    +        try {
    +            tenantId = persistor
    +                    .persistTenant(tenant, false, tenantInfoBean.getSuccessKey(), tenantInfoBean.getOriginatedService(),
    +                            false);
    +        } catch (Exception e) {
    +            String msg = "Could not add tenant: " + e.getMessage();
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        tenantInfoBean.setTenantId(tenantId);
    +
    +        try {
    +            TenantMgtUtil.addClaimsToUserStoreManager(tenant);
    +        } catch (Exception e) {
    +            String msg = "Error in granting permissions for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        //Notify tenant addition
    +        try {
    +            TenantMgtUtil.triggerAddTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        } catch (StratosException e) {
    +            String msg = "Error in notifying tenant addition.";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        // For the super tenant tenant creation, tenants are always activated as they are created.
    +        try {
    +            TenantMgtUtil.activateTenantInitially(
    +                    ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean), tenantId);
    +        } catch (Exception e) {
    +            String msg = "Error in initial activation of tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        try {
    +            TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
    +        } catch (RegistryException e) {
    +            String msg = "Error in preparing theme mgt page for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +    }
    +
    +    /**
    +     * Update Existing Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws Exception
    +     */
    +    public static void updateExistingTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws Exception {
    +
    +        TenantManager tenantManager = ServiceHolder.getTenantManager();
    +        UserStoreManager userStoreManager;
    +
    +        // filling the non-set admin and admin password first
    +        UserRegistry configSystemRegistry = ServiceHolder.getRegistryService()
    +                .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 TenantNotFoundException(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);
    --- End diff --
    
    Fixed with 49f34bb42d9d7a91953d95262bd4552936ea4193


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by prabathabey <gi...@git.apache.org>.
Github user prabathabey commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35573573
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    +            String msg = "Invalid email is provided";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        String tenantDomain = tenantInfoBean.getTenantDomain();
    +        try {
    +            TenantMgtUtil.validateDomain(tenantDomain);
    +        } catch (Exception e) {
    +            String msg = "Tenant domain validation error for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
    +                getRegistry(RegistryType.USER_GOVERNANCE);
    +        if (userRegistry == null) {
    +            log.error("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +            throw new RestAPIException("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +        }
    +
    +        if (userRegistry.getTenantId() != MultitenantConstants.SUPER_TENANT_ID) {
    +            log.error("Security alert! None super tenant trying to create a tenant.");
    +            throw new RestAPIException("Security alert! None super tenant trying to create a tenant.");
    +        }
    +
    +        Tenant tenant = TenantMgtUtil
    +                .initializeTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        TenantPersistor persistor = ServiceHolder.getTenantPersistor();
    +        // not validating the domain ownership, since created by super tenant
    +        int tenantId; //TODO verify whether this is the correct approach (isSkeleton)
    +        try {
    +            tenantId = persistor
    +                    .persistTenant(tenant, false, tenantInfoBean.getSuccessKey(), tenantInfoBean.getOriginatedService(),
    +                            false);
    +        } catch (Exception e) {
    +            String msg = "Could not add tenant: " + e.getMessage();
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        tenantInfoBean.setTenantId(tenantId);
    +
    +        try {
    +            TenantMgtUtil.addClaimsToUserStoreManager(tenant);
    +        } catch (Exception e) {
    +            String msg = "Error in granting permissions for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        //Notify tenant addition
    +        try {
    +            TenantMgtUtil.triggerAddTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        } catch (StratosException e) {
    +            String msg = "Error in notifying tenant addition.";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        // For the super tenant tenant creation, tenants are always activated as they are created.
    +        try {
    +            TenantMgtUtil.activateTenantInitially(
    +                    ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean), tenantId);
    +        } catch (Exception e) {
    +            String msg = "Error in initial activation of tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        try {
    +            TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
    +        } catch (RegistryException e) {
    +            String msg = "Error in preparing theme mgt page for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +    }
    +
    +    /**
    +     * Update Existing Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws Exception
    +     */
    +    public static void updateExistingTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws Exception {
    +
    +        TenantManager tenantManager = ServiceHolder.getTenantManager();
    +        UserStoreManager userStoreManager;
    +
    +        // filling the non-set admin and admin password first
    +        UserRegistry configSystemRegistry = ServiceHolder.getRegistryService()
    +                .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 TenantNotFoundException(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);
    --- End diff --
    
    Generic exception is thrown here as well. Need fixing with the substitution of an appropriate implementation specific checked-exception.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/stratos/pull/287


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by prabathabey <gi...@git.apache.org>.
Github user prabathabey commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35573320
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    +            String msg = "Invalid email is provided";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        String tenantDomain = tenantInfoBean.getTenantDomain();
    +        try {
    +            TenantMgtUtil.validateDomain(tenantDomain);
    +        } catch (Exception e) {
    +            String msg = "Tenant domain validation error for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
    +                getRegistry(RegistryType.USER_GOVERNANCE);
    +        if (userRegistry == null) {
    +            log.error("Security alert! User registry is null. A user is trying create a tenant "
    --- End diff --
    
    If this is necessary, a better option would be to assign the error message to a variable and re-use it for logging and throwing exceptions.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by anuruddhal <gi...@git.apache.org>.
Github user anuruddhal commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35633488
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -173,7 +193,7 @@ public static void removeCartridge(String cartridgeType) throws RestAPIException
                     log.info(String.format("Successfully removed cartridge: [cartridge-type] %s ", cartridgeType));
                 }
             } catch (Exception e) {
    -            String msg = "Could not remove cartridge";
    +            String msg = "Could not remove cartridge "+e.getLocalizedMessage();
    --- End diff --
    
    Already fixed in the latest code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by anuruddhal <gi...@git.apache.org>.
Github user anuruddhal commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35633294
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    +            String msg = "Invalid email is provided";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        String tenantDomain = tenantInfoBean.getTenantDomain();
    +        try {
    +            TenantMgtUtil.validateDomain(tenantDomain);
    +        } catch (Exception e) {
    +            String msg = "Tenant domain validation error for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
    +                getRegistry(RegistryType.USER_GOVERNANCE);
    +        if (userRegistry == null) {
    +            log.error("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +            throw new RestAPIException("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +        }
    +
    +        if (userRegistry.getTenantId() != MultitenantConstants.SUPER_TENANT_ID) {
    +            log.error("Security alert! None super tenant trying to create a tenant.");
    --- End diff --
    
    Fixed with 49f34bb


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by anuruddhal <gi...@git.apache.org>.
Github user anuruddhal commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35633501
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2220,7 +2239,7 @@ public static void removeDeploymentPolicy(String deploymentPolicyID)
             try {
                 AutoscalerServiceClient.getInstance().removeDeploymentPolicy(deploymentPolicyID);
             } catch (Exception e) {
    -            String msg = "Could not remove deployment policy";
    +            String msg = "Could not remove deployment policy "+e.getLocalizedMessage();
    --- End diff --
    
    Already fixed in the latest code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by anuruddhal <gi...@git.apache.org>.
Github user anuruddhal commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35633495
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2203,7 +2222,7 @@ public static void updateDeploymentPolicy(DeploymentPolicyBean deploymentPolicyD
                 log.error(msg, e);
                 throw new RestAPIException(msg);
             } catch (Exception e) {
    -            String msg = "Could not update deployment policy";
    +            String msg = "Could not update deployment policy "+e.getLocalizedMessage();
    --- End diff --
    
    Already fixed in the latest code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by prabathabey <gi...@git.apache.org>.
Github user prabathabey commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35573608
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    +            String msg = "Invalid email is provided";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        String tenantDomain = tenantInfoBean.getTenantDomain();
    +        try {
    +            TenantMgtUtil.validateDomain(tenantDomain);
    +        } catch (Exception e) {
    +            String msg = "Tenant domain validation error for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
    +                getRegistry(RegistryType.USER_GOVERNANCE);
    +        if (userRegistry == null) {
    +            log.error("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +            throw new RestAPIException("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +        }
    +
    +        if (userRegistry.getTenantId() != MultitenantConstants.SUPER_TENANT_ID) {
    +            log.error("Security alert! None super tenant trying to create a tenant.");
    +            throw new RestAPIException("Security alert! None super tenant trying to create a tenant.");
    +        }
    +
    +        Tenant tenant = TenantMgtUtil
    +                .initializeTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        TenantPersistor persistor = ServiceHolder.getTenantPersistor();
    +        // not validating the domain ownership, since created by super tenant
    +        int tenantId; //TODO verify whether this is the correct approach (isSkeleton)
    +        try {
    +            tenantId = persistor
    +                    .persistTenant(tenant, false, tenantInfoBean.getSuccessKey(), tenantInfoBean.getOriginatedService(),
    +                            false);
    +        } catch (Exception e) {
    +            String msg = "Could not add tenant: " + e.getMessage();
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        tenantInfoBean.setTenantId(tenantId);
    +
    +        try {
    +            TenantMgtUtil.addClaimsToUserStoreManager(tenant);
    +        } catch (Exception e) {
    +            String msg = "Error in granting permissions for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        //Notify tenant addition
    +        try {
    +            TenantMgtUtil.triggerAddTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        } catch (StratosException e) {
    +            String msg = "Error in notifying tenant addition.";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        // For the super tenant tenant creation, tenants are always activated as they are created.
    +        try {
    +            TenantMgtUtil.activateTenantInitially(
    +                    ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean), tenantId);
    +        } catch (Exception e) {
    +            String msg = "Error in initial activation of tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        try {
    +            TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
    +        } catch (RegistryException e) {
    +            String msg = "Error in preparing theme mgt page for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +    }
    +
    +    /**
    +     * Update Existing Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws Exception
    +     */
    +    public static void updateExistingTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws Exception {
    +
    +        TenantManager tenantManager = ServiceHolder.getTenantManager();
    +        UserStoreManager userStoreManager;
    +
    +        // filling the non-set admin and admin password first
    +        UserRegistry configSystemRegistry = ServiceHolder.getRegistryService()
    +                .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 TenantNotFoundException(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("");
    --- End diff --
    
    Why not null?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by anuruddhal <gi...@git.apache.org>.
Github user anuruddhal commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35633207
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    +            String msg = "Invalid email is provided";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        String tenantDomain = tenantInfoBean.getTenantDomain();
    +        try {
    +            TenantMgtUtil.validateDomain(tenantDomain);
    +        } catch (Exception e) {
    +            String msg = "Tenant domain validation error for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
    +                getRegistry(RegistryType.USER_GOVERNANCE);
    +        if (userRegistry == null) {
    +            log.error("Security alert! User registry is null. A user is trying create a tenant "
    --- End diff --
    
    Fixed with 49f34bb


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r28853335
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    +            String msg = "Invalid email is provided";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        String tenantDomain = tenantInfoBean.getTenantDomain();
    +        try {
    +            TenantMgtUtil.validateDomain(tenantDomain);
    +        } catch (Exception e) {
    +            String msg = "Tenant domain validation error for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
    +                getRegistry(RegistryType.USER_GOVERNANCE);
    +        if (userRegistry == null) {
    +            log.error("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +            throw new RestAPIException("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +        }
    +
    +        if (userRegistry.getTenantId() != MultitenantConstants.SUPER_TENANT_ID) {
    +            log.error("Security alert! None super tenant trying to create a tenant.");
    +            throw new RestAPIException("Security alert! None super tenant trying to create a tenant.");
    +        }
    +
    +        Tenant tenant = TenantMgtUtil
    +                .initializeTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        TenantPersistor persistor = ServiceHolder.getTenantPersistor();
    +        // not validating the domain ownership, since created by super tenant
    +        int tenantId; //TODO verify whether this is the correct approach (isSkeleton)
    +        try {
    +            tenantId = persistor
    +                    .persistTenant(tenant, false, tenantInfoBean.getSuccessKey(), tenantInfoBean.getOriginatedService(),
    +                            false);
    +        } catch (Exception e) {
    +            String msg = "Could not add tenant: " + e.getMessage();
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        tenantInfoBean.setTenantId(tenantId);
    +
    +        try {
    +            TenantMgtUtil.addClaimsToUserStoreManager(tenant);
    +        } catch (Exception e) {
    +            String msg = "Error in granting permissions for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        //Notify tenant addition
    +        try {
    +            TenantMgtUtil.triggerAddTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        } catch (StratosException e) {
    +            String msg = "Error in notifying tenant addition.";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        // For the super tenant tenant creation, tenants are always activated as they are created.
    +        try {
    +            TenantMgtUtil.activateTenantInitially(
    +                    ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean), tenantId);
    +        } catch (Exception e) {
    +            String msg = "Error in initial activation of tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        try {
    +            TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
    +        } catch (RegistryException e) {
    +            String msg = "Error in preparing theme mgt page for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +    }
    +
    +    /**
    +     * Update Existing Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws Exception
    +     */
    +    public static void updateExistingTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws Exception {
    +
    +        TenantManager tenantManager = ServiceHolder.getTenantManager();
    +        UserStoreManager userStoreManager;
    +
    +        // filling the non-set admin and admin password first
    +        UserRegistry configSystemRegistry = ServiceHolder.getRegistryService()
    +                .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);
    --- End diff --
    
    May be throwing Exception is not a good practice. Shall we change this to specific exception type? May be something like TenantManagementException.
    Thanks


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by prabathabey <gi...@git.apache.org>.
Github user prabathabey commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35572904
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2203,7 +2222,7 @@ public static void updateDeploymentPolicy(DeploymentPolicyBean deploymentPolicyD
                 log.error(msg, e);
                 throw new RestAPIException(msg);
             } catch (Exception e) {
    -            String msg = "Could not update deployment policy";
    +            String msg = "Could not update deployment policy "+e.getLocalizedMessage();
    --- End diff --
    
    More formatting issues.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by prabathabey <gi...@git.apache.org>.
Github user prabathabey commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35573262
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    +            String msg = "Invalid email is provided";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        String tenantDomain = tenantInfoBean.getTenantDomain();
    +        try {
    +            TenantMgtUtil.validateDomain(tenantDomain);
    +        } catch (Exception e) {
    +            String msg = "Tenant domain validation error for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
    +                getRegistry(RegistryType.USER_GOVERNANCE);
    +        if (userRegistry == null) {
    +            log.error("Security alert! User registry is null. A user is trying create a tenant "
    --- End diff --
    
    Log and throw is generally considered a bad practice. If not extremely necessary, we should probably be able to get rid of it in this sort of instances.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by prabathabey <gi...@git.apache.org>.
Github user prabathabey commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35572885
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -173,7 +193,7 @@ public static void removeCartridge(String cartridgeType) throws RestAPIException
                     log.info(String.format("Successfully removed cartridge: [cartridge-type] %s ", cartridgeType));
                 }
             } catch (Exception e) {
    -            String msg = "Could not remove cartridge";
    +            String msg = "Could not remove cartridge "+e.getLocalizedMessage();
    --- End diff --
    
    Please fix formatting issues here as well.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on the pull request:

    https://github.com/apache/stratos/pull/287#issuecomment-95072957
  
    @anuruddhal Please add a description to this pull request.
    Thanks


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by anuruddhal <gi...@git.apache.org>.
Github user anuruddhal commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35633276
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    --- End diff --
    
    Fixed with https://github.com/apache/stratos/pull/405


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r28853408
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    +            String msg = "Invalid email is provided";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        String tenantDomain = tenantInfoBean.getTenantDomain();
    +        try {
    +            TenantMgtUtil.validateDomain(tenantDomain);
    +        } catch (Exception e) {
    +            String msg = "Tenant domain validation error for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
    +                getRegistry(RegistryType.USER_GOVERNANCE);
    +        if (userRegistry == null) {
    +            log.error("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +            throw new RestAPIException("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +        }
    +
    +        if (userRegistry.getTenantId() != MultitenantConstants.SUPER_TENANT_ID) {
    +            log.error("Security alert! None super tenant trying to create a tenant.");
    +            throw new RestAPIException("Security alert! None super tenant trying to create a tenant.");
    +        }
    +
    +        Tenant tenant = TenantMgtUtil
    +                .initializeTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        TenantPersistor persistor = ServiceHolder.getTenantPersistor();
    +        // not validating the domain ownership, since created by super tenant
    +        int tenantId; //TODO verify whether this is the correct approach (isSkeleton)
    +        try {
    +            tenantId = persistor
    +                    .persistTenant(tenant, false, tenantInfoBean.getSuccessKey(), tenantInfoBean.getOriginatedService(),
    +                            false);
    +        } catch (Exception e) {
    +            String msg = "Could not add tenant: " + e.getMessage();
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        tenantInfoBean.setTenantId(tenantId);
    +
    +        try {
    +            TenantMgtUtil.addClaimsToUserStoreManager(tenant);
    +        } catch (Exception e) {
    +            String msg = "Error in granting permissions for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        //Notify tenant addition
    +        try {
    +            TenantMgtUtil.triggerAddTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        } catch (StratosException e) {
    +            String msg = "Error in notifying tenant addition.";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        // For the super tenant tenant creation, tenants are always activated as they are created.
    +        try {
    +            TenantMgtUtil.activateTenantInitially(
    +                    ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean), tenantId);
    +        } catch (Exception e) {
    +            String msg = "Error in initial activation of tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        try {
    +            TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
    +        } catch (RegistryException e) {
    +            String msg = "Error in preparing theme mgt page for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +    }
    +
    +    /**
    +     * Update Existing Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws Exception
    +     */
    +    public static void updateExistingTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws Exception {
    +
    +        TenantManager tenantManager = ServiceHolder.getTenantManager();
    +        UserStoreManager userStoreManager;
    +
    +        // filling the non-set admin and admin password first
    +        UserRegistry configSystemRegistry = ServiceHolder.getRegistryService()
    +                .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 TenantNotFoundException(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);
    --- End diff --
    
    The same concern here, might be its better to throw a specific exception rather than using Exception.
    Thanks


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by prabathabey <gi...@git.apache.org>.
Github user prabathabey commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35572842
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -126,7 +146,7 @@ public static void updateCartridge(CartridgeBean cartridgeDefinition) throws Res
                 log.error(msg, e);
                 throw new RestAPIException(msg);
             } catch (Exception e) {
    -            String msg = "Could not update cartridge";
    +            String msg = "Could not update cartridge "+e.getLocalizedMessage();
    --- End diff --
    
    Fix formatting issues.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by anuruddhal <gi...@git.apache.org>.
Github user anuruddhal commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35633482
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -126,7 +146,7 @@ public static void updateCartridge(CartridgeBean cartridgeDefinition) throws Res
                 log.error(msg, e);
                 throw new RestAPIException(msg);
             } catch (Exception e) {
    -            String msg = "Could not update cartridge";
    +            String msg = "Could not update cartridge "+e.getLocalizedMessage();
    --- End diff --
    
    Already fixed in the latest code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by prabathabey <gi...@git.apache.org>.
Github user prabathabey commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35572931
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2220,7 +2239,7 @@ public static void removeDeploymentPolicy(String deploymentPolicyID)
             try {
                 AutoscalerServiceClient.getInstance().removeDeploymentPolicy(deploymentPolicyID);
             } catch (Exception e) {
    -            String msg = "Could not remove deployment policy";
    +            String msg = "Could not remove deployment policy "+e.getLocalizedMessage();
    --- End diff --
    
    This particular formatting issue too needs to be fixed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by anuruddhal <gi...@git.apache.org>.
Github user anuruddhal commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35632741
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    +            String msg = "Invalid email is provided";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        String tenantDomain = tenantInfoBean.getTenantDomain();
    +        try {
    +            TenantMgtUtil.validateDomain(tenantDomain);
    +        } catch (Exception e) {
    +            String msg = "Tenant domain validation error for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
    +                getRegistry(RegistryType.USER_GOVERNANCE);
    +        if (userRegistry == null) {
    +            log.error("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +            throw new RestAPIException("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +        }
    +
    +        if (userRegistry.getTenantId() != MultitenantConstants.SUPER_TENANT_ID) {
    +            log.error("Security alert! None super tenant trying to create a tenant.");
    +            throw new RestAPIException("Security alert! None super tenant trying to create a tenant.");
    +        }
    +
    +        Tenant tenant = TenantMgtUtil
    +                .initializeTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        TenantPersistor persistor = ServiceHolder.getTenantPersistor();
    +        // not validating the domain ownership, since created by super tenant
    +        int tenantId; //TODO verify whether this is the correct approach (isSkeleton)
    +        try {
    +            tenantId = persistor
    +                    .persistTenant(tenant, false, tenantInfoBean.getSuccessKey(), tenantInfoBean.getOriginatedService(),
    +                            false);
    +        } catch (Exception e) {
    +            String msg = "Could not add tenant: " + e.getMessage();
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        tenantInfoBean.setTenantId(tenantId);
    +
    +        try {
    +            TenantMgtUtil.addClaimsToUserStoreManager(tenant);
    +        } catch (Exception e) {
    +            String msg = "Error in granting permissions for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        //Notify tenant addition
    +        try {
    +            TenantMgtUtil.triggerAddTenant(ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean));
    +        } catch (StratosException e) {
    +            String msg = "Error in notifying tenant addition.";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +        // For the super tenant tenant creation, tenants are always activated as they are created.
    +        try {
    +            TenantMgtUtil.activateTenantInitially(
    +                    ObjectConverter.convertTenantInfoBeanToCarbonTenantInfoBean(tenantInfoBean), tenantId);
    +        } catch (Exception e) {
    +            String msg = "Error in initial activation of tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        try {
    +            TenantMgtUtil.prepareStringToShowThemeMgtPage(tenant.getId());
    +        } catch (RegistryException e) {
    +            String msg = "Error in preparing theme mgt page for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +    }
    +
    +    /**
    +     * Update Existing Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws Exception
    +     */
    +    public static void updateExistingTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws Exception {
    +
    +        TenantManager tenantManager = ServiceHolder.getTenantManager();
    +        UserStoreManager userStoreManager;
    +
    +        // filling the non-set admin and admin password first
    +        UserRegistry configSystemRegistry = ServiceHolder.getRegistryService()
    +                .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 TenantNotFoundException(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("");
    --- End diff --
    
    Fixed with https://github.com/apache/stratos/pull/405


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Moving non-API methods to StratosApiV41Utils...

Posted by prabathabey <gi...@git.apache.org>.
Github user prabathabey commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/287#discussion_r35573348
  
    --- Diff: components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java ---
    @@ -2239,4 +2258,501 @@ public static ClusterBean getClusterInfo(String clusterId) throws RestAPIExcepti
     
             return ObjectConverter.convertClusterToClusterBean(cluster, clusterId);
         }
    +
    +    //util methods for Tenants
    +
    +    /**
    +     * Add Tenant
    +     *
    +     * @param tenantInfoBean
    +     * @throws RestAPIException
    +     */
    +    public static void addTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws RestAPIException {
    +
    +        try {
    +            CommonUtil.validateEmail(tenantInfoBean.getEmail());
    +        } catch (Exception e) {
    +            String msg = "Invalid email is provided";
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        String tenantDomain = tenantInfoBean.getTenantDomain();
    +        try {
    +            TenantMgtUtil.validateDomain(tenantDomain);
    +        } catch (Exception e) {
    +            String msg = "Tenant domain validation error for tenant " + tenantDomain;
    +            log.error(msg, e);
    +            throw new RestAPIException(msg);
    +        }
    +
    +        UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
    +                getRegistry(RegistryType.USER_GOVERNANCE);
    +        if (userRegistry == null) {
    +            log.error("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +            throw new RestAPIException("Security alert! User registry is null. A user is trying create a tenant "
    +                    + " without an authenticated session.");
    +        }
    +
    +        if (userRegistry.getTenantId() != MultitenantConstants.SUPER_TENANT_ID) {
    +            log.error("Security alert! None super tenant trying to create a tenant.");
    --- End diff --
    
    The same goes here as well.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---