diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index e0ce6e82a7..9f386b1e74 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -358,6 +358,14 @@ org.wso2.carbon.devicemgt io.entgra.notification.logger + + org.wso2.carbon.devicemgt + io.entgra.application.mgt.core + + + org.wso2.carbon.devicemgt + io.entgra.application.mgt.common + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceMgtTenantMgtListener.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceMgtTenantMgtListener.java index 5e0e0cff93..dcb54ef1d6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceMgtTenantMgtListener.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/DeviceMgtTenantMgtListener.java @@ -17,6 +17,9 @@ package org.wso2.carbon.device.mgt.core.util; +import io.entgra.application.mgt.common.exception.ApplicationManagementException; +import io.entgra.application.mgt.core.config.ConfigurationManager; +import io.entgra.application.mgt.core.util.ApplicationManagementUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; @@ -32,6 +35,7 @@ import org.wso2.carbon.stratos.common.listeners.TenantMgtListener; import org.wso2.carbon.user.api.Permission; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; +import io.entgra.application.mgt.common.services.ApplicationManager; import java.util.ArrayList; import java.util.HashMap; @@ -46,12 +50,12 @@ public class DeviceMgtTenantMgtListener implements TenantMgtListener { @Override public void onTenantCreate(TenantInfoBean tenantInfoBean) { DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); - if (config.getDefaultRoles().isEnabled()) { - Map> roleMap = getValidRoleMap(config); - try { - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext() - .setTenantDomain(tenantInfoBean.getTenantDomain(), true); + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantInfoBean.getTenantDomain(), true); + + if (config.getDefaultRoles().isEnabled()) { + Map> roleMap = getValidRoleMap(config); UserStoreManager userStoreManager = DeviceManagementDataHolder.getInstance().getRealmService() .getTenantUserRealm(tenantInfoBean.getTenantId()).getUserStoreManager(); @@ -59,14 +63,24 @@ public class DeviceMgtTenantMgtListener implements TenantMgtListener { try { userStoreManager.addRole(key, null, value.toArray(new Permission[0])); } catch (UserStoreException e) { - log.error("Error occurred while adding default roles into user store.", e); + log.error("Error occurred while adding default roles into user store", e); } }); - } catch (UserStoreException e) { - log.error("Error occurred while getting user store manager.", e); - } finally { - PrivilegedCarbonContext.endTenantFlow(); } + + List defaultCategories = ConfigurationManager.getInstance().getConfiguration().getAppCategories(); + if(defaultCategories != null && !defaultCategories.isEmpty()) { + ApplicationManager applicationManager = ApplicationManagementUtil.getApplicationManagerInstance(); + applicationManager.addApplicationCategories(defaultCategories); + log.info("Successfully registered default categories into tenant "+tenantInfoBean.getTenantDomain()); + } + + } catch (UserStoreException e) { + log.error("Error occurred while getting user store manager", e); + } catch (ApplicationManagementException e) { + log.error("Error occurred while registering default categories to tenant "+tenantInfoBean.getTenantDomain()); + } finally { + PrivilegedCarbonContext.endTenantFlow(); } }