EMM-1342:Added policy revoke operation

4.x.x
harshanl 8 years ago
parent 39bc2e6747
commit 6e1fdabaad

@ -17,6 +17,7 @@
*/ */
package org.wso2.carbon.device.mgt.core; 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; import org.wso2.carbon.device.mgt.core.operation.mgt.PolicyOperation;
public final class DeviceManagementConstants { public final class DeviceManagementConstants {
@ -57,6 +58,7 @@ public final class DeviceManagementConstants {
public static final String MONITOR_OPERATION_CODE = "MONITOR"; public static final String MONITOR_OPERATION_CODE = "MONITOR";
public static final String POLICY_OPERATION_CODE = PolicyOperation.POLICY_OPERATION_CODE; 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 { public static final class EmailAttributes {

@ -881,6 +881,9 @@ public class OperationManagerImpl implements OperationManager {
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE: case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE:
status = true; status = true;
break; break;
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_REVOKE_OPERATION_CODE:
status = true;
break;
default: default:
status = false; status = false;
} }

@ -70,14 +70,10 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
Policy policy = this.getEffectivePolicy(identifier); Policy policy = this.getEffectivePolicy(identifier);
if (policy != null) { if (policy != null) {
List<DeviceIdentifier> 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<DeviceIdentifier> deviceIdentifiers = new ArrayList<>(); List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
deviceIdentifiers.add(identifier); deviceIdentifiers.add(identifier);
this.addPolicyRevokeOperation(deviceIdentifiers); this.addPolicyRevokeOperation(deviceIdentifiers);
this.addPolicyOperation(deviceIdentifiers, policy);
} }
} }
} }

@ -107,7 +107,8 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
@Override @Override
public boolean deletePolicy(Policy policy) throws PolicyManagementException { public boolean deletePolicy(Policy policy) throws PolicyManagementException {
boolean bool = policyManager.deletePolicy(policy); boolean bool = policyManager.deletePolicy(policy);
PolicyCacheManagerImpl.getInstance().rePopulateCache(); PolicyCacheManager policyCacheManager = PolicyCacheManagerImpl.getInstance();
policyCacheManager.rePopulateCache();
return bool; return bool;
} }
@ -116,11 +117,6 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint {
boolean bool =policyManager.deletePolicy(policyId); boolean bool =policyManager.deletePolicy(policyId);
PolicyCacheManager policyCacheManager = PolicyCacheManagerImpl.getInstance(); PolicyCacheManager policyCacheManager = PolicyCacheManagerImpl.getInstance();
policyCacheManager.rePopulateCache(); policyCacheManager.rePopulateCache();
List<Policy> 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; return bool;
} }

Loading…
Cancel
Save