Minor refactoring on policy merging

revert-70aa11f8
Supun94 8 years ago
parent 451b2fd1dc
commit eb1575126f

@ -383,7 +383,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(deviceType); deviceIdentifier.setType(deviceType);
policy = policyManagementService.getEffectivePolicy(deviceIdentifier); policy = policyManagementService.getAppliedPolicyToDevice(deviceIdentifier);
if (policy == null) { if (policy == null) {
return Response.status(Response.Status.NOT_FOUND).entity( return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage( new ErrorResponse.ErrorResponseBuilder().setMessage(

@ -33,7 +33,7 @@ public class PolicyConfiguration {
private int minRetriesToMarkUnreachable; private int minRetriesToMarkUnreachable;
private int minRetriesToMarkInactive; private int minRetriesToMarkInactive;
private List<String> platforms; private List<String> platforms;
private String policyEvaluationPointName; private String policyEvaluationPoint;
@XmlElement(name = "MonitoringClass", required = true) @XmlElement(name = "MonitoringClass", required = true)
public String getMonitoringClass() { public String getMonitoringClass() {
@ -99,13 +99,13 @@ public class PolicyConfiguration {
this.platforms = platforms; this.platforms = platforms;
} }
@XmlElement(name = "PolicyEvaluationPointName", required = true) @XmlElement(name = "PolicyEvaluationPoint", required = true)
public String getPolicyEvaluationPointName() { public String getPolicyEvaluationPointName() {
return policyEvaluationPointName; return policyEvaluationPoint;
} }
public void setPolicyEvaluationPointName(String policyEvaluationPointName) { public void setPolicyEvaluationPointName(String policyEvaluationPointName) {
this.policyEvaluationPointName = policyEvaluationPointName; this.policyEvaluationPoint = policyEvaluationPointName;
} }
} }

@ -23,7 +23,7 @@ var stepBackFrom = {};
var policy = {}; var policy = {};
var configuredOperations = []; var configuredOperations = [];
var baseApiUrl = "/api/device-mgt/v1.0"; var base_api_url = "/api/device-mgt/v1.0";
// Constants to define platform types available // Constants to define platform types available
var platformTypeConstants = { var platformTypeConstants = {
@ -119,7 +119,6 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
policyDescriptionInput.val(policyPayloadObj["description"]); policyDescriptionInput.val(policyPayloadObj["description"]);
// updating next-page wizard title with selected platform // updating next-page wizard title with selected platform
$("#policy-heading").text(policy["platform"].toUpperCase() + " POLICY - " + policy["name"].toUpperCase()); $("#policy-heading").text(policy["platform"].toUpperCase() + " POLICY - " + policy["name"].toUpperCase());
// $("#policy-heading").text("Android" + " POLICY - " + "Merged Policy");
$("#policy-platform").text(policy["platform"].toUpperCase()); $("#policy-platform").text(policy["platform"].toUpperCase());
$("#policy-assignment").text(policyPayloadObj.ownershipType); $("#policy-assignment").text(policyPayloadObj.ownershipType);
$("#policy-action").text(policyPayloadObj.compliance.toUpperCase()); $("#policy-action").text(policyPayloadObj.compliance.toUpperCase());
@ -149,9 +148,9 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
// $("#roles-row").addClass("hidden"); // $("#roles-row").addClass("hidden");
// } // }
var deviceType = "android"; var deviceType = policy["platform"];
var hiddenOperationsByDeviceType = $("#hidden-operations-" + "android"); var hiddenOperationsByDeviceType = $("#hidden-operations-" + deviceType);
var hiddenOperationsByDeviceTypeCacheKey = "android" + "HiddenOperations"; var hiddenOperationsByDeviceTypeCacheKey = deviceType + "HiddenOperations";
var hiddenOperationsByDeviceTypeSrc = hiddenOperationsByDeviceType.attr("src"); var hiddenOperationsByDeviceTypeSrc = hiddenOperationsByDeviceType.attr("src");
setTimeout( setTimeout(
@ -162,7 +161,7 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
$(".wr-advance-operations").html(content); $(".wr-advance-operations").html(content);
// populating values and getting the list of configured features // populating values and getting the list of configured features
var configuredOperations = operationModule. var configuredOperations = operationModule.
populateProfile(policy["platform"], policyPayloadObj["profile"]["profileFeaturesList"]); populateProfile(policy["platform"], policyPayloadObj["profile"]["profileFeaturesList"]);
// updating grouped input visibility according to the populated values // updating grouped input visibility according to the populated values
$(".wr-advance-operations li.grouped-input").each(function () { $(".wr-advance-operations li.grouped-input").each(function () {
updateGroupedInputVisibility(this); updateGroupedInputVisibility(this);
@ -171,9 +170,9 @@ skipStep["policy-platform"] = function (policyPayloadObj) {
for (var i = 0; i < configuredOperations.length; ++i) { for (var i = 0; i < configuredOperations.length; ++i) {
var configuredOperation = configuredOperations[i]; var configuredOperation = configuredOperations[i];
$(".operation-data").filterByData("operation-code", configuredOperation). $(".operation-data").filterByData("operation-code", configuredOperation).
find(".panel-title .wr-input-control.switch input[type=checkbox]").each(function () { find(".panel-title .wr-input-control.switch input[type=checkbox]").each(function () {
$(this).click(); $(this).click();
}); });
} }
}); });
}, },
@ -555,7 +554,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "One or more permitted App ID entries in " + "subErrorMsg": "One or more permitted App ID entries in " +
"Autonomous Single App Mode are empty.", "Autonomous Single App Mode are empty.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -563,7 +562,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Duplicate values exist with permitted App ID entries in " + "subErrorMsg": "Duplicate values exist with permitted App ID entries in " +
"Autonomous Single App Mode.", "Autonomous Single App Mode.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -636,7 +635,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Wi-Fi Proxy Port is not within the range " + "subErrorMsg": "Wi-Fi Proxy Port is not within the range " +
"of valid port numbers.", "of valid port numbers.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -686,7 +685,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "One or more Payload Certificate " + "subErrorMsg": "One or more Payload Certificate " +
"Anchor UUIDs are empty.", "Anchor UUIDs are empty.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -694,7 +693,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Duplicate values exist " + "subErrorMsg": "Duplicate values exist " +
"with Payload Certificate Anchor UUIDs.", "with Payload Certificate Anchor UUIDs.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -746,7 +745,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Duplicate values exist " + "subErrorMsg": "Duplicate values exist " +
"with TLS Trusted Server Names.", "with TLS Trusted Server Names.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -807,7 +806,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "One or more Roaming Consortium OIs " + "subErrorMsg": "One or more Roaming Consortium OIs " +
"are out of allowed length.", "are out of allowed length.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -816,7 +815,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "One or more Roaming Consortium OIs " + "subErrorMsg": "One or more Roaming Consortium OIs " +
"contain non-hexadecimal characters.", "contain non-hexadecimal characters.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -955,7 +954,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "One or more MCC/MNC pairs " + "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 "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -1031,7 +1030,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Incoming Mail Server Port is not within the range " + "subErrorMsg": "Incoming Mail Server Port is not within the range " +
"of valid port numbers.", "of valid port numbers.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -1070,7 +1069,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Outgoing Mail Server Port is not within the range " + "subErrorMsg": "Outgoing Mail Server Port is not within the range " +
"of valid port numbers.", "of valid port numbers.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -1150,7 +1149,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "One or more Device Names of " + "subErrorMsg": "One or more Device Names of " +
"AirPlay Credentials are empty.", "AirPlay Credentials are empty.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -1159,7 +1158,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Duplicate values exist with " + "subErrorMsg": "Duplicate values exist with " +
"Device Names of AirPlay Credentials.", "Device Names of AirPlay Credentials.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -1182,7 +1181,7 @@ validateStep["policy-profile"] = function () {
// if child input field is empty // if child input field is empty
emptyChildInputCount++; emptyChildInputCount++;
} else if (!inputIsValidAgainstRegExp( } 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 // if child input field is invalid against RegEx
invalidAgainstRegExCount++ invalidAgainstRegExCount++
} }
@ -1217,7 +1216,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "One or more AirPlay Destination fields " + "subErrorMsg": "One or more AirPlay Destination fields " +
"do not fulfill expected format.", "do not fulfill expected format.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -1319,7 +1318,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Duplicate values exist with " + "subErrorMsg": "Duplicate values exist with " +
"Search Setting Search Base and Scope pairs.", "Search Setting Search Base and Scope pairs.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -1376,7 +1375,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Account Port is not within the range " + "subErrorMsg": "Account Port is not within the range " +
"of valid port numbers.", "of valid port numbers.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -1489,7 +1488,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Duplicate values exist with " + "subErrorMsg": "Duplicate values exist with " +
"APN fields of Configurations.", "APN fields of Configurations.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -1577,7 +1576,7 @@ validateStep["policy-profile"] = function () {
validationStatus = { validationStatus = {
"error": true, "error": true,
"subErrorMsg": "Duplicate values exist with " + "subErrorMsg": "Duplicate values exist with " +
"APN fields of APN Configurations.", "APN fields of APN Configurations.",
"erroneousFeature": operation "erroneousFeature": operation
}; };
continueToCheckNextInputs = false; continueToCheckNextInputs = false;
@ -1815,12 +1814,7 @@ var updatePolicy = function (policy, state) {
payload["users"] = []; payload["users"] = [];
payload["roles"] = []; payload["roles"] = [];
} }
//var serviceURL = baseApiUrl + "/policies/effective-policy/" + policy["platform"] + "/" + getParameterByName("id"); var serviceURL = base_api_url + "/policy/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");
invokerUtil.put( invokerUtil.put(
serviceURL, serviceURL,
payload, payload,
@ -1829,7 +1823,7 @@ var updatePolicy = function (policy, state) {
if (state == "save") { if (state == "save") {
var policyList = []; var policyList = [];
policyList.push(getParameterByName("id")); policyList.push(getParameterByName("id"));
serviceURL = baseApiUrl + "/policies/deactivate-policy"; serviceURL = base_api_url + "/policies/deactivate-policy";
invokerUtil.post( invokerUtil.post(
serviceURL, serviceURL,
policyList, policyList,
@ -1846,7 +1840,7 @@ var updatePolicy = function (policy, state) {
} else if (state == "publish") { } else if (state == "publish") {
var policyList = []; var policyList = [];
policyList.push(getParameterByName("id")); policyList.push(getParameterByName("id"));
serviceURL = baseApiUrl + "/policies/activate-policy"; serviceURL = base_api_url + "/policies/activate-policy";
invokerUtil.post( invokerUtil.post(
serviceURL, serviceURL,
policyList, policyList,
@ -1960,14 +1954,12 @@ var slideDownPaneAgainstValueSet = function (selectElement, paneID, valueSet) {
var slideDownPaneAgainstValueSetForRadioButtons = function (selectElement, paneID, valueSet) { var slideDownPaneAgainstValueSetForRadioButtons = function (selectElement, paneID, valueSet) {
var selectedValueOnChange = selectElement.value; var selectedValueOnChange = selectElement.value;
var slideDownVotes = 0;
var i, slideDownVotes = 0; for (var i = 0; i < valueSet.length; i++) {
for (i = 0; i < valueSet.length; i++) {
if (selectedValueOnChange == valueSet[i]) { if (selectedValueOnChange == valueSet[i]) {
slideDownVotes++; slideDownVotes++;
} }
} }
var paneSelector = "#" + paneID; var paneSelector = "#" + paneID;
if(slideDownVotes > 0) { if(slideDownVotes > 0) {
$(paneSelector).removeClass("hidden"); $(paneSelector).removeClass("hidden");
@ -2057,10 +2049,7 @@ $(document).ready(function () {
var policyPayloadObj; var policyPayloadObj;
invokerUtil.get( invokerUtil.get(
// baseApiUrl + "/policies/" + getParameterByName("id"), base_api_url + "/policies/effective-policy/" + getParameterByName("type") + "/" + getParameterByName("id"),
baseApiUrl + "/policies/effective-policy/" + getParameterByName("type") + "/" + getParameterByName("id"),
// on success // on success
function (data, textStatus, jqXHR) { function (data, textStatus, jqXHR) {
if (jqXHR.status == 200 && data) { if (jqXHR.status == 200 && data) {
@ -2231,7 +2220,7 @@ $(document).ready(function () {
$(advanceOperations).on("click", "[data-click-event=add-form]", function () { $(advanceOperations).on("click", "[data-click-event=add-form]", function () {
var addFormContainer = $("[data-add-form-container=" + $(this).attr("href") + "]"); var addFormContainer = $("[data-add-form-container=" + $(this).attr("href") + "]");
var clonedForm = $("[data-add-form=" + $(this).attr("href") + "]").clone(). 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 // adding class .child-input to capture text-input-array-values
$("input, select", clonedForm).addClass("child-input"); $("input, select", clonedForm).addClass("child-input");

@ -104,9 +104,9 @@ public class MergedPolicyEvaluationServiceComponent {
PolicyDecisionPointDataHolder.getInstance().setPolicyManagerService(null); PolicyDecisionPointDataHolder.getInstance().setPolicyManagerService(null);
} }
protected String getName() { // protected String getName() {
return MergedPolicyEvaluationServiceComponent.class.getName(); // return MergedPolicyEvaluationServiceComponent.class.getName();
} // }
} }

@ -29,74 +29,63 @@ import org.wso2.carbon.policy.decision.point.internal.PolicyDecisionPointDataHol
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.*; import java.util.*;
/**
* This class helps to merge related policies and return as a effective policy.
*/
public class MergedEvaluationPoint implements PolicyEvaluationPoint { public class MergedEvaluationPoint implements PolicyEvaluationPoint {
private static final Log log = LogFactory.getLog(MergedEvaluationPoint.class); private static final Log log = LogFactory.getLog(MergedEvaluationPoint.class);
private PolicyManagerService policyManagerService; private PolicyManagerService policyManagerService;
private List<Policy> policyList; private static final String effectivePolicyName = "Effective-Policy";
PIPDevice pipDevice; private static final String policyEvaluationPoint = "Merged";
@Override @Override
public List<ProfileFeature> getEffectiveFeatures(List<Policy> policyList, DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { public List<ProfileFeature> getEffectiveFeatures(List<Policy> policyList, DeviceIdentifier deviceIdentifier)
PolicyAdministratorPoint policyAdministratorPoint; throws PolicyEvaluationException {
policyManagerService = getPolicyManagerService(); return this.getEffectivePolicy(deviceIdentifier).getProfile().getProfileFeaturesList();
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);
}
} }
@Override @Override
public String getName() { public String getName() {
return "MergedPolicyEvaluationServiceComponent"; return policyEvaluationPoint;
} }
@Override @Override
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
PIPDevice pipDevice;
List<Policy> policyList;
Policy policy;
try { try {
policyManagerService = getPolicyManagerService(); policyManagerService = getPolicyManagerService();
if (policyManagerService == null) {
return null;
}
PolicyInformationPoint policyInformationPoint = policyManagerService.getPIP(); PolicyInformationPoint policyInformationPoint = policyManagerService.getPIP();
pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier); pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier);
policyList = policyInformationPoint.getRelatedPolicies(pipDevice); policyList = policyInformationPoint.getRelatedPolicies(pipDevice);
if (policyManagerService == null || policyList.size() == 0) { if (policyList.size() == 0) {
return null; return null;
} }
Policy policy = new Policy(); // Set effective-policy information
Profile profile = new Profile(); Profile profile = new Profile();
profile.setProfileFeaturesList(getEffectiveFeatures(policyList, deviceIdentifier)); policy = policyResolve(policyList);
profile.setProfileFeaturesList(policy.getProfile().getProfileFeaturesList());
policy.setProfile(profile); policy.setProfile(profile);
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime()); Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
profile.setCreatedDate(currentTimestamp); profile.setCreatedDate(currentTimestamp);
profile.setUpdatedDate(currentTimestamp); profile.setUpdatedDate(currentTimestamp);
profile.setDeviceType(deviceIdentifier.getType()); profile.setDeviceType(deviceIdentifier.getType());
profile.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); profile.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
policy.setPolicyName("Effective-Policy"); policy.setPolicyName(effectivePolicyName);
policy.setOwnershipType(pipDevice.getOwnershipType()); policy.setOwnershipType(pipDevice.getOwnershipType());
policy.setRoles(null);
policy.setDevices(null);
policy.setUsers(null);
policy.setActive(true); policy.setActive(true);
policy.setUpdated(true); policy.setUpdated(true);
policy.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); policy.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
policy.setDescription("This is a system generated effective policy by merging relevant policies."); policy.setDescription("This is a system generated effective policy by merging relevant policies.");
policy.setCompliance(policyList.get(0).getCompliance()); policy.setCompliance(policyList.get(0).getCompliance());
policy.setId(-1);
return policy; return policy;
} catch (PolicyManagementException e) { } catch (PolicyManagementException e) {
String msg = "Error occurred when retrieving the policy related data from policy management service."; 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<Policy> policyList) throws PolicyEvaluationException, PolicyManagementException { private Policy policyResolve(List<Policy> policyList) throws PolicyEvaluationException, PolicyManagementException {
sortPolicies(); Collections.sort(policyList, Collections.reverseOrder());
// Iterate through all policies // Iterate through all policies
Map<String, ProfileFeature> featureMap = new HashMap<>(); Map<String, ProfileFeature> featureMap = new HashMap<>();
// Merge roles of policies for (Policy policy : policyList) {
//Map<String, java.lang.Integer> rolesMap = new HashMap<>();
Iterator<Policy> policyIterator = policyList.iterator();
while (policyIterator.hasNext()) {
Policy policy = policyIterator.next();
List<ProfileFeature> profileFeaturesList = policy.getProfile().getProfileFeaturesList(); List<ProfileFeature> profileFeaturesList = policy.getProfile().getProfileFeaturesList();
if (profileFeaturesList != null) { if (profileFeaturesList != null) {
Iterator<ProfileFeature> featureIterator = profileFeaturesList.iterator(); for (ProfileFeature feature : profileFeaturesList) {
while (featureIterator.hasNext()) {
ProfileFeature feature = featureIterator.next();
featureMap.put(feature.getFeatureCode(), feature); featureMap.put(feature.getFeatureCode(), feature);
} }
} }
// List<String> policyRolesList = policy.getRoles();
//
// if (policyRolesList != null) {
// Iterator<String> roleIterator = policyRolesList.iterator();
// while (roleIterator.hasNext()) {
// String role = roleIterator.next();
// rolesMap.put(role,policy.getId());
// }
// }
} }
// Get prioritized features list // Get prioritized features list
List<ProfileFeature> newFeaturesList = new ArrayList<>(featureMap.values()); List<ProfileFeature> newFeaturesList = new ArrayList<>(featureMap.values());
Profile profile = new Profile(); Profile profile = new Profile();
profile.setProfileFeaturesList(newFeaturesList); profile.setProfileFeaturesList(newFeaturesList);
Policy effectivePolicy = new Policy(); Policy effectivePolicy = new Policy();
effectivePolicy.setProfile(profile); effectivePolicy.setProfile(profile);
//effectivePolicy.setRoles(rolesList);
return effectivePolicy; return effectivePolicy;
} }
public void sortPolicies() throws PolicyEvaluationException {
Collections.sort(policyList, Collections.reverseOrder());
}
private PolicyManagerService getPolicyManagerService() { private PolicyManagerService getPolicyManagerService() {
return PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); return PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
} }
} }

@ -29,6 +29,7 @@ import java.util.List;
public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint {
private SimpleEvaluationImpl evaluation; private SimpleEvaluationImpl evaluation;
private static final String policyEvaluationPoint = "Simple";
public PolicyEvaluationServiceImpl() { public PolicyEvaluationServiceImpl() {
evaluation = new SimpleEvaluationImpl(); evaluation = new SimpleEvaluationImpl();
@ -50,6 +51,6 @@ public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint {
@Override @Override
public String getName() { public String getName() {
return "SimplePolicyEvaluationServiceComponent"; return policyEvaluationPoint;
} }
} }

@ -39,10 +39,15 @@ public interface PolicyEvaluationPoint {
/** /**
* This class will return the effective feature set from the list. * 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<ProfileFeature> getEffectiveFeatures(List<Policy> policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; List<ProfileFeature> getEffectiveFeatures(List<Policy> policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException;
/**
* This method returns the name of the Policy Evaluation Point
* @return returns Policy Evaluation Point name
*/
String getName(); String getName();
} }

@ -100,6 +100,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService {
if (policy == null) { if (policy == null) {
return null; return null;
} }
this.getPAP().setPolicyUsed(deviceIdentifier, policy);
} else { } else {
throw new PolicyEvaluationException("Error occurred while getting the policy evaluation point " + throw new PolicyEvaluationException("Error occurred while getting the policy evaluation point " +
deviceIdentifier.getId() + " - " + deviceIdentifier.getType()); deviceIdentifier.getId() + " - " + deviceIdentifier.getType());

@ -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.OperationManagerImpl;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants; 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.Policy;
import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint;
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
@ -84,7 +85,12 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato
public Policy getEffectivePolicy(DeviceIdentifier identifier) throws PolicyDelegationException { public Policy getEffectivePolicy(DeviceIdentifier identifier) throws PolicyDelegationException {
try { try {
PolicyManagerService policyManagerService = new PolicyManagerServiceImpl(); 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); //return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().getEffectivePolicy(identifier);
} catch (PolicyEvaluationException e) { } catch (PolicyEvaluationException e) {
String msg = "Error occurred while retrieving the effective policy for devices."; String msg = "Error occurred while retrieving the effective policy for devices.";

@ -102,7 +102,7 @@ public class PolicyManagementDataHolder {
} }
public void removePolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) { public void removePolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) {
policyEvaluationPoints.put(policyEvaluationPoint.getName(), this.policyEvaluationPoint); policyEvaluationPoints.remove(policyEvaluationPoint.getName());
} }

@ -166,7 +166,7 @@ public class PolicyManagementServiceComponent {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Removing Policy Information Service"); log.debug("Removing Policy Information Service");
} }
PolicyManagementDataHolder.getInstance().removePolicyEvaluationPoint(null); PolicyManagementDataHolder.getInstance().removePolicyEvaluationPoint(pepService);
} }
protected void setDeviceManagementService(DeviceManagementProviderService deviceManagerService) { protected void setDeviceManagementService(DeviceManagementProviderService deviceManagerService) {

@ -879,10 +879,10 @@ public class PolicyManagerImpl implements PolicyManager {
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId()); Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId());
if (policySaved != null && policySaved.getId() != 0) { if (policySaved != null) {
// if (policy.getId() != policySaved.getId()) { if (policySaved.getId() != 0) {
policyDAO.updateEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy); policyDAO.updateEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy);
// } }
} else { } else {
policyDAO.addEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy); policyDAO.addEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy);
} }
@ -912,17 +912,17 @@ public class PolicyManagerImpl implements PolicyManager {
Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId()); Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId());
if (policySaved != null) { if (policySaved != null) {
policyDAO.deleteEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId()); policyDAO.deleteEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId());
} }
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
PolicyManagementDAOFactory.rollbackTransaction(); PolicyManagementDAOFactory.rollbackTransaction();
throw new PolicyManagementException("Error occurred while removing the applied policy to device (" + throw new PolicyManagementException("Error occurred while removing the applied policy to device (" +
deviceId + ")", e); deviceId + ")", e);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
PolicyManagementDAOFactory.rollbackTransaction(); PolicyManagementDAOFactory.rollbackTransaction();
throw new PolicyManagementException("Error occurred while getting the device details (" + throw new PolicyManagementException("Error occurred while getting the device details (" +
deviceIdentifier.getId() + ")", e); deviceIdentifier.getId() + ")", e);
} finally { } finally {
PolicyManagementDAOFactory.closeConnection(); PolicyManagementDAOFactory.closeConnection();
} }

@ -79,7 +79,7 @@ SimplePolicyEvaluationTest implements PolicyEvaluationPoint {
@Override @Override
public String getName() { public String getName() {
return "SimplePolicyEvaluationServiceComponent"; return "SimplePolicy";
} }
public void sortPolicies(List<Policy> policyList) throws PolicyEvaluationException { public void sortPolicies(List<Policy> policyList) throws PolicyEvaluationException {

@ -42,8 +42,8 @@
<maxRetries>5</maxRetries> <maxRetries>5</maxRetries>
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable> <minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
<minRetriesToMarkInactive>20</minRetriesToMarkInactive> <minRetriesToMarkInactive>20</minRetriesToMarkInactive>
<!--<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>--> <!--<PolicyEvaluationPoint>Simple</PolicyEvaluationPoint>-->
<PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName> <PolicyEvaluationPoint>Merged</PolicyEvaluationPoint>
</PolicyConfiguration> </PolicyConfiguration>
</ManagementRepository> </ManagementRepository>
</DeviceMgtConfiguration> </DeviceMgtConfiguration>

@ -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 @@
<MaxRetries>5</MaxRetries>
<MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable>
<MinRetriesToMarkInactive>20</MinRetriesToMarkInactive>
- <!--<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>-->
- <PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName>
+ <!--<PolicyEvaluationPoint>Simple</PolicyEvaluationPoint>-->
+ <PolicyEvaluationPoint>Merged</PolicyEvaluationPoint>
<Platforms>
<Platform>android</Platform>
<Platform>ios</Platform>

@ -43,8 +43,8 @@
<MaxRetries>5</MaxRetries> <MaxRetries>5</MaxRetries>
<MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable> <MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable>
<MinRetriesToMarkInactive>20</MinRetriesToMarkInactive> <MinRetriesToMarkInactive>20</MinRetriesToMarkInactive>
<!--<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>--> <!--<PolicyEvaluationPoint>Simple</PolicyEvaluationPoint>-->
<PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName> <PolicyEvaluationPoint>Merged</PolicyEvaluationPoint>
<Platforms> <Platforms>
<Platform>android</Platform> <Platform>android</Platform>
<Platform>ios</Platform> <Platform>ios</Platform>

Loading…
Cancel
Save