From f0471203e70a23bbf8d2fe51f772f5b7b6461af4 Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 17 Nov 2015 18:28:42 +0530 Subject: [PATCH] Added logic to skip device authorization for policy operations --- .../mgt/core/DeviceManagementConstants.java | 11 +++++++++++ .../operation/mgt/OperationManagerImpl.java | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java index d5554fbf53..1b0cf9ee10 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java @@ -17,6 +17,8 @@ */ package org.wso2.carbon.device.mgt.core; +import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation; + public final class DeviceManagementConstants { public static final class Common { @@ -47,4 +49,13 @@ public final class DeviceManagementConstants { public static final String ENROL_NOTIFICATION_TYPE = "enrol"; public static final String USER_REGISTRATION_NOTIFICATION_TYPE = "userRegistration"; } + + public static final class AuthorizationSkippedOperationCodes { + private AuthorizationSkippedOperationCodes() { + throw new AssertionError(); + } + + public static final String MONITOR_OPERATION_CODE = "MONITOR"; + public static final String POLICY_OPERATION_CODE = PolicyOperation.POLICY_OPERATION_CODE; + } } 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 0337a0a079..3238fcdb32 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 @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorization import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; +import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; @@ -83,7 +84,7 @@ public class OperationManagerImpl implements OperationManager { } try { List authorizedDeviceList; - if (operation != null && PolicyOperation.POLICY_OPERATION_CODE.equals(operation.getCode())) { + if (operation != null && isAuthenticationSkippedOperation(operation)) { authorizedDeviceList = deviceIds; } else { authorizedDeviceList = DeviceManagementDataHolder.getInstance(). @@ -618,4 +619,20 @@ public class OperationManagerImpl implements OperationManager { return CarbonContext.getThreadLocalCarbonContext().getUsername(); } + private boolean isAuthenticationSkippedOperation(Operation operation) { + boolean status; + switch (operation.getCode()) { + case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_OPERATION_CODE : + status = true; + break; + case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE : + status = true; + break; + default: + status = false; + } + + return status; + } + }