From eb1575126f4c5ef3b2ef091e591951eb267be3d4 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Fri, 25 Nov 2016 11:14:53 +0530 Subject: [PATCH] Minor refactoring on policy merging --- .../impl/PolicyManagementServiceImpl.java | 2 +- .../config/policy/PolicyConfiguration.java | 8 +- .../public/js/view.js | 79 +++++++---------- ...ergedPolicyEvaluationServiceComponent.java | 6 +- .../point/merged/MergedEvaluationPoint.java | 83 ++++++------------ .../simple/PolicyEvaluationServiceImpl.java | 3 +- .../mgt/common/PolicyEvaluationPoint.java | 9 +- .../mgt/core/PolicyManagerServiceImpl.java | 1 + .../PolicyEnforcementDelegatorImpl.java | 8 +- .../internal/PolicyManagementDataHolder.java | 2 +- .../PolicyManagementServiceComponent.java | 2 +- .../mgt/core/mgt/impl/PolicyManagerImpl.java | 12 +-- .../services/SimplePolicyEvaluationTest.java | 2 +- .../repository/conf/cdm-config.xml | 4 +- ...hanges or stash them before you can merge. | 15 ++++ .../main/resources/conf/.cdm-config.xml.swp | Bin 0 -> 16384 bytes .../src/main/resources/conf/cdm-config.xml | 4 +- 17 files changed, 112 insertions(+), 128 deletions(-) create mode 100644 e, commit your changes or stash them before you can merge. create mode 100644 features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/.cdm-config.xml.swp diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index be9d318e3ec..73ed8523a26 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -383,7 +383,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceIdentifier.setId(deviceId); deviceIdentifier.setType(deviceType); - policy = policyManagementService.getEffectivePolicy(deviceIdentifier); + policy = policyManagementService.getAppliedPolicyToDevice(deviceIdentifier); if (policy == null) { return Response.status(Response.Status.NOT_FOUND).entity( new ErrorResponse.ErrorResponseBuilder().setMessage( 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 a9522c9c2e0..1f52150f3f7 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 policyEvaluationPoint; @XmlElement(name = "MonitoringClass", required = true) public String getMonitoringClass() { @@ -99,13 +99,13 @@ public class PolicyConfiguration { this.platforms = platforms; } - @XmlElement(name = "PolicyEvaluationPointName", required = true) + @XmlElement(name = "PolicyEvaluationPoint", required = true) public String getPolicyEvaluationPointName() { - return policyEvaluationPointName; + return policyEvaluationPoint; } public void setPolicyEvaluationPointName(String policyEvaluationPointName) { - this.policyEvaluationPointName = policyEvaluationPointName; + this.policyEvaluationPoint = policyEvaluationPointName; } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/js/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/js/view.js index 067565db8e5..d990e1ef1a1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/js/view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/js/view.js @@ -23,7 +23,7 @@ var stepBackFrom = {}; var policy = {}; var configuredOperations = []; -var baseApiUrl = "/api/device-mgt/v1.0"; +var base_api_url = "/api/device-mgt/v1.0"; // Constants to define platform types available var platformTypeConstants = { @@ -119,7 +119,6 @@ skipStep["policy-platform"] = function (policyPayloadObj) { policyDescriptionInput.val(policyPayloadObj["description"]); // updating next-page wizard title with selected platform $("#policy-heading").text(policy["platform"].toUpperCase() + " POLICY - " + policy["name"].toUpperCase()); - // $("#policy-heading").text("Android" + " POLICY - " + "Merged Policy"); $("#policy-platform").text(policy["platform"].toUpperCase()); $("#policy-assignment").text(policyPayloadObj.ownershipType); $("#policy-action").text(policyPayloadObj.compliance.toUpperCase()); @@ -149,9 +148,9 @@ skipStep["policy-platform"] = function (policyPayloadObj) { // $("#roles-row").addClass("hidden"); // } - var deviceType = "android"; - var hiddenOperationsByDeviceType = $("#hidden-operations-" + "android"); - var hiddenOperationsByDeviceTypeCacheKey = "android" + "HiddenOperations"; + var deviceType = policy["platform"]; + var hiddenOperationsByDeviceType = $("#hidden-operations-" + deviceType); + var hiddenOperationsByDeviceTypeCacheKey = deviceType + "HiddenOperations"; var hiddenOperationsByDeviceTypeSrc = hiddenOperationsByDeviceType.attr("src"); setTimeout( @@ -162,7 +161,7 @@ skipStep["policy-platform"] = function (policyPayloadObj) { $(".wr-advance-operations").html(content); // populating values and getting the list of configured features var configuredOperations = operationModule. - populateProfile(policy["platform"], policyPayloadObj["profile"]["profileFeaturesList"]); + populateProfile(policy["platform"], policyPayloadObj["profile"]["profileFeaturesList"]); // updating grouped input visibility according to the populated values $(".wr-advance-operations li.grouped-input").each(function () { updateGroupedInputVisibility(this); @@ -171,9 +170,9 @@ skipStep["policy-platform"] = function (policyPayloadObj) { for (var i = 0; i < configuredOperations.length; ++i) { var configuredOperation = configuredOperations[i]; $(".operation-data").filterByData("operation-code", configuredOperation). - find(".panel-title .wr-input-control.switch input[type=checkbox]").each(function () { - $(this).click(); - }); + find(".panel-title .wr-input-control.switch input[type=checkbox]").each(function () { + $(this).click(); + }); } }); }, @@ -555,7 +554,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "One or more permitted App ID entries in " + - "Autonomous Single App Mode are empty.", + "Autonomous Single App Mode are empty.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -563,7 +562,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "Duplicate values exist with permitted App ID entries in " + - "Autonomous Single App Mode.", + "Autonomous Single App Mode.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -636,7 +635,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "Wi-Fi Proxy Port is not within the range " + - "of valid port numbers.", + "of valid port numbers.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -686,7 +685,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "One or more Payload Certificate " + - "Anchor UUIDs are empty.", + "Anchor UUIDs are empty.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -694,7 +693,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "Duplicate values exist " + - "with Payload Certificate Anchor UUIDs.", + "with Payload Certificate Anchor UUIDs.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -746,7 +745,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "Duplicate values exist " + - "with TLS Trusted Server Names.", + "with TLS Trusted Server Names.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -807,7 +806,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "One or more Roaming Consortium OIs " + - "are out of allowed length.", + "are out of allowed length.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -816,7 +815,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "One or more Roaming Consortium OIs " + - "contain non-hexadecimal characters.", + "contain non-hexadecimal characters.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -955,7 +954,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "One or more MCC/MNC pairs " + - "do not fulfill the accepted length of 6 digits.", + "do not fulfill the accepted length of 6 digits.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -1031,7 +1030,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "Incoming Mail Server Port is not within the range " + - "of valid port numbers.", + "of valid port numbers.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -1070,7 +1069,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "Outgoing Mail Server Port is not within the range " + - "of valid port numbers.", + "of valid port numbers.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -1150,7 +1149,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "One or more Device Names of " + - "AirPlay Credentials are empty.", + "AirPlay Credentials are empty.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -1159,7 +1158,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "Duplicate values exist with " + - "Device Names of AirPlay Credentials.", + "Device Names of AirPlay Credentials.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -1182,7 +1181,7 @@ validateStep["policy-profile"] = function () { // if child input field is empty emptyChildInputCount++; } else if (!inputIsValidAgainstRegExp( - /([a-z|A-Z|0-9][a-z|A-Z|0-9][:]){5}([a-z|A-Z|0-9][a-z|A-Z|0-9])$/, childInput)) { + /([a-z|A-Z|0-9][a-z|A-Z|0-9][:]){5}([a-z|A-Z|0-9][a-z|A-Z|0-9])$/, childInput)) { // if child input field is invalid against RegEx invalidAgainstRegExCount++ } @@ -1217,7 +1216,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "One or more AirPlay Destination fields " + - "do not fulfill expected format.", + "do not fulfill expected format.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -1319,7 +1318,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "Duplicate values exist with " + - "Search Setting Search Base and Scope pairs.", + "Search Setting Search Base and Scope pairs.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -1376,7 +1375,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "Account Port is not within the range " + - "of valid port numbers.", + "of valid port numbers.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -1489,7 +1488,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "Duplicate values exist with " + - "APN fields of Configurations.", + "APN fields of Configurations.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -1577,7 +1576,7 @@ validateStep["policy-profile"] = function () { validationStatus = { "error": true, "subErrorMsg": "Duplicate values exist with " + - "APN fields of APN Configurations.", + "APN fields of APN Configurations.", "erroneousFeature": operation }; continueToCheckNextInputs = false; @@ -1815,12 +1814,7 @@ var updatePolicy = function (policy, state) { payload["users"] = []; payload["roles"] = []; } - //var serviceURL = baseApiUrl + "/policies/effective-policy/" + policy["platform"] + "/" + getParameterByName("id"); - - // role management - //set service url - //api/device-mgt/v1.0/ policy?........ - var serviceURL = baseApiUrl + "/policy/effective-policy/" + policy["platform"] + "/" + getParameterByName("id"); + var serviceURL = base_api_url + "/policy/effective-policy/" + policy["platform"] + "/" + getParameterByName("id"); invokerUtil.put( serviceURL, payload, @@ -1829,7 +1823,7 @@ var updatePolicy = function (policy, state) { if (state == "save") { var policyList = []; policyList.push(getParameterByName("id")); - serviceURL = baseApiUrl + "/policies/deactivate-policy"; + serviceURL = base_api_url + "/policies/deactivate-policy"; invokerUtil.post( serviceURL, policyList, @@ -1846,7 +1840,7 @@ var updatePolicy = function (policy, state) { } else if (state == "publish") { var policyList = []; policyList.push(getParameterByName("id")); - serviceURL = baseApiUrl + "/policies/activate-policy"; + serviceURL = base_api_url + "/policies/activate-policy"; invokerUtil.post( serviceURL, policyList, @@ -1960,14 +1954,12 @@ var slideDownPaneAgainstValueSet = function (selectElement, paneID, valueSet) { var slideDownPaneAgainstValueSetForRadioButtons = function (selectElement, paneID, valueSet) { var selectedValueOnChange = selectElement.value; - - var i, slideDownVotes = 0; - for (i = 0; i < valueSet.length; i++) { + var slideDownVotes = 0; + for (var i = 0; i < valueSet.length; i++) { if (selectedValueOnChange == valueSet[i]) { slideDownVotes++; } } - var paneSelector = "#" + paneID; if(slideDownVotes > 0) { $(paneSelector).removeClass("hidden"); @@ -2057,10 +2049,7 @@ $(document).ready(function () { var policyPayloadObj; invokerUtil.get( - // baseApiUrl + "/policies/" + getParameterByName("id"), - - - baseApiUrl + "/policies/effective-policy/" + getParameterByName("type") + "/" + getParameterByName("id"), + base_api_url + "/policies/effective-policy/" + getParameterByName("type") + "/" + getParameterByName("id"), // on success function (data, textStatus, jqXHR) { if (jqXHR.status == 200 && data) { @@ -2231,7 +2220,7 @@ $(document).ready(function () { $(advanceOperations).on("click", "[data-click-event=add-form]", function () { var addFormContainer = $("[data-add-form-container=" + $(this).attr("href") + "]"); var clonedForm = $("[data-add-form=" + $(this).attr("href") + "]").clone(). - find("[data-add-form-element=clone]").attr("data-add-form-clone", $(this).attr("href")); + find("[data-add-form-element=clone]").attr("data-add-form-clone", $(this).attr("href")); // adding class .child-input to capture text-input-array-values $("input, select", clonedForm).addClass("child-input"); 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 906e3d0a4dd..3ec27e3918c 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 @@ -104,9 +104,9 @@ public class MergedPolicyEvaluationServiceComponent { PolicyDecisionPointDataHolder.getInstance().setPolicyManagerService(null); } - protected String getName() { - return MergedPolicyEvaluationServiceComponent.class.getName(); - } +// protected String getName() { +// return MergedPolicyEvaluationServiceComponent.class.getName(); +// } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java index d88ca9fb14d..678705d9ed0 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java @@ -29,74 +29,63 @@ import org.wso2.carbon.policy.decision.point.internal.PolicyDecisionPointDataHol import java.sql.Timestamp; import java.util.*; +/** + * This class helps to merge related policies and return as a effective policy. + */ public class MergedEvaluationPoint implements PolicyEvaluationPoint { private static final Log log = LogFactory.getLog(MergedEvaluationPoint.class); private PolicyManagerService policyManagerService; - private List policyList; - PIPDevice pipDevice; + private static final String effectivePolicyName = "Effective-Policy"; + private static final String policyEvaluationPoint = "Merged"; @Override - public List getEffectiveFeatures(List policyList, DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { - PolicyAdministratorPoint policyAdministratorPoint; - policyManagerService = getPolicyManagerService(); - - try { - if (policyManagerService != null) { - - if (!policyList.isEmpty()) { - Policy effectivePolicy = policyResolve(policyList); - effectivePolicy.setActive(true); - policyAdministratorPoint = policyManagerService.getPAP(); - policyAdministratorPoint.setPolicyUsed(deviceIdentifier, effectivePolicy); - return effectivePolicy.getProfile().getProfileFeaturesList(); - } - } - return null; - } catch (PolicyManagementException e) { - String msg = "Error occurred when retrieving the policy related data from policy management service."; - log.error(msg, e); - throw new PolicyEvaluationException(msg, e); - } + public List getEffectiveFeatures(List policyList, DeviceIdentifier deviceIdentifier) + throws PolicyEvaluationException { + return this.getEffectivePolicy(deviceIdentifier).getProfile().getProfileFeaturesList(); } @Override public String getName() { - return "MergedPolicyEvaluationServiceComponent"; + return policyEvaluationPoint; } @Override public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { - + PIPDevice pipDevice; + List policyList; + Policy policy; try { policyManagerService = getPolicyManagerService(); + if (policyManagerService == null) { + return null; + } PolicyInformationPoint policyInformationPoint = policyManagerService.getPIP(); pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier); policyList = policyInformationPoint.getRelatedPolicies(pipDevice); - if (policyManagerService == null || policyList.size() == 0) { + if (policyList.size() == 0) { return null; } - Policy policy = new Policy(); + // Set effective-policy information Profile profile = new Profile(); - profile.setProfileFeaturesList(getEffectiveFeatures(policyList, deviceIdentifier)); + policy = policyResolve(policyList); + profile.setProfileFeaturesList(policy.getProfile().getProfileFeaturesList()); policy.setProfile(profile); Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime()); profile.setCreatedDate(currentTimestamp); profile.setUpdatedDate(currentTimestamp); profile.setDeviceType(deviceIdentifier.getType()); profile.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); - policy.setPolicyName("Effective-Policy"); + policy.setPolicyName(effectivePolicyName); policy.setOwnershipType(pipDevice.getOwnershipType()); - policy.setRoles(null); - policy.setDevices(null); - policy.setUsers(null); policy.setActive(true); policy.setUpdated(true); policy.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); policy.setDescription("This is a system generated effective policy by merging relevant policies."); policy.setCompliance(policyList.get(0).getCompliance()); + policy.setId(-1); return policy; } catch (PolicyManagementException e) { String msg = "Error occurred when retrieving the policy related data from policy management service."; @@ -106,52 +95,30 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { } private Policy policyResolve(List policyList) throws PolicyEvaluationException, PolicyManagementException { - sortPolicies(); + Collections.sort(policyList, Collections.reverseOrder()); // Iterate through all policies Map featureMap = new HashMap<>(); - // Merge roles of policies - //Map rolesMap = new HashMap<>(); - Iterator policyIterator = policyList.iterator(); - while (policyIterator.hasNext()) { - Policy policy = policyIterator.next(); + for (Policy policy : policyList) { List profileFeaturesList = policy.getProfile().getProfileFeaturesList(); if (profileFeaturesList != null) { - Iterator featureIterator = profileFeaturesList.iterator(); - while (featureIterator.hasNext()) { - ProfileFeature feature = featureIterator.next(); + for (ProfileFeature feature : profileFeaturesList) { featureMap.put(feature.getFeatureCode(), feature); } } -// List policyRolesList = policy.getRoles(); -// -// if (policyRolesList != null) { -// Iterator roleIterator = policyRolesList.iterator(); -// while (roleIterator.hasNext()) { -// String role = roleIterator.next(); -// rolesMap.put(role,policy.getId()); -// } -// } - } // Get prioritized features list List newFeaturesList = new ArrayList<>(featureMap.values()); Profile profile = new Profile(); profile.setProfileFeaturesList(newFeaturesList); - Policy effectivePolicy = new Policy(); effectivePolicy.setProfile(profile); - //effectivePolicy.setRoles(rolesList); - return effectivePolicy; } - public void sortPolicies() throws PolicyEvaluationException { - Collections.sort(policyList, Collections.reverseOrder()); - } - private PolicyManagerService getPolicyManagerService() { return PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); } + } diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java index 24ec30dc84b..ac1f6ebf895 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java @@ -29,6 +29,7 @@ import java.util.List; public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { private SimpleEvaluationImpl evaluation; + private static final String policyEvaluationPoint = "Simple"; public PolicyEvaluationServiceImpl() { evaluation = new SimpleEvaluationImpl(); @@ -50,6 +51,6 @@ public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { @Override public String getName() { - return "SimplePolicyEvaluationServiceComponent"; + return policyEvaluationPoint; } } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java index 7b497ccb6e6..bf668f8531d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java @@ -39,10 +39,15 @@ public interface PolicyEvaluationPoint { /** * This class will return the effective feature set from the list. - * @param deviceIdentifier device information. - * @return returns the effective feature set. + * + * @param deviceIdentifier device information. + * @return returns the effective feature set. */ List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; + /** + * This method returns the name of the Policy Evaluation Point + * @return returns Policy Evaluation Point name + */ String getName(); } 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..d06c3cb0ee5 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 @@ -100,6 +100,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { if (policy == null) { return null; } + this.getPAP().setPolicyUsed(deviceIdentifier, policy); } else { throw new PolicyEvaluationException("Error occurred while getting the policy evaluation point " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType()); 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 2fa70bb3af6..fb3c8143f34 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 @@ -30,6 +30,7 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationManagerImpl; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants; import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; @@ -84,7 +85,12 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato public Policy getEffectivePolicy(DeviceIdentifier identifier) throws PolicyDelegationException { try { PolicyManagerService policyManagerService = new PolicyManagerServiceImpl(); - return policyManagerService.getPEP().getEffectivePolicy(identifier); + PolicyAdministratorPoint policyAdministratorPoint; + + Policy policy = policyManagerService.getPEP().getEffectivePolicy(identifier); + policyAdministratorPoint = policyManagerService.getPAP(); + policyAdministratorPoint.setPolicyUsed(identifier, policy); + return policy; //return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().getEffectivePolicy(identifier); } catch (PolicyEvaluationException e) { String msg = "Error occurred while retrieving the effective policy for devices."; 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 a85928b0632..27f9487ac6e 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 @@ -102,7 +102,7 @@ public class PolicyManagementDataHolder { } public void removePolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) { - policyEvaluationPoints.put(policyEvaluationPoint.getName(), this.policyEvaluationPoint); + policyEvaluationPoints.remove(policyEvaluationPoint.getName()); } 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 0d8b41a64c9..85bce853323 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 @@ -166,7 +166,7 @@ public class PolicyManagementServiceComponent { if (log.isDebugEnabled()) { log.debug("Removing Policy Information Service"); } - PolicyManagementDataHolder.getInstance().removePolicyEvaluationPoint(null); + PolicyManagementDataHolder.getInstance().removePolicyEvaluationPoint(pepService); } protected void setDeviceManagementService(DeviceManagementProviderService deviceManagerService) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index 2fbb9d84e16..78bb6088905 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -879,10 +879,10 @@ public class PolicyManagerImpl implements PolicyManager { PolicyManagementDAOFactory.beginTransaction(); Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId()); - if (policySaved != null && policySaved.getId() != 0) { -// if (policy.getId() != policySaved.getId()) { + if (policySaved != null) { + if (policySaved.getId() != 0) { policyDAO.updateEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy); -// } + } } else { policyDAO.addEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy); } @@ -912,17 +912,17 @@ public class PolicyManagerImpl implements PolicyManager { Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId()); if (policySaved != null) { - policyDAO.deleteEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId()); + policyDAO.deleteEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId()); } PolicyManagementDAOFactory.commitTransaction(); } catch (PolicyManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new PolicyManagementException("Error occurred while removing the applied policy to device (" + - deviceId + ")", e); + deviceId + ")", e); } catch (DeviceManagementException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new PolicyManagementException("Error occurred while getting the device details (" + - deviceIdentifier.getId() + ")", e); + deviceIdentifier.getId() + ")", e); } finally { PolicyManagementDAOFactory.closeConnection(); } 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 3a1c674413b..7fe3561ec28 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 "SimplePolicyEvaluationServiceComponent"; + return "SimplePolicy"; } 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..3e2078ad11b 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 + + Merged diff --git a/e, commit your changes or stash them before you can merge. b/e, commit your changes or stash them before you can merge. new file mode 100644 index 00000000000..151a40c3e7d --- /dev/null +++ b/e, commit your changes or stash them before you can merge. @@ -0,0 +1,15 @@ +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 addf38e..4e2ad6b 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 ++  ++ Merged +  + android + ios diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/.cdm-config.xml.swp b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/.cdm-config.xml.swp new file mode 100644 index 0000000000000000000000000000000000000000..a8e6a11569ace238c1868963897a7820a82ec4ac GIT binary patch literal 16384 zcmeHNO^hTr6)qOCKp-Rv;s6M68VT)+?W&pC9dYMKRs6fL&& zsk{81pY6}juWXmcE4yBoT(_@TNKaVSn>*KEdhy%B`hZwgl0}(N`Trtmz2<1j#k~Oy znxplrE43w#w4&3Iel}wwO`IN^-))D{lsZ0*$5J!{w$FXmoJ~?^kI^)XS>jakWIVCw ziCnXDbvqZ?P`48n@3Yu0N;ygFJ2T3K0}C>Xec17(*mL|~)>MD^#6FmXwXHOnhJlBb zfyb$kw`z!C5R;5zVC;G@r3)&Xz<*niZr-v2CgfnNY~;054ofCaqw8O!=PAb@q? zN#HFUO8f|T9(WY^`$gmdZvd|XF9UtxI`C!SZ;x2kkAYW!F>n*O2)zF(%lb9&8X$pP zpanbuyn_Rf-vB=WeBd_F1il3P8HXpo1bzlgfoFiP1CIcI1+Q-dKLs?$+6M@dJD?LT zXv(G7&^HpYSUsX=sTPjl# z#F7Wg3b;#ZcDI?I#WC)bjQETttyR}Km2;+kw?}8J)!E$jHa72W^*7ohuitYWoqIyr zT@ZDWj)#G#^#|ptJs50xIY)Q5yy58oji`Uup}gMh{)2K4#s!(^MKF=x0Fr7XF5EYS8A-tFFw+5LWS(sj0Wf)eyY)IlHAvvFUV0q1b=$jK zy3+Nhltk@h)t7qD7)uB+=UMy19pUB?UX?%?UU zF53=fTnsQ9=Q0jjR6V)Q$;`5EI)4Wj5`}ujRFxN*rSeeUTil7m)-+9{>-^!9{Po{j2`?>GNa-Rn*uKKt3&?0|XbYTZ66A6|li5onh@ebh#;aX@lJQ z?zs7@vpY#obpj;i{(3|*fq6vIDI;6Bqbw3;LwH1zi1})|k&uc>rWWcGiMOsmOe9!h z&v>Gz5W!oBgnY(RJueeo_C>GPxk4C+(U`D<2$z);f;GK*QE(R6gbW$0R;gF~(AK3J z?IH1o4f0%j=nb!sJKpH|{?3TpX>V`0dn0diNc!7kqu=XzYHf?B+oaw5e%@%gm(FR- zNWc>;6UJGJ{ll3K5}uq;kOIBX<#$A=nyS_hJVw#+A)yi4?5j5nn3$_x&`Hc7OC{lg z%wr6>m|RiCwFyF0z(c&7&*zvzcsns0Q^0`{MQ-9?!MWKRZZ_BKl|`XLnUNViByx;3 z4qAi#P=u$w6CBZ0R{*&$6_Hf^9KZ~3_+aX9emt6K0R;w&N0B+&1M16`K t;!CVPiLaO7^dV1fTOHctSouuBT0vQ^dV+hV?770SeBR?TC2O*+e*$B=U5 8 20 - - MergedPolicyEvaluationServiceComponent + + Merged android ios