From 64d194bfea72d6a5f55ac20f41f1c8f92d13d401 Mon Sep 17 00:00:00 2001 From: rajitha Date: Mon, 10 Apr 2023 03:29:10 +0530 Subject: [PATCH] add tenant-mgt module --- .../DeviceManagementServiceComponent.java | 4 +- .../io.entgra.tenant.mgt.common/pom.xml | 49 +++++++ .../common/exception/TenantMgtException.java | 11 ++ .../mgt/common/spi/TenantManagerService.java | 10 ++ .../io.entgra.tenant.mgt.core/pom.xml | 115 +++++++++++++++++ .../entgra/tenant/mgt/core/TenantManager.java | 10 ++ .../mgt/core/impl/TenantManagerImpl.java | 122 ++++++++++++++++++ .../core/impl/TenantManagerServiceImpl.java | 27 ++++ .../core/internal/TenantMgtDataHolder.java | 53 ++++++++ .../internal/TenantMgtServiceComponent.java | 74 +++++++++++ .../listener/DeviceMgtTenantListener.java | 74 +++++++++++ components/tenant-mgt/pom.xml | 23 ++++ .../pom.xml | 94 ++++++++++++++ .../src/main/resources/build.properties | 1 + .../src/main/resources/p2.inf | 1 + features/tenant-mgt/pom.xml | 19 +++ pom.xml | 15 ++- 17 files changed, 699 insertions(+), 3 deletions(-) create mode 100644 components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml create mode 100644 components/tenant-mgt/io.entgra.tenant.mgt.common/src/main/java/io/entgra/tenant/mgt/common/exception/TenantMgtException.java create mode 100644 components/tenant-mgt/io.entgra.tenant.mgt.common/src/main/java/io/entgra/tenant/mgt/common/spi/TenantManagerService.java create mode 100644 components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml create mode 100644 components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/TenantManager.java create mode 100644 components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/impl/TenantManagerImpl.java create mode 100644 components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/impl/TenantManagerServiceImpl.java create mode 100644 components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/internal/TenantMgtDataHolder.java create mode 100644 components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/internal/TenantMgtServiceComponent.java create mode 100644 components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/listener/DeviceMgtTenantListener.java create mode 100644 components/tenant-mgt/pom.xml create mode 100644 features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml create mode 100644 features/tenant-mgt/io.entgra.tenant.mgt.server.feature/src/main/resources/build.properties create mode 100644 features/tenant-mgt/io.entgra.tenant.mgt.server.feature/src/main/resources/p2.inf create mode 100644 features/tenant-mgt/pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index f36def494d..180730dd6c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -271,8 +271,8 @@ public class DeviceManagementServiceComponent { componentContext.getBundleContext().registerService(PrivacyComplianceProvider.class.getName(), privacyComplianceProvider, null); - componentContext.getBundleContext() - .registerService(TenantMgtListener.class.getName(), new DeviceMgtTenantMgtListener(), null); +// componentContext.getBundleContext() +// .registerService(TenantMgtListener.class.getName(), new DeviceMgtTenantMgtListener(), null); if (log.isDebugEnabled()) { log.debug("Device management core bundle has been successfully initialized"); diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml b/components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml new file mode 100644 index 0000000000..2c81fb58c6 --- /dev/null +++ b/components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml @@ -0,0 +1,49 @@ + + + + tenant-mgt + org.wso2.carbon.devicemgt + 5.0.25-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.tenant.mgt.common + Entgra IoT - Tenant Manager Common + Entgra IoT - Tenant Manager Common + bundle + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Tenant Management Common Bundle + + org.apache.commons.logging, + org.wso2.carbon.stratos.common.beans + + io.entgra.tenant.mgt.common.* + + + + + + + + + org.wso2.carbon.commons + org.wso2.carbon.tenant.common + ${carbon.commons.version} + + + + \ No newline at end of file diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.common/src/main/java/io/entgra/tenant/mgt/common/exception/TenantMgtException.java b/components/tenant-mgt/io.entgra.tenant.mgt.common/src/main/java/io/entgra/tenant/mgt/common/exception/TenantMgtException.java new file mode 100644 index 0000000000..c0e278bd2b --- /dev/null +++ b/components/tenant-mgt/io.entgra.tenant.mgt.common/src/main/java/io/entgra/tenant/mgt/common/exception/TenantMgtException.java @@ -0,0 +1,11 @@ +package io.entgra.tenant.mgt.common.exception; + +public class TenantMgtException extends Exception { + public TenantMgtException(String msg, Throwable ex) { + super(msg, ex); + } + + public TenantMgtException(String msg) { + super(msg); + } +} diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.common/src/main/java/io/entgra/tenant/mgt/common/spi/TenantManagerService.java b/components/tenant-mgt/io.entgra.tenant.mgt.common/src/main/java/io/entgra/tenant/mgt/common/spi/TenantManagerService.java new file mode 100644 index 0000000000..a721e03029 --- /dev/null +++ b/components/tenant-mgt/io.entgra.tenant.mgt.common/src/main/java/io/entgra/tenant/mgt/common/spi/TenantManagerService.java @@ -0,0 +1,10 @@ +package io.entgra.tenant.mgt.common.spi; + +import io.entgra.tenant.mgt.common.exception.TenantMgtException; +import org.wso2.carbon.stratos.common.beans.TenantInfoBean; + +public interface TenantManagerService { + void addDefaultRoles(TenantInfoBean tenantInfoBean) throws TenantMgtException; + + void addDefaultAppCategories(TenantInfoBean tenantInfoBean) throws TenantMgtException; +} \ No newline at end of file diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml b/components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml new file mode 100644 index 0000000000..76284fea49 --- /dev/null +++ b/components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml @@ -0,0 +1,115 @@ + + + + tenant-mgt + org.wso2.carbon.devicemgt + 5.0.25-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.tenant.mgt.core + Entgra IoT - Tenant Manager Core + Entgra IoT - Tenant Manager Core + bundle + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Tenant Management Core Bundle + io.entgra.tenant.mgt.core.internal + + org.osgi.framework.*;version="${imp.package.version.osgi.framework}", + org.osgi.service.*;version="${imp.package.version.osgi.service}", + org.apache.commons.logging, + io.entgra.application.mgt.common.*, + io.entgra.application.mgt.core.config, + org.wso2.carbon.device.mgt.core, + org.wso2.carbon.user.api, + org.wso2.carbon.registry.core.exceptions, + io.entgra.tenant.mgt.common.*, + org.wso2.carbon.stratos.common.beans, + org.wso2.carbon.stratos.common.exception, + org.wso2.carbon.stratos.common.listeners, + org.wso2.carbon.device.mgt.common.metadata.mgt, + org.wso2.carbon.device.mgt.core.metadata.mgt, + org.wso2.carbon.user.core.service, + org.wso2.carbon.context + + + !io.entgra.tenant.mgt.core.internal, + io.entgra.tenant.mgt.core.* + + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.wso2.carbon.commons + org.wso2.carbon.tenant.common + ${carbon.commons.version} + + + org.wso2.carbon + org.wso2.carbon.registry.core + + + org.wso2.carbon + org.wso2.carbon.user.core + + + org.wso2.carbon + org.wso2.carbon.user.api + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + + + org.wso2.carbon.devicemgt + io.entgra.application.mgt.core + + + org.wso2.carbon.devicemgt + io.entgra.application.mgt.common + + + org.wso2.carbon.devicemgt + io.entgra.tenant.mgt.common + + + org.wso2.carbon + org.wso2.carbon.utils + + + + \ No newline at end of file diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/TenantManager.java b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/TenantManager.java new file mode 100644 index 0000000000..2f9b63281b --- /dev/null +++ b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/TenantManager.java @@ -0,0 +1,10 @@ +package io.entgra.tenant.mgt.core; + +import io.entgra.tenant.mgt.common.exception.TenantMgtException; +import org.wso2.carbon.stratos.common.beans.TenantInfoBean; + +public interface TenantManager { + void addDefaultRoles(TenantInfoBean tenantInfoBean) throws TenantMgtException; + + void addDefaultAppCategories(TenantInfoBean tenantInfoBean) throws TenantMgtException; +} diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/impl/TenantManagerImpl.java b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/impl/TenantManagerImpl.java new file mode 100644 index 0000000000..8782f7ca1a --- /dev/null +++ b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/impl/TenantManagerImpl.java @@ -0,0 +1,122 @@ +package io.entgra.tenant.mgt.core.impl; + +import io.entgra.application.mgt.common.exception.ApplicationManagementException; +import io.entgra.application.mgt.common.exception.InvalidConfigurationException; +import io.entgra.application.mgt.core.config.ConfigurationManager; +import io.entgra.application.mgt.common.services.ApplicationManager; +import io.entgra.tenant.mgt.core.TenantManager; +import io.entgra.tenant.mgt.common.exception.TenantMgtException; +import io.entgra.tenant.mgt.core.internal.TenantMgtDataHolder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; +import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils; +import org.wso2.carbon.registry.core.exceptions.RegistryException; +import org.wso2.carbon.stratos.common.beans.TenantInfoBean; +import org.wso2.carbon.user.api.Permission; +import org.wso2.carbon.device.mgt.common.exceptions.MetadataManagementException; +import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException; +import org.wso2.carbon.device.mgt.common.roles.config.Role; +import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.user.api.UserStoreManager; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class TenantManagerImpl implements TenantManager { + private static final Log log = LogFactory.getLog(TenantManagerImpl.class); + private static final String PERMISSION_ACTION = "ui.execute"; + + @Override + public void addDefaultRoles(TenantInfoBean tenantInfoBean) throws TenantMgtException { + initTenantFlow(tenantInfoBean); + DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); + if (config.getDefaultRoles().isEnabled()) { + Map> roleMap = getValidRoleMap(config); + try { + UserStoreManager userStoreManager = TenantMgtDataHolder.getInstance().getRealmService() + .getTenantUserRealm(tenantInfoBean.getTenantId()).getUserStoreManager(); + + roleMap.forEach((key, value) -> { + 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); + } + }); + } catch (UserStoreException e) { + String msg = "Error occurred while getting user store manager"; + log.error(msg, e); + throw new TenantMgtException(msg, e); + } + } + try { + TenantMgtDataHolder.getInstance().getWhiteLabelManagementService(). + addDefaultWhiteLabelThemeIfNotExist(tenantInfoBean.getTenantId()); + } catch (MetadataManagementException e) { + String msg = "Error occurred while adding default white label theme to created tenant - id "+tenantInfoBean.getTenantId(); + log.error(msg, e); + throw new TenantMgtException(msg, e); + } finally { + endTenantFlow(); + } + } + + @Override + public void addDefaultAppCategories(TenantInfoBean tenantInfoBean) throws TenantMgtException { + initTenantFlow(tenantInfoBean); + try { + ApplicationManager applicationManager = TenantMgtDataHolder.getInstance().getApplicationManager(); + applicationManager + .addApplicationCategories(ConfigurationManager.getInstance().getConfiguration().getAppCategories()); + } catch (InvalidConfigurationException e) { + String msg = "Error occurred while getting application manager"; + throw new TenantMgtException(msg, e); + } catch (ApplicationManagementException e) { + String msg = "Error occurred while getting default application categories"; + log.error(msg, e); + throw new TenantMgtException(msg, e); + } finally { + endTenantFlow(); + } + + } + + private void initTenantFlow(TenantInfoBean tenantInfoBean) { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + privilegedCarbonContext.setTenantId(tenantInfoBean.getTenantId()); + privilegedCarbonContext.setTenantDomain(tenantInfoBean.getTenantDomain()); + } + + private void endTenantFlow() { + PrivilegedCarbonContext.endTenantFlow(); + } + + private Map> getValidRoleMap(DeviceManagementConfig config) { + Map> roleMap = new HashMap<>(); + try { + for (Role role : config.getDefaultRoles().getRoles()) { + List permissionList = new ArrayList<>(); + for (String permissionPath : role.getPermissions()) { + if (PermissionUtils.checkResourceExists(permissionPath)) { + Permission permission = new Permission(permissionPath, PERMISSION_ACTION); + + permissionList.add(permission); + } else { + log.warn("Permission " + permissionPath + " does not exist. Hence it will not add to role " + + role.getName()); + } + } + roleMap.put(role.getName(), permissionList); + } + } catch (PermissionManagementException | RegistryException e) { + log.error("Error occurred while checking permission existence.", e); + } + return roleMap; + } +} diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/impl/TenantManagerServiceImpl.java b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/impl/TenantManagerServiceImpl.java new file mode 100644 index 0000000000..760e49f4e8 --- /dev/null +++ b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/impl/TenantManagerServiceImpl.java @@ -0,0 +1,27 @@ +package io.entgra.tenant.mgt.core.impl; + +import io.entgra.tenant.mgt.common.spi.TenantManagerService; +import io.entgra.tenant.mgt.core.TenantManager; +import io.entgra.tenant.mgt.common.exception.TenantMgtException; +import io.entgra.tenant.mgt.core.internal.TenantMgtDataHolder; +import org.wso2.carbon.stratos.common.beans.TenantInfoBean; + +public class TenantManagerServiceImpl implements TenantManagerService { + + private final TenantManager tenantManager; + + public TenantManagerServiceImpl() { + tenantManager = new TenantManagerImpl(); + TenantMgtDataHolder.getInstance().setTenantManager(tenantManager); + } + + @Override + public void addDefaultRoles(TenantInfoBean tenantInfoBean) throws TenantMgtException { + tenantManager.addDefaultRoles(tenantInfoBean); + } + + @Override + public void addDefaultAppCategories(TenantInfoBean tenantInfoBean) throws TenantMgtException { + tenantManager.addDefaultAppCategories(tenantInfoBean); + } +} diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/internal/TenantMgtDataHolder.java b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/internal/TenantMgtDataHolder.java new file mode 100644 index 0000000000..6f9d603a3f --- /dev/null +++ b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/internal/TenantMgtDataHolder.java @@ -0,0 +1,53 @@ +package io.entgra.tenant.mgt.core.internal; + +import io.entgra.application.mgt.common.services.ApplicationManager; +import io.entgra.tenant.mgt.core.TenantManager; +import org.wso2.carbon.device.mgt.common.metadata.mgt.WhiteLabelManagementService; +import org.wso2.carbon.user.core.service.RealmService; + +public class TenantMgtDataHolder { + private static final TenantMgtDataHolder instance = new TenantMgtDataHolder(); + private TenantManager tenantManager; + + private ApplicationManager applicationManager; + + private WhiteLabelManagementService whiteLabelManagementService; + + private RealmService realmService; + + public RealmService getRealmService() { + return realmService; + } + + public void setRealmService(RealmService realmService) { + this.realmService = realmService; + } + + public ApplicationManager getApplicationManager() { + return applicationManager; + } + + public void setApplicationManager(ApplicationManager applicationManager) { + this.applicationManager = applicationManager; + } + + public WhiteLabelManagementService getWhiteLabelManagementService() { + return whiteLabelManagementService; + } + + public void setWhiteLabelManagementService(WhiteLabelManagementService whiteLabelManagementService) { + this.whiteLabelManagementService = whiteLabelManagementService; + } + + public TenantManager getTenantManager() { + return tenantManager; + } + + public void setTenantManager(TenantManager tenantManager) { + this.tenantManager = tenantManager; + } + + public static TenantMgtDataHolder getInstance() { + return instance; + } +} diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/internal/TenantMgtServiceComponent.java b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/internal/TenantMgtServiceComponent.java new file mode 100644 index 0000000000..ac2b0be69b --- /dev/null +++ b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/internal/TenantMgtServiceComponent.java @@ -0,0 +1,74 @@ +package io.entgra.tenant.mgt.core.internal; + +import io.entgra.application.mgt.common.services.ApplicationManager; +import io.entgra.tenant.mgt.common.spi.TenantManagerService; +import io.entgra.tenant.mgt.core.impl.TenantManagerServiceImpl; +import io.entgra.tenant.mgt.core.listener.DeviceMgtTenantListener; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.device.mgt.common.metadata.mgt.WhiteLabelManagementService; +import org.wso2.carbon.device.mgt.core.metadata.mgt.WhiteLabelManagementServiceImpl; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * @scr.component name="org.wso2.carbon.devicemgt.tenant.manager" immediate="true" + * @scr.reference name="org.wso2.carbon.application.mgt.service" + * interface="io.entgra.application.mgt.common.services.ApplicationManager" + * cardinality="1..1" + * policy="dynamic" + * bind="setApplicationManager" + * unbind="unsetApplicationManager" + * @scr.reference name="user.realmservice.default" + * interface="org.wso2.carbon.user.core.service.RealmService" + * cardinality="1..1" + * policy="dynamic" + * bind="setRealmService" + * unbind="unsetRealmService" + */ + +public class TenantMgtServiceComponent { + + private static final Log log = LogFactory.getLog(TenantManagerService.class); + + @SuppressWarnings("unused") + protected void activate(ComponentContext componentContext) { + try { + TenantManagerService tenantManagerService = new TenantManagerServiceImpl(); + componentContext.getBundleContext(). + registerService(TenantManagerServiceImpl.class.getName(), tenantManagerService, null); + WhiteLabelManagementService whiteLabelManagementService = new WhiteLabelManagementServiceImpl(); + componentContext.getBundleContext().registerService(WhiteLabelManagementServiceImpl.class.getName(), + whiteLabelManagementService, null); + TenantMgtDataHolder.getInstance().setWhiteLabelManagementService(whiteLabelManagementService); + DeviceMgtTenantListener deviceMgtTenantListener = new DeviceMgtTenantListener(); + componentContext.getBundleContext(). + registerService(DeviceMgtTenantListener.class.getName(), deviceMgtTenantListener, null); + log.info("Tenant management service activated"); + } catch (Throwable t) { + String msg = "Error occurred while activating tenant management service"; + log.error(msg, t); + } + } + + @SuppressWarnings("unused") + protected void deactivate(ComponentContext componentContext) { + // nothing to do + } + + protected void setApplicationManager(ApplicationManager applicationManager) { + TenantMgtDataHolder.getInstance().setApplicationManager(applicationManager); + } + + protected void unsetApplicationManager(ApplicationManager applicationManager) { + TenantMgtDataHolder.getInstance().setApplicationManager(null); + } + + protected void setRealmService(RealmService realmService) { + TenantMgtDataHolder.getInstance().setRealmService(realmService); + } + + protected void unsetRealmService(RealmService realmService) { + TenantMgtDataHolder.getInstance().setRealmService(null); + } +} diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/listener/DeviceMgtTenantListener.java b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/listener/DeviceMgtTenantListener.java new file mode 100644 index 0000000000..43e31cf4e0 --- /dev/null +++ b/components/tenant-mgt/io.entgra.tenant.mgt.core/src/main/java/io/entgra/tenant/mgt/core/listener/DeviceMgtTenantListener.java @@ -0,0 +1,74 @@ +package io.entgra.tenant.mgt.core.listener; + +import io.entgra.tenant.mgt.core.TenantManager; +import io.entgra.tenant.mgt.common.exception.TenantMgtException; +import io.entgra.tenant.mgt.core.internal.TenantMgtDataHolder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.stratos.common.beans.TenantInfoBean; +import org.wso2.carbon.stratos.common.exception.StratosException; +import org.wso2.carbon.stratos.common.listeners.TenantMgtListener; + +public class DeviceMgtTenantListener implements TenantMgtListener { + + private static final Log log = LogFactory.getLog(DeviceMgtTenantListener.class); + public static final int LISTENER_EXECUTION_ORDER = 11; + + @Override + public void onTenantCreate(TenantInfoBean tenantInfoBean) { + // Any work to be performed after a tenant creation + TenantManager tenantManager = TenantMgtDataHolder.getInstance().getTenantManager(); + try { + tenantManager.addDefaultRoles(tenantInfoBean); + tenantManager.addDefaultAppCategories(tenantInfoBean); + } catch (TenantMgtException e) { + String msg = "Error occurred while executing tenant creation flow"; + log.error(msg, e); + } + } + + @Override + public void onTenantUpdate(TenantInfoBean tenantInfoBean) throws StratosException { + // Any work to be performed after a tenant information update happens + } + + @Override + public void onTenantDelete(int i) { + // Any work to be performed after a tenant deletion + } + + @Override + public void onTenantRename(int i, String s, String s1) throws StratosException { + // Any work to be performed after a tenant rename happens + } + + @Override + public void onTenantInitialActivation(int i) throws StratosException { + // Any work to be performed after a tenant's initial activation happens + } + + @Override + public void onTenantActivation(int i) throws StratosException { + // Any work to be performed after a tenant activation + } + + @Override + public void onTenantDeactivation(int i) throws StratosException { + // Any work to be performed after a tenant deactivation + } + + @Override + public void onSubscriptionPlanChange(int i, String s, String s1) throws StratosException { + // Any work to be performed after subscription plan change + } + + @Override + public int getListenerOrder() { + return LISTENER_EXECUTION_ORDER; + } + + @Override + public void onPreDelete(int i) throws StratosException { + // Any work to be performed before a tenant is deleted + } +} diff --git a/components/tenant-mgt/pom.xml b/components/tenant-mgt/pom.xml new file mode 100644 index 0000000000..58b3ebceb0 --- /dev/null +++ b/components/tenant-mgt/pom.xml @@ -0,0 +1,23 @@ + + + + carbon-devicemgt + org.wso2.carbon.devicemgt + 5.0.25-SNAPSHOT + ../../pom.xml + + + 4.0.0 + tenant-mgt + pom + Entgra IoT - Tenant Management Component + Entgra IoT - Tenant Management Component + + + io.entgra.tenant.mgt.core + io.entgra.tenant.mgt.common + + + \ No newline at end of file diff --git a/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml b/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml new file mode 100644 index 0000000000..04cf1bb3e5 --- /dev/null +++ b/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml @@ -0,0 +1,94 @@ + + + + tenant-mgt-feature + org.wso2.carbon.devicemgt + 5.0.25-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.tenant.mgt.server.feature + Entgra IoT - Tenant Management Server Feature + Entgra IoT - Tenant Management Server Feature + pom + + + + org.wso2.carbon.devicemgt + io.entgra.tenant.mgt.core + + + org.wso2.carbon.devicemgt + io.entgra.tenant.mgt.common + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + io.entgra.tenant.mgt.server + ../../etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + + org.eclipse.equinox.p2.type.group:true + + + + + + + org.wso2.carbon.devicemgt:io.entgra.tenant.mgt.core:${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt:io.entgra.tenant.mgt.common:${carbon.device.mgt.version} + + + + + + + + + + \ No newline at end of file diff --git a/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/src/main/resources/build.properties b/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/src/main/resources/build.properties new file mode 100644 index 0000000000..920f577888 --- /dev/null +++ b/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/src/main/resources/build.properties @@ -0,0 +1 @@ +custom=true \ No newline at end of file diff --git a/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/src/main/resources/p2.inf b/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/src/main/resources/p2.inf new file mode 100644 index 0000000000..7ab37b9d7d --- /dev/null +++ b/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/src/main/resources/p2.inf @@ -0,0 +1 @@ +instructions.configure = \ \ No newline at end of file diff --git a/features/tenant-mgt/pom.xml b/features/tenant-mgt/pom.xml new file mode 100644 index 0000000000..d55378a8cb --- /dev/null +++ b/features/tenant-mgt/pom.xml @@ -0,0 +1,19 @@ + + + + + carbon-devicemgt + org.wso2.carbon.devicemgt + 5.0.25-SNAPSHOT + ../../pom.xml + + + 4.0.0 + tenant-mgt-feature + pom + Entgra IoT - Tenant Management Feature + + + io.entgra.tenant.mgt.server.feature + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2851e5865f..7eee718846 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,7 @@ components/webapp-authenticator-framework components/logger components/task-mgt + components/tenant-mgt features/device-mgt features/apimgt-extensions features/application-mgt @@ -62,7 +63,7 @@ features/webapp-authenticator-framework features/logger features/task-mgt - + features/tenant-mgt @@ -370,6 +371,18 @@ + + + org.wso2.carbon.devicemgt + io.entgra.tenant.mgt.common + ${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt + io.entgra.tenant.mgt.core + ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt