From 35f3fcc8f978e8733fd168b4dbe35a50b5299a5b Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 8 Nov 2016 22:14:13 +0530 Subject: [PATCH] Changed policy evaluation point --- .../config/policy/PolicyConfiguration.java | 2 +- ...ergedPolicyEvaluationServiceComponent.java | 6 ++---- .../PolicyEvaluationServiceComponent.java | 5 +++-- .../mgt/core/PolicyManagerServiceImpl.java | 1 + .../internal/PolicyManagementDataHolder.java | 19 ++++++++++++++++--- .../PolicyManagementServiceComponent.java | 8 ++++---- .../mgt/core/PolicyEvaluationTestCase.java | 5 ++--- .../services/SimplePolicyEvaluationTest.java | 2 +- .../repository/conf/cdm-config.xml | 4 ++-- .../src/main/resources/conf/cdm-config.xml | 4 ++-- 10 files changed, 34 insertions(+), 22 deletions(-) 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 56a5fe4cf2..a9522c9c2e 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 6ea320442c..906e3d0a4d 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 1ede6cb522..b331cbcef2 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 1cd88a72d0..24659bb421 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 584bd2ec08..f089d81185 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 0c456fce28..427109e1d0 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 af0c3d604c..821526f2a5 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 62741ba503..3a1c674413 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 559cc3edd5..5dbad500c4 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 9e326a4f03..d115d0b74f 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