From 3333ed03812be0f4f8c6cff0c9de2ab41effa797 Mon Sep 17 00:00:00 2001 From: Hasunie Date: Mon, 19 Jun 2017 19:18:34 +0530 Subject: [PATCH 1/6] Fixing permission issue which resolves wso2/product-iots#430 --- .../devicemgt/app/modules/business-controllers/user.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index f8c420d58c6..ff37153c434 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -110,6 +110,7 @@ var userModule = function () { * @returns {number} HTTP Status code 201 if succeeded, 409 if user already exists */ publicMethods.registerUser = function (username, firstname, lastname, emailAddress, password, userRoles) { + log.info("Register user:::::::::"); var carbon = require('carbon'); var tenantId = carbon.server.tenantId(); var url = carbon.server.address('https') + "/admin/services"; @@ -632,11 +633,17 @@ var userModule = function () { var url = carbon.server.address('https') + "/admin/services"; var server = new carbon.server.Server(url); var userManager = new carbon.user.UserManager(server, tenantId); + try { if (!userManager.roleExists(roleName)) { userManager.addRole(roleName, users, permissions); } else { - log.info("Role exist with name: " + roleName); + var array = Object.keys(permissions); + var i, permission; + for (i = 0; i < array.length; i++) { + permission = array[i]; + userManager.authorizeRole(roleName, permission, "ui.execute"); + } } } catch (e) { throw e; From 19495321d2374afaf1081ca26eee8b8d70fba668 Mon Sep 17 00:00:00 2001 From: Hasunie Date: Mon, 19 Jun 2017 19:23:01 +0530 Subject: [PATCH 2/6] removing unnecessary lines --- .../devicemgt/app/modules/business-controllers/user.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index ff37153c434..24e7cc696d5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -110,13 +110,11 @@ var userModule = function () { * @returns {number} HTTP Status code 201 if succeeded, 409 if user already exists */ publicMethods.registerUser = function (username, firstname, lastname, emailAddress, password, userRoles) { - log.info("Register user:::::::::"); var carbon = require('carbon'); var tenantId = carbon.server.tenantId(); var url = carbon.server.address('https') + "/admin/services"; var server = new carbon.server.Server(url); var userManager = new carbon.user.UserManager(server, tenantId); - try { if (userManager.userExists(username)) { if (log.isDebugEnabled()) { From dcbffac1988d578949184b58418970193dc31922 Mon Sep 17 00:00:00 2001 From: Ace Date: Thu, 22 Jun 2017 15:12:40 +0530 Subject: [PATCH 3/6] Adding fixes for https://github.com/wso2/product-iots/issues/997 --- .../org.wso2.carbon.device.mgt.api/pom.xml | 10 ++++ .../impl/RoleManagementServiceImpl.java | 60 +++++++++++++++++++ pom.xml | 5 ++ 3 files changed, 75 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index 6b32f6b8052..4d83651f9d6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -301,6 +301,16 @@ org.wso2.carbon.identity.jwt.client.extension provided + + org.wso2.carbon + org.wso2.carbon.registry.core + provided + + + org.wso2.carbon.registry + org.wso2.carbon.registry.resource + provided + org.wso2.carbon.identity.framework org.wso2.carbon.identity.user.store.count diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index e947c258c04..d396237df4b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -22,6 +22,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.context.RegistryType; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; @@ -30,6 +32,9 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer; +import org.wso2.carbon.registry.api.Registry; +import org.wso2.carbon.registry.core.session.UserRegistry; +import org.wso2.carbon.registry.resource.services.utils.ChangeRolePermissionsUtil; import org.wso2.carbon.user.api.*; import org.wso2.carbon.user.core.common.AbstractUserStoreManager; import org.wso2.carbon.user.mgt.UserRealmProxy; @@ -296,6 +301,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { } } userStoreManager.addRole(roleInfo.getRoleName(), roleInfo.getUsers(), permissions); + authorizeRoleForAppmgt(roleInfo.getRoleName(), roleInfo.getPermissions()); //TODO fix what's returned in the entity return Response.created(new URI(API_BASE_PATH + "/" + URLEncoder.encode(roleInfo.getRoleName(), "UTF-8"))). @@ -450,6 +456,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { authorizationManager.authorizeRole(roleName, permission, CarbonConstants.UI_PERMISSION_ACTION); } } + authorizeRoleForAppmgt(roleName, roleInfo.getPermissions()); } //TODO: Need to send the updated role information in the entity back to the client return Response.status(Response.Status.OK).entity("Role '" + roleInfo.getRoleName() + "' has " + @@ -467,6 +474,59 @@ public class RoleManagementServiceImpl implements RoleManagementService { } } + /** + * When presented with role and a set of permissions, if given role has permission to + * perform mobile app management, said role will be given rights mobile app collection in the + * governance registry. + * + * @param role + * @param permissions + * @return state of role update Operation + */ + private boolean authorizeRoleForAppmgt(String role, String[] permissions) { + String permissionString = + "ra^true:rd^false:wa^true:wd^false:da^true:dd^false:aa^true:ad^false"; + String resourcePath = "/_system/governance/mobileapps/"; + boolean appmPermAvailable = false; + + if (permissions != null) { + for (int i = 0; i < permissions.length; i++) + switch (permissions[i]) { + case "/permission/admin/manage/mobileapp": + appmPermAvailable = true; + break; + case "/permission/admin/manage/mobileapp/create": + appmPermAvailable = true; + break; + case "/permission/admin/manage/mobileapp/publish": + appmPermAvailable = true; + break; + } + } + + if (appmPermAvailable) { + try { + Registry registry = CarbonContext.getThreadLocalCarbonContext(). + getRegistry(RegistryType.SYSTEM_GOVERNANCE); + ChangeRolePermissionsUtil.changeRolePermissions((UserRegistry) registry, + resourcePath, role + ":" + permissionString); + + return true; + } catch (Exception e) { + String msg = "Error while retrieving user registry in order to update permissions " + + "for resource : " + resourcePath; + log.error(msg, e); + return false; + } + } else { + if (log.isDebugEnabled()) { + log.debug("Mobile App Management permissions not selected, therefore role : " + + role + " not given permission for registry collection : " + resourcePath); + } + return false; + } + } + @DELETE @Path("/{roleName}") @Override diff --git a/pom.xml b/pom.xml index d082af790a3..a9aa099d9fe 100644 --- a/pom.xml +++ b/pom.xml @@ -1523,6 +1523,11 @@ org.wso2.carbon.event.stream.stub ${carbon.analytics.common.version} + + org.wso2.carbon.registry + org.wso2.carbon.registry.resource + 4.6.5 + From 07357124b015190b70c2b76839cb622c682fbd75 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 22 Jun 2017 15:45:11 +0530 Subject: [PATCH 4/6] Fixing the task for all the tenants --- .../carbon/device/mgt/core/dao/DeviceDAO.java | 2 + .../core/dao/impl/AbstractDeviceDAOImpl.java | 23 +++++ .../DeviceManagementProviderService.java | 2 + .../DeviceManagementProviderServiceImpl.java | 15 ++++ .../task/impl/DeviceDetailsRetrieverTask.java | 73 +++++++++++++--- .../policy/mgt/core/task/MonitoringTask.java | 83 +++++++++++++++---- 6 files changed, 169 insertions(+), 29 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index 14ac17dd956..f6a0a363b4a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -420,5 +420,7 @@ public interface DeviceDAO { */ List getEnrolmentsByStatus(List deviceIds, Status status, int tenantId) throws DeviceManagementDAOException; + + List getDeviceEnrolledTenants() throws DeviceManagementDAOException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index d62f2c1674c..0a941e84f64 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -1071,4 +1071,27 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { return devices; } + + public List getDeviceEnrolledTenants() throws DeviceManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + List tenants = new ArrayList<>(); + try { + conn = this.getConnection(); + String sql = "SELECT distinct(TENANT_ID) FROM DM_DEVICE"; + stmt = conn.prepareStatement(sql); + rs = stmt.executeQuery(); + while (rs.next()) { + tenants.add(rs.getInt("TENANT_ID")); + } + } catch (SQLException e) { + throw new DeviceManagementDAOException("Error occurred while retrieving tenants which have " + + "device registered.", e); + } finally { + DeviceManagementDAOUtil.cleanupResources(stmt, rs); + } + return tenants; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 09911f3cd6a..d2df0e2c3b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -558,4 +558,6 @@ public interface DeviceManagementProviderService { */ boolean changeDeviceStatus(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status newStatus) throws DeviceManagementException; + + List getDeviceEnrolledTenants() throws DeviceManagementException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 77934202b2b..33a10a8d213 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -1468,6 +1468,21 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return isDeviceUpdated; } + @Override + public List getDeviceEnrolledTenants() throws DeviceManagementException { + try { + DeviceManagementDAOFactory.openConnection(); + return deviceDAO.getDeviceEnrolledTenants(); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while retrieving the tenants " + + "which have device enrolled.", e); + } catch (SQLException e) { + throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + } + private boolean updateEnrollment(int deviceId, EnrolmentInfo enrolmentInfo, int tenantId) throws DeviceManagementException { boolean isUpdatedEnrollment = false; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java index 6d1228563c1..7dc2d97079e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java @@ -22,20 +22,25 @@ package org.wso2.carbon.device.mgt.core.task.impl; import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; +import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException; import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager; import org.wso2.carbon.ntask.core.Task; +import org.wso2.carbon.user.api.UserStoreException; +import java.util.List; import java.util.Map; public class DeviceDetailsRetrieverTask implements Task { private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class); -// private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(); private String deviceType; private String oppConfig; private OperationMonitoringTaskConfig operationMonitoringTaskConfig; + private boolean executeForTenants = false; @Override public void setProperties(Map map) { @@ -54,19 +59,65 @@ public class DeviceDetailsRetrieverTask implements Task { @Override public void execute() { - if (log.isDebugEnabled()) { - log.debug("Device details retrieving task started to run."); + + if(System.getProperty("is.cloud") != null && Boolean.parseBoolean(System.getProperty("is.cloud"))){ + executeForTenants = true; + } + if(executeForTenants){ + this.executeForAllTenants(); + } else { + + if (log.isDebugEnabled()) { + log.debug("Device details retrieving task started to run."); + } + + DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, + operationMonitoringTaskConfig); + //pass the configurations also from here, monitoring tasks + try { + deviceTaskManager.addOperations(); + } catch (DeviceMgtTaskException e) { + log.error( + "Error occurred while trying to add the operations to device to retrieve device details.", + e); + } } + } + + + private void executeForAllTenants() { - DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, - operationMonitoringTaskConfig); - //pass the configurations also from here, monitoring tasks + if (log.isDebugEnabled()) { + log.debug("Device details retrieving task started to run for all tenants."); + } try { - deviceTaskManager.addOperations(); - } catch (DeviceMgtTaskException e) { - log.error( - "Error occurred while trying to add the operations to device to retrieve device details.", - e); + List tenants = DeviceManagementDataHolder.getInstance(). + getDeviceManagementProvider().getDeviceEnrolledTenants(); + for (Integer tenant : tenants) { + String tenantDomain = DeviceManagementDataHolder.getInstance(). + getRealmService().getTenantManager().getDomain(tenant); + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant); + DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, + operationMonitoringTaskConfig); + //pass the configurations also from here, monitoring tasks + try { + deviceTaskManager.addOperations(); + } catch (DeviceMgtTaskException e) { + log.error("Error occurred while trying to add the operations to " + + "device to retrieve device details.", e); + } + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } + } catch (UserStoreException e) { + log.error("Error occurred while trying to get the available tenants", e); + } catch (DeviceManagementException e) { + log.error("Error occurred while trying to get the available tenants " + + "from device manager provider service.", e); } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java index a70fb4db757..06563430199 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java @@ -21,14 +21,18 @@ package org.wso2.carbon.policy.mgt.core.task; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; import org.wso2.carbon.ntask.core.Task; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.mgt.MonitoringManager; +import org.wso2.carbon.user.api.UserStoreException; import java.util.ArrayList; import java.util.List; @@ -39,6 +43,7 @@ public class MonitoringTask implements Task { private static Log log = LogFactory.getLog(MonitoringTask.class); Map properties; + private boolean executeForTenants = false; @Override @@ -56,6 +61,66 @@ public class MonitoringTask implements Task { if (log.isDebugEnabled()) { log.debug("Monitoring task started to run."); } + if(System.getProperty("is.cloud") != null && Boolean.parseBoolean(System.getProperty("is.cloud"))){ + executeForTenants = true; + } + if(executeForTenants) { + this.executeforAllTenants(); + } else { + this.executeTask(); + } + } + + /** + * Check whether Device platform (ex: android) is exist in the cdm-config.xml file before adding a + * Monitoring operation to a specific device type. + * + * @param deviceType available device types. + * @return return platform is exist(true) or not (false). + */ + + private boolean isPlatformExist(String deviceType) { + PolicyMonitoringManager policyMonitoringManager = PolicyManagementDataHolder.getInstance() + .getDeviceManagementService().getPolicyMonitoringManager(deviceType); + if (policyMonitoringManager != null) { + return true; + } + return false; + } + + + private void executeforAllTenants() { + + if (log.isDebugEnabled()) { + log.debug("Monitoring task started to run for all tenants."); + } + try { + DeviceManagementProviderService deviceManagementService = new DeviceManagementProviderServiceImpl(); + List tenants = deviceManagementService.getDeviceEnrolledTenants(); + for (Integer tenant : tenants) { + String tenantDomain = PolicyManagementDataHolder.getInstance(). + getRealmService().getTenantManager().getDomain(tenant); + try { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant); + + this.executeTask(); + + } finally { + PrivilegedCarbonContext.endTenantFlow(); + } + } + } catch (UserStoreException e) { + log.error("Error occurred while trying to get the available tenants", e); + } catch (DeviceManagementException e) { + log.error("Error occurred while trying to get the available tenants from device manager service ", e); + } + + } + + + private void executeTask(){ MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager(); List deviceTypes = new ArrayList<>(); @@ -121,23 +186,5 @@ public class MonitoringTask implements Task { } else { log.info("No device types registered currently. So did not run the monitoring task."); } - - } - - /** - * Check whether Device platform (ex: android) is exist in the cdm-config.xml file before adding a - * Monitoring operation to a specific device type. - * - * @param deviceType available device types. - * @return return platform is exist(true) or not (false). - */ - - private boolean isPlatformExist(String deviceType) { - PolicyMonitoringManager policyMonitoringManager = PolicyManagementDataHolder.getInstance() - .getDeviceManagementService().getPolicyMonitoringManager(deviceType); - if (policyMonitoringManager != null) { - return true; - } - return false; } } From 5f71313af1342421155661d0fd9dc86571faaec8 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 22 Jun 2017 15:53:11 +0530 Subject: [PATCH 5/6] Fixing formating issues --- .../mgt/core/task/impl/DeviceDetailsRetrieverTask.java | 7 +------ .../wso2/carbon/policy/mgt/core/task/MonitoringTask.java | 5 ----- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java index 7dc2d97079e..4a8ace7bbdb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java @@ -66,11 +66,9 @@ public class DeviceDetailsRetrieverTask implements Task { if(executeForTenants){ this.executeForAllTenants(); } else { - if (log.isDebugEnabled()) { log.debug("Device details retrieving task started to run."); } - DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, operationMonitoringTaskConfig); //pass the configurations also from here, monitoring tasks @@ -78,13 +76,11 @@ public class DeviceDetailsRetrieverTask implements Task { deviceTaskManager.addOperations(); } catch (DeviceMgtTaskException e) { log.error( - "Error occurred while trying to add the operations to device to retrieve device details.", - e); + "Error occurred while trying to add the operations to device to retrieve device details.", e); } } } - private void executeForAllTenants() { if (log.isDebugEnabled()) { @@ -119,7 +115,6 @@ public class DeviceDetailsRetrieverTask implements Task { log.error("Error occurred while trying to get the available tenants " + "from device manager provider service.", e); } - } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java index 06563430199..3be4e2a5626 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java @@ -88,7 +88,6 @@ public class MonitoringTask implements Task { return false; } - private void executeforAllTenants() { if (log.isDebugEnabled()) { @@ -104,9 +103,7 @@ public class MonitoringTask implements Task { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant); - this.executeTask(); - } finally { PrivilegedCarbonContext.endTenantFlow(); } @@ -116,10 +113,8 @@ public class MonitoringTask implements Task { } catch (DeviceManagementException e) { log.error("Error occurred while trying to get the available tenants from device manager service ", e); } - } - private void executeTask(){ MonitoringManager monitoringManager = PolicyManagementDataHolder.getInstance().getMonitoringManager(); From 1655b512b009b55a9f51a75a752ed06dc3617275 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 22 Jun 2017 15:55:22 +0530 Subject: [PATCH 6/6] Fixing formating issues --- .../device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java | 3 ++- .../org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java index 4a8ace7bbdb..7b65a3b6ee5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java @@ -41,6 +41,7 @@ public class DeviceDetailsRetrieverTask implements Task { private String oppConfig; private OperationMonitoringTaskConfig operationMonitoringTaskConfig; private boolean executeForTenants = false; + private final String IS_CLOUD = "is.cloud"; @Override public void setProperties(Map map) { @@ -60,7 +61,7 @@ public class DeviceDetailsRetrieverTask implements Task { @Override public void execute() { - if(System.getProperty("is.cloud") != null && Boolean.parseBoolean(System.getProperty("is.cloud"))){ + if(System.getProperty(IS_CLOUD) != null && Boolean.parseBoolean(System.getProperty(IS_CLOUD))){ executeForTenants = true; } if(executeForTenants){ diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java index 3be4e2a5626..f489a1386a6 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/task/MonitoringTask.java @@ -44,6 +44,7 @@ public class MonitoringTask implements Task { Map properties; private boolean executeForTenants = false; + private final String IS_CLOUD = "is.cloud"; @Override @@ -61,7 +62,7 @@ public class MonitoringTask implements Task { if (log.isDebugEnabled()) { log.debug("Monitoring task started to run."); } - if(System.getProperty("is.cloud") != null && Boolean.parseBoolean(System.getProperty("is.cloud"))){ + if(System.getProperty(IS_CLOUD) != null && Boolean.parseBoolean(System.getProperty(IS_CLOUD))){ executeForTenants = true; } if(executeForTenants) {