diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java index 56a5fe4cf2c..a9522c9c2e0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java @@ -33,7 +33,7 @@ public class PolicyConfiguration { private int minRetriesToMarkUnreachable; private int minRetriesToMarkInactive; private List platforms; - private String policyEvaluationPointName; + private String policyEvaluationPointName; @XmlElement(name = "MonitoringClass", required = true) public String getMonitoringClass() { diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java index 6ea320442c1..906e3d0a4dd 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java @@ -21,6 +21,7 @@ package org.wso2.carbon.policy.decision.point.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.user.core.service.RealmService; @@ -51,11 +52,8 @@ public class MergedPolicyEvaluationServiceComponent { } try { - //TODO: fetch PEP class from config - - componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(), - new MergedPolicyEvaluationServiceComponent(), null); + new MergedEvaluationPoint(), null); } catch (Throwable t) { log.error("Error occurred while initializing the policy evaluation bundle"); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java index 1ede6cb522d..b331cbcef22 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java @@ -22,6 +22,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; import org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint; +import org.wso2.carbon.policy.decision.point.simple.PolicyEvaluationServiceImpl; +import org.wso2.carbon.policy.decision.point.simple.SimpleEvaluationImpl; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.user.core.service.RealmService; @@ -52,9 +54,8 @@ public class PolicyEvaluationServiceComponent { } try { - //TODO: fetch PEP class from config componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(), - new MergedEvaluationPoint(), null); + new PolicyEvaluationServiceImpl(), null); } catch (Throwable t) { log.error("Error occurred while initializing the simple policy evaluation bundle"); } 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 1cd88a72d04..24659bb4214 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 @@ -173,6 +173,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { @Override public PolicyEvaluationPoint getPEP() throws PolicyManagementException { + PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java index 584bd2ec08c..f089d811854 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.policy.mgt.core.internal; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.ntask.core.service.TaskService; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; @@ -36,6 +38,7 @@ public class PolicyManagementDataHolder { private RealmService realmService; private TenantManager tenantManager; private PolicyEvaluationPoint policyEvaluationPoint; + private Map policyEvaluationPoints = new HashMap<>(); private PolicyInformationPoint policyInformationPoint; private DeviceManagementProviderService deviceManagementService; private MonitoringManager monitoringManager; @@ -88,13 +91,23 @@ public class PolicyManagementDataHolder { } public PolicyEvaluationPoint getPolicyEvaluationPoint() { - return policyEvaluationPoint; + PolicyConfiguration policyConfiguration = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig().getPolicyConfiguration(); + String policyEvaluationPointName = policyConfiguration.getPolicyEvaluationPointName(); + return policyEvaluationPoints.get(policyEvaluationPointName); } - public void setPolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) { - this.policyEvaluationPoint = policyEvaluationPoint; + public void putPolicyEvaluationPoint(String name, PolicyEvaluationPoint policyEvaluationPoint) { + policyEvaluationPoints.put(name,policyEvaluationPoint); +// this.policyEvaluationPoint = policyEvaluationPoint; } + public void removePolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) { + policyEvaluationPoints.put(policyEvaluationPoint.getName(), this.policyEvaluationPoint); +// this.policyEvaluationPoint = policyEvaluationPoint; + } + + public PolicyInformationPoint getPolicyInformationPoint() { return policyInformationPoint; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java index 0c456fce288..427109e1d03 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java @@ -46,9 +46,9 @@ import org.wso2.carbon.user.core.service.RealmService; * policy="dynamic" * bind="setRealmService" * unbind="unsetRealmService" - * @scr.reference name="org.wso2.carbon.devicemgt.simple.policy.evaluation.manager" + * @scr.reference name="org.wso2.carbon.devicemgt.policy.evaluation.manager" * interface="org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint" - * cardinality="1..1" + * cardinality="1..n" * policy="dynamic" * bind="setPEPService" * unbind="unsetPEPService" @@ -159,14 +159,14 @@ public class PolicyManagementServiceComponent { if (log.isDebugEnabled()) { log.debug("Setting Policy Information Service"); } - PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(pepService); + PolicyManagementDataHolder.getInstance().putPolicyEvaluationPoint(pepService.getName(), pepService); } protected void unsetPEPService(PolicyEvaluationPoint pepService) { if (log.isDebugEnabled()) { log.debug("Removing Policy Information Service"); } - PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(null); + PolicyManagementDataHolder.getInstance().removePolicyEvaluationPoint(null); } protected void setDeviceManagementService(DeviceManagementProviderService deviceManagerService) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java index af0c3d604cf..821526f2a52 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java @@ -51,7 +51,7 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest { @Override public void init() throws Exception { PolicyEvaluationPoint evaluationPoint = new SimplePolicyEvaluationTest(); - PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(evaluationPoint); + PolicyManagementDataHolder.getInstance().putPolicyEvaluationPoint(evaluationPoint.getName(), evaluationPoint); } @Test @@ -93,7 +93,7 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest { } @Test(dependsOnMethods = ("activatePolicies")) - public void getEffectivePolicy() throws DeviceManagementException, PolicyEvaluationException { + public void getEffectivePolicy(DeviceIdentifier identifier) throws DeviceManagementException, PolicyEvaluationException { log.debug("Getting effective policy for device started .........."); @@ -103,7 +103,6 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest { PolicyEvaluationPoint evaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); for (Device device : devices) { - DeviceIdentifier identifier = new DeviceIdentifier(); identifier.setType(device.getType()); identifier.setId(device.getDeviceIdentifier()); Policy policy = evaluationPoint.getEffectivePolicy(identifier); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java index 62741ba5035..3a1c674413b 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java @@ -79,7 +79,7 @@ SimplePolicyEvaluationTest implements PolicyEvaluationPoint { @Override public String getName() { - return "MergedPolicyEvaluationServiceComponent"; + return "SimplePolicyEvaluationServiceComponent"; } public void sortPolicies(List policyList) throws PolicyEvaluationException { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml index 559cc3edd5a..5dbad500c44 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml @@ -42,8 +42,8 @@ 5 8 20 - - MergedPolicyEvaluationServiceComponent + SimplePolicyEvaluationServiceComponent + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index 9e326a4f039..d115d0b74fb 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -43,8 +43,8 @@ 5 8 20 - - MergedPolicyEvaluationServiceComponent + SimplePolicyEvaluationServiceComponent + android ios