diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java index d05dd69bb7a..338170cfba5 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java @@ -86,28 +86,31 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { Policy policy = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(). getEffectivePolicy(deviceIdentifier); - List effectiveFeatures =policy.getProfile().getProfileFeaturesList(); + if (policy != null) { - PolicyOperation policyOperation = new PolicyOperation(); + List effectiveFeatures = policy.getProfile().getProfileFeaturesList(); - List profileOperationList = new ArrayList(); - for (ProfileFeature feature : effectiveFeatures) { - ProfileOperation operation = new ProfileOperation(); + PolicyOperation policyOperation = new PolicyOperation(); - operation.setCode(feature.getFeatureCode()); - operation.setPayLoad(feature.getContent()); - profileOperationList.add(operation); - } - policyOperation.setProfileOperations(profileOperationList); - policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); - - List deviceIdentifiers = new ArrayList(); - deviceIdentifiers.add(deviceIdentifier); + List profileOperationList = new ArrayList(); + for (ProfileFeature feature : effectiveFeatures) { + ProfileOperation operation = new ProfileOperation(); - PolicyManagementDataHolder.getInstance().getDeviceManagementService(). - addOperation(policyOperation, deviceIdentifiers); + operation.setCode(feature.getFeatureCode()); + operation.setPayLoad(feature.getContent()); + profileOperationList.add(operation); + } + policyOperation.setProfileOperations(profileOperationList); + policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); + List deviceIdentifiers = new ArrayList(); + deviceIdentifiers.add(deviceIdentifier); + PolicyManagementDataHolder.getInstance().getDeviceManagementService(). + addOperation(policyOperation, deviceIdentifiers); + } else { + return null; + } return policy; } catch (PolicyEvaluationException e) { @@ -131,24 +134,28 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { List effectiveFeatures = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(). getEffectiveFeatures(deviceIdentifier); - PolicyOperation policyOperation = new PolicyOperation(); + if (!effectiveFeatures.isEmpty()) { + PolicyOperation policyOperation = new PolicyOperation(); - List profileOperationList = new ArrayList(); - for (ProfileFeature feature : effectiveFeatures) { - ProfileOperation operation = new ProfileOperation(); + List profileOperationList = new ArrayList(); + for (ProfileFeature feature : effectiveFeatures) { + ProfileOperation operation = new ProfileOperation(); - operation.setCode(feature.getFeatureCode()); - operation.setPayLoad(feature.getContent()); - profileOperationList.add(operation); - } - policyOperation.setProfileOperations(profileOperationList); - policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); + operation.setCode(feature.getFeatureCode()); + operation.setPayLoad(feature.getContent()); + profileOperationList.add(operation); + } + policyOperation.setProfileOperations(profileOperationList); + policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE); - List deviceIdentifiers = new ArrayList(); - deviceIdentifiers.add(deviceIdentifier); + List deviceIdentifiers = new ArrayList(); + deviceIdentifiers.add(deviceIdentifier); - PolicyManagementDataHolder.getInstance().getDeviceManagementService(). - addOperation(policyOperation, deviceIdentifiers); + PolicyManagementDataHolder.getInstance().getDeviceManagementService(). + addOperation(policyOperation, deviceIdentifiers); + } else { + return null; + } return effectiveFeatures; } catch (PolicyEvaluationException e) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java index abcaafd3f8e..b9552e542ef 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java @@ -39,6 +39,9 @@ public class PolicyFilterImpl implements PolicyFilter { for (Policy policy : policies) { List tempRoles = policy.getRoles(); + if (tempRoles == null) { + continue; + } if (PolicyManagementConstants.ANY.equalsIgnoreCase(tempRoles.get(0))) { temp.add(policy); continue; diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java index 57d8cdffece..188a742f3d1 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java @@ -55,8 +55,11 @@ public class SimpleEvaluationImpl implements SimpleEvaluation { policyList = policyInformationPoint.getRelatedPolicies(pipDevice); sortPolicies(); - policy = policyList.get(0); - + if(!policyList.isEmpty()) { + policy = policyList.get(0); + } else { + return null; + } //TODO : UNCOMMENT THE FOLLOWING CASE // policyAdministratorPoint = policyManagerService.getPAP(); // policyAdministratorPoint.setPolicyUsed(deviceIdentifier, policy);