From 6e1fdabaad89963082c1731ac30838bdef5d5562 Mon Sep 17 00:00:00 2001 From: harshanl Date: Fri, 14 Oct 2016 17:13:43 +0530 Subject: [PATCH 1/3] EMM-1342:Added policy revoke operation --- .../carbon/device/mgt/core/DeviceManagementConstants.java | 2 ++ .../mgt/core/operation/mgt/OperationManagerImpl.java | 3 +++ .../core/enforcement/PolicyEnforcementDelegatorImpl.java | 6 +----- .../mgt/core/impl/PolicyAdministratorPointImpl.java | 8 ++------ 4 files changed, 8 insertions(+), 11 deletions(-) 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 62e38e6a66..2b5398fb88 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,7 @@ */ package org.wso2.carbon.device.mgt.core; +import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants; import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation; public final class DeviceManagementConstants { @@ -57,6 +58,7 @@ public final class DeviceManagementConstants { public static final String MONITOR_OPERATION_CODE = "MONITOR"; public static final String POLICY_OPERATION_CODE = PolicyOperation.POLICY_OPERATION_CODE; + public static final String POLICY_REVOKE_OPERATION_CODE = OperationMgtConstants.OperationCodes.POLICY_REVOKE; } public static final class EmailAttributes { 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 50407a85f4..9cffdb5bf8 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 @@ -881,6 +881,9 @@ public class OperationManagerImpl implements OperationManager { case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE: status = true; break; + case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_REVOKE_OPERATION_CODE: + status = true; + break; default: status = false; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java index 90f7acd875..304482f136 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java @@ -70,14 +70,10 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato Policy policy = this.getEffectivePolicy(identifier); if (policy != null) { - List deviceIdentifiers = new ArrayList<>(); - deviceIdentifiers.add(identifier); - this.addPolicyOperation(deviceIdentifiers, policy); - } else { - //This means all the applicable policies have been removed. Hence sending policy-revoke operation. List deviceIdentifiers = new ArrayList<>(); deviceIdentifiers.add(identifier); this.addPolicyRevokeOperation(deviceIdentifiers); + this.addPolicyOperation(deviceIdentifiers, policy); } } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index 1f82cb780b..2c5de5d729 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -107,7 +107,8 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { @Override public boolean deletePolicy(Policy policy) throws PolicyManagementException { boolean bool = policyManager.deletePolicy(policy); - PolicyCacheManagerImpl.getInstance().rePopulateCache(); + PolicyCacheManager policyCacheManager = PolicyCacheManagerImpl.getInstance(); + policyCacheManager.rePopulateCache(); return bool; } @@ -116,11 +117,6 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { boolean bool =policyManager.deletePolicy(policyId); PolicyCacheManager policyCacheManager = PolicyCacheManagerImpl.getInstance(); policyCacheManager.rePopulateCache(); - List appliedPolicies = policyCacheManager.getAllPolicies(); - //This means all the policies have been deleted. Hence triggering publishChanges to take immediate effect. - if (appliedPolicies.isEmpty()) { - this.publishChanges(); - } return bool; } From 73539362d49efbe3461563b77735932652706b39 Mon Sep 17 00:00:00 2001 From: harshanl Date: Fri, 14 Oct 2016 17:33:41 +0530 Subject: [PATCH 2/3] Refactored PolicyAdministratorPointImpl --- .../policy/mgt/core/impl/PolicyAdministratorPointImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index 2c5de5d729..e742a10ff4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -114,7 +114,7 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { @Override public boolean deletePolicy(int policyId) throws PolicyManagementException { - boolean bool =policyManager.deletePolicy(policyId); + boolean bool = policyManager.deletePolicy(policyId); PolicyCacheManager policyCacheManager = PolicyCacheManagerImpl.getInstance(); policyCacheManager.rePopulateCache(); return bool; From 036ed6fe4161b7b9cb9562831829a813b295ab55 Mon Sep 17 00:00:00 2001 From: harshanl Date: Fri, 14 Oct 2016 19:20:11 +0530 Subject: [PATCH 3/3] Added POLICY_REVOKE operation upon deletion of the last policy --- .../core/enforcement/PolicyEnforcementDelegatorImpl.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java index 304482f136..2fa70bb3af 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/enforcement/PolicyEnforcementDelegatorImpl.java @@ -68,12 +68,14 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato identifier.setType(device.getType()); Policy policy = this.getEffectivePolicy(identifier); - + List deviceIdentifiers = new ArrayList<>(); + deviceIdentifiers.add(identifier); if (policy != null) { - List deviceIdentifiers = new ArrayList<>(); - deviceIdentifiers.add(identifier); this.addPolicyRevokeOperation(deviceIdentifiers); this.addPolicyOperation(deviceIdentifiers, policy); + } else { + //This means all the applicable policies have been removed from device. Hence calling a policy revoke. + this.addPolicyRevokeOperation(deviceIdentifiers); } } }