mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Minor refactoring on policy merging
This commit is contained in:
parent
451b2fd1dc
commit
eb1575126f
@ -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(
|
||||
|
||||
@ -33,7 +33,7 @@ public class PolicyConfiguration {
|
||||
private int minRetriesToMarkUnreachable;
|
||||
private int minRetriesToMarkInactive;
|
||||
private List<String> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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");
|
||||
|
||||
@ -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();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -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<Policy> policyList;
|
||||
PIPDevice pipDevice;
|
||||
private static final String effectivePolicyName = "Effective-Policy";
|
||||
private static final String policyEvaluationPoint = "Merged";
|
||||
|
||||
@Override
|
||||
public List<ProfileFeature> getEffectiveFeatures(List<Policy> 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<ProfileFeature> getEffectiveFeatures(List<Policy> 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<Policy> 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<Policy> policyList) throws PolicyEvaluationException, PolicyManagementException {
|
||||
sortPolicies();
|
||||
Collections.sort(policyList, Collections.reverseOrder());
|
||||
|
||||
// Iterate through all policies
|
||||
Map<String, ProfileFeature> featureMap = new HashMap<>();
|
||||
// Merge roles of policies
|
||||
//Map<String, java.lang.Integer> rolesMap = new HashMap<>();
|
||||
Iterator<Policy> policyIterator = policyList.iterator();
|
||||
while (policyIterator.hasNext()) {
|
||||
Policy policy = policyIterator.next();
|
||||
for (Policy policy : policyList) {
|
||||
List<ProfileFeature> profileFeaturesList = policy.getProfile().getProfileFeaturesList();
|
||||
if (profileFeaturesList != null) {
|
||||
Iterator<ProfileFeature> featureIterator = profileFeaturesList.iterator();
|
||||
while (featureIterator.hasNext()) {
|
||||
ProfileFeature feature = featureIterator.next();
|
||||
for (ProfileFeature feature : profileFeaturesList) {
|
||||
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
|
||||
List<ProfileFeature> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<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();
|
||||
}
|
||||
|
||||
@ -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());
|
||||
|
||||
@ -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.";
|
||||
|
||||
@ -102,7 +102,7 @@ public class PolicyManagementDataHolder {
|
||||
}
|
||||
|
||||
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()) {
|
||||
log.debug("Removing Policy Information Service");
|
||||
}
|
||||
PolicyManagementDataHolder.getInstance().removePolicyEvaluationPoint(null);
|
||||
PolicyManagementDataHolder.getInstance().removePolicyEvaluationPoint(pepService);
|
||||
}
|
||||
|
||||
protected void setDeviceManagementService(DeviceManagementProviderService deviceManagerService) {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ SimplePolicyEvaluationTest implements PolicyEvaluationPoint {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "SimplePolicyEvaluationServiceComponent";
|
||||
return "SimplePolicy";
|
||||
}
|
||||
|
||||
public void sortPolicies(List<Policy> policyList) throws PolicyEvaluationException {
|
||||
|
||||
@ -42,8 +42,8 @@
|
||||
<maxRetries>5</maxRetries>
|
||||
<minRetriesToMarkUnreachable>8</minRetriesToMarkUnreachable>
|
||||
<minRetriesToMarkInactive>20</minRetriesToMarkInactive>
|
||||
<!--<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>-->
|
||||
<PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName>
|
||||
<!--<PolicyEvaluationPoint>Simple</PolicyEvaluationPoint>-->
|
||||
<PolicyEvaluationPoint>Merged</PolicyEvaluationPoint>
|
||||
</PolicyConfiguration>
|
||||
</ManagementRepository>
|
||||
</DeviceMgtConfiguration>
|
||||
|
||||
15
e, commit your changes or stash them before you can merge.
Normal file
15
e, commit your changes or stash them before you can merge.
Normal file
@ -0,0 +1,15 @@
|
||||
[1mdiff --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[m
|
||||
[1mindex addf38e..4e2ad6b 100644[m
|
||||
[1m--- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml[m
|
||||
[1m+++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml[m
|
||||
[36m@@ -43,8 +43,8 @@[m
|
||||
<MaxRetries>5</MaxRetries>[m
|
||||
<MinRetriesToMarkUnreachable>8</MinRetriesToMarkUnreachable>[m
|
||||
<MinRetriesToMarkInactive>20</MinRetriesToMarkInactive>[m
|
||||
[31m- <!--<PolicyEvaluationPointName>SimplePolicyEvaluationServiceComponent</PolicyEvaluationPointName>-->[m
|
||||
[31m- <PolicyEvaluationPointName>MergedPolicyEvaluationServiceComponent</PolicyEvaluationPointName>[m
|
||||
[32m+[m[32m <!--<PolicyEvaluationPoint>Simple</PolicyEvaluationPoint>-->[m
|
||||
[32m+[m[32m <PolicyEvaluationPoint>Merged</PolicyEvaluationPoint>[m
|
||||
<Platforms>[m
|
||||
<Platform>android</Platform>[m
|
||||
<Platform>ios</Platform>[m
|
||||
Binary file not shown.
@ -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>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user