From fbc7c0807c4634757d6a7f1e836d1d0f75ec69c8 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Wed, 30 Mar 2016 14:10:17 +0530 Subject: [PATCH] Skipping the validation of task operations --- .../operation/mgt/OperationManagerImpl.java | 9 +++++++ .../mgt/core/task/DeviceTaskManager.java | 8 ++++++ .../core/task/impl/DeviceTaskManagerImpl.java | 26 +++++++++++++++---- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index b6bcb4ce1c..265dd02f8c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -37,6 +37,8 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOF import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationMappingDAO; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.util.OperationDAOUtil; import org.wso2.carbon.device.mgt.core.operation.mgt.util.OperationCreateTimeComparator; +import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager; +import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerImpl; import java.sql.SQLException; import java.util.ArrayList; @@ -679,6 +681,13 @@ public class OperationManagerImpl implements OperationManager { } private boolean isAuthenticationSkippedOperation(Operation operation) { + + //This is to check weather operations are coming from the task related to retrieving device information. + DeviceTaskManager taskManager = new DeviceTaskManagerImpl(); + if (taskManager.isTaskOperation(operation.getCode())) { + return true; + } + boolean status; switch (operation.getCode()) { case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_OPERATION_CODE : diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/DeviceTaskManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/DeviceTaskManager.java index cc8ff8515f..9e3306cbc1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/DeviceTaskManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/DeviceTaskManager.java @@ -68,4 +68,12 @@ public interface DeviceTaskManager { */ List getValidOperationNames() throws DeviceMgtTaskException; + /** + * This method will check wheather give operation is added by the task. + * @param opName - Operation name + * @return - true or false + * @throws DeviceMgtTaskException + */ + boolean isTaskOperation(String opName); + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java index 813caf7f3b..cc9e8ac40b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java @@ -76,7 +76,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { @Override public String getTaskImplementedClazz() throws DeviceMgtTaskException { - return DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). + return DeviceConfigurationManager.getInstance().getDeviceManagementConfig(). getDeviceManagementConfigRepository().getTaskConfiguration().getTaskClazz(); } @@ -97,7 +97,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { List devices = deviceManagementProviderService.getAllDevices(); List operations = this.getValidOperationNames(); - if(!devices.isEmpty()) { + if (!devices.isEmpty()) { for (String str : operations) { CommandOperation operation = new CommandOperation(); @@ -107,12 +107,12 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { deviceManagementProviderService.addOperation(operation, DeviceManagerUtil.convertDevices(devices)); } } else { - if(log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("No devices are available to perform the operations."); } } } catch (DeviceManagementException e) { - throw new DeviceMgtTaskException("Error occurred while retrieving the device list.", e); + throw new DeviceMgtTaskException("Error occurred while retrieving the device list.", e); } catch (OperationManagementException e) { throw new DeviceMgtTaskException("Error occurred while adding the operations to devices", e); } @@ -142,10 +142,26 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { } } - if(log.isDebugEnabled()){ + if (log.isDebugEnabled()) { log.debug("Valid operation names are : " + Arrays.toString(opNames.toArray())); } return opNames; } + + @Override + public boolean isTaskOperation(String opName) { + try { + List taskOperations = this.getOperationList(); + for (TaskOperation taop : taskOperations) { + if (taop.getTaskName().equalsIgnoreCase(opName)) { + return true; + } + } + } catch (DeviceMgtTaskException e) { + // ignoring the error, no need to throw, If error occurs, return value will be false. + } + return false; + + } }