From 21bc81228195ec45fd54dece8ec11107a77971fe Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 11 Oct 2016 16:11:29 +0530 Subject: [PATCH 01/22] Minor refactoring on Policy Eval service comp --- .../point/internal/PolicyEvaluationServiceComponent.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyEvaluationServiceComponent.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyEvaluationServiceComponent.java index 189534294f..74dcca1eec 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyEvaluationServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyEvaluationServiceComponent.java @@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; -import org.wso2.carbon.simple.policy.decision.point.PolicyEvaluationServiceImpl; +import org.wso2.carbon.simple.policy.decision.point.SimpleEvaluationPoint; import org.wso2.carbon.user.core.service.RealmService; /** @@ -52,8 +52,9 @@ public class PolicyEvaluationServiceComponent { } try { + //TODO: fetch PEP class from config componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(), - new PolicyEvaluationServiceImpl(), null); + new SimpleEvaluationPoint(), null); } catch (Throwable t) { log.error("Error occurred while initializing the simple policy evaluation bundle"); } From cc5d9012c1a278db8634bfd36ab5738011a2d92a Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 11 Oct 2016 16:13:30 +0530 Subject: [PATCH 02/22] Created simple evaluation point --- .../decision/point/SimpleEvaluationPoint.java | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java new file mode 100644 index 0000000000..b2b81076ed --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java @@ -0,0 +1,119 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.simple.policy.decision.point; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.mgt.common.*; +import org.wso2.carbon.policy.mgt.core.PolicyManagerService; +import org.wso2.carbon.simple.policy.decision.point.internal.PolicyDecisionPointDataHolder; + +import java.util.*; + +public class SimpleEvaluationPoint implements PolicyEvaluationPoint { + + private static final Log log = LogFactory.getLog(SimpleEvaluationPoint.class); + //TODO : to revove the stale reference + private PolicyManagerService policyManagerService; + private List policyList; +// public SimpleEvaluationPoint() { +// policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); +// } + + + @Override + public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + PolicyAdministratorPoint policyAdministratorPoint; + PolicyInformationPoint policyInformationPoint; + policyManagerService = getPolicyManagerService(); + + try { + if (policyManagerService != null) { + + policyInformationPoint = policyManagerService.getPIP(); + PIPDevice pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier); + policyList = policyInformationPoint.getRelatedPolicies(pipDevice); + + if (!policyList.isEmpty()) { + //policy = policyList.get(0); + //policyList = new ArrayList(); + Policy effectivePolicy = policyResolve(policyList); + effectivePolicy.setActive(true); + //TODO : UNCOMMENT THE FOLLOWING CASE + 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 + public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + Policy policy = new Policy(); + Profile profile = new Profile(); + profile.setProfileFeaturesList(getEffectiveFeatures(deviceIdentifier)); + policy.setProfile(profile); + return policy; + } + + private Policy policyResolve(List policyList) throws PolicyEvaluationException, PolicyManagementException { + sortPolicies(); + + // Iterate through all policies + Map featureMap = new HashMap<>(); + Iterator policyIterator = policyList.iterator(); + while (policyIterator.hasNext()) { + Policy policy = policyIterator.next(); + List profileFeaturesList = policy.getProfile().getProfileFeaturesList(); + if (profileFeaturesList != null) { + Iterator featureIterator = profileFeaturesList.iterator(); + while (featureIterator.hasNext()) { + ProfileFeature feature = featureIterator.next(); + featureMap.put(feature.getFeatureCode(), feature); + } + } + } + + // Get prioritized features list + List newFeaturesList = new ArrayList<>(featureMap.values()); + Profile profile = new Profile(); + profile.setProfileFeaturesList(newFeaturesList); + + Policy effectivePolicy = new Policy(); + effectivePolicy.setProfile(profile); + + return effectivePolicy; + } + + public void sortPolicies() throws PolicyEvaluationException { + //Collections.sort(policyList); + Collections.sort(policyList, Collections.reverseOrder()); + } + + private PolicyManagerService getPolicyManagerService() { + return PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); + } +} From c91da9219d3ef5c2e8094bb7f85349681d86f0a6 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Fri, 4 Nov 2016 22:01:51 +0530 Subject: [PATCH 03/22] fixed policy conflicts --- .../mgt/core/PolicyManagerServiceImpl.java | 17 ++++++++++++----- .../decision/point/SimpleEvaluationPoint.java | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) 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 da127b70a9..89c244f55a 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 @@ -91,11 +91,18 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { @Override public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException { try { - Policy policy = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(). - getEffectivePolicy(deviceIdentifier); - - if (policy == null) { - return null; + PolicyEvaluationPoint policyEvaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); + Policy policy; + + if (policyEvaluationPoint != null) { + policy = policyEvaluationPoint. + getEffectivePolicy(deviceIdentifier); + if (policy == null) { + return null; + } + } else { + throw new PolicyEvaluationException("Error occurred while getting the policy evaluation point " + + deviceIdentifier.getId() + " - " + deviceIdentifier.getType()); } List deviceIdentifiers = new ArrayList(); deviceIdentifiers.add(deviceIdentifier); diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java index b2b81076ed..1519fea1c5 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java @@ -72,6 +72,11 @@ public class SimpleEvaluationPoint implements PolicyEvaluationPoint { @Override public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + + if (policyManagerService == null || policyList.size() == 0) { + return null; + } + Policy policy = new Policy(); Profile profile = new Profile(); profile.setProfileFeaturesList(getEffectiveFeatures(deviceIdentifier)); From 33b79dcbba104c1424c846f3d1c2dea09e845330 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Mon, 7 Nov 2016 17:25:28 +0530 Subject: [PATCH 04/22] Adding effective policy service --- .../service/api/PolicyManagementService.java | 4 +++ .../impl/PolicyManagementServiceImpl.java | 25 +++++++++++++++++ .../decision/point/SimpleEvaluationPoint.java | 28 +++++++++++++------ 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java index 6a77938b0f..9226fd61dc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java @@ -562,5 +562,9 @@ public interface PolicyManagementService { required = true) List priorityUpdatedPolicies); + @GET + @Path("/effective-policy/{deviceType}/{deviceId}") + @Permission(name = "Get Effective Policy of Devices", permission = "/device-mgt/policies/view") + Response getEffectivePolicy(@PathParam("deviceId") String deviceId, @PathParam("deviceType") String deviceType); } 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 16e7a8eb06..be9d318e3e 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 @@ -373,4 +373,29 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { } } + @GET + @Path("/effective-policy/{deviceType}/{deviceId}") + @Override + public Response getEffectivePolicy(@PathParam("deviceId") String deviceId, @PathParam("deviceType") String deviceType) { + PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); + final org.wso2.carbon.policy.mgt.common.Policy policy; + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(deviceId); + deviceIdentifier.setType(deviceType); + policy = policyManagementService.getEffectivePolicy(deviceIdentifier); + if (policy == null) { + return Response.status(Response.Status.NOT_FOUND).entity( + new ErrorResponse.ErrorResponseBuilder().setMessage( + "No policy found for device ID '" + deviceId + "'"+ deviceId).build()).build(); + } + } catch (PolicyManagementException e) { + String msg = "Error occurred while retrieving policy corresponding to the id '" + deviceType + "'"+ deviceId; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + return Response.status(Response.Status.OK).entity(policy).build(); + } + } diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java index 1519fea1c5..137d95c3aa 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java @@ -33,6 +33,7 @@ public class SimpleEvaluationPoint implements PolicyEvaluationPoint { //TODO : to revove the stale reference private PolicyManagerService policyManagerService; private List policyList; + PIPDevice pipDevice; // public SimpleEvaluationPoint() { // policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); // } @@ -73,15 +74,26 @@ public class SimpleEvaluationPoint implements PolicyEvaluationPoint { @Override public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { - if (policyManagerService == null || policyList.size() == 0) { - return null; + try { + policyManagerService = getPolicyManagerService(); + PolicyInformationPoint policyInformationPoint = policyManagerService.getPIP(); + pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier); + policyList = policyInformationPoint.getRelatedPolicies(pipDevice); + + if (policyManagerService == null || policyList.size() == 0) { + return null; + } + + Policy policy = new Policy(); + Profile profile = new Profile(); + profile.setProfileFeaturesList(getEffectiveFeatures(deviceIdentifier)); + policy.setProfile(profile); + return policy; + } 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); } - - Policy policy = new Policy(); - Profile profile = new Profile(); - profile.setProfileFeaturesList(getEffectiveFeatures(deviceIdentifier)); - policy.setProfile(profile); - return policy; } private Policy policyResolve(List policyList) throws PolicyEvaluationException, PolicyManagementException { From 2847ff2095962ddacbaa700e78f0d64859756b4b Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 8 Nov 2016 09:26:15 +0530 Subject: [PATCH 05/22] Adding cdmf effective policy page --- .../cdmf.page.effective-policy.view/view.hbs | 43 +++++++++++++++++++ .../cdmf.page.effective-policy.view/view.js | 26 +++++++++++ .../cdmf.page.effective-policy.view/view.json | 5 +++ 3 files changed, 74 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.json diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.hbs new file mode 100644 index 0000000000..4fbf555f53 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.hbs @@ -0,0 +1,43 @@ +{{! + Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + + WSO2 Inc. licenses this file to you under the Apache License, + Version 2.0 (the "License"); you may not use this file + except in compliance with the License. You may + obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +}} + +{{unit "cdmf.unit.ui.title" pageTitle="Policy Management | View Policy"}} + +{{#zone "breadcrumbs"}} +
  • + + + +
  • +
  • + + + Policies + +
  • +
  • + + View + +
  • +{{/zone}} + +{{#zone "content"}} + {{unit "cdmf.unit.device.operation-mod"}} + {{unit "cdmf.unit.effective-policy.view"}} +{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.js new file mode 100644 index 0000000000..b7056d8c03 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +function onRequest(context) { + var utility = require("/app/modules/utility.js")["utility"]; + var deviceType = context.uriParams.deviceType; + var deviceId = context.uriParams.deviceId; + new Log().info("Device Type : "+deviceType); + new Log().info("Device ID : "+deviceId); + return {"deviceTypePolicyView": utility.getTenantedDeviceUnitName(deviceType, deviceId,"policy-view")}; +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.json new file mode 100644 index 0000000000..ec79d2b203 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "uri": "/policy/effective-policy/", + "layout": "cdmf.layout.default" +} \ No newline at end of file From 5a1c73b119cc71e56e9710eb89591e85609861d5 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 8 Nov 2016 09:33:10 +0530 Subject: [PATCH 06/22] Adding cdmf effective policy unit --- .../public/js/view.js | 2316 ++++++++ .../templates/hidden-operations-android.hbs | 1493 ++++++ .../templates/hidden-operations-ios.hbs | 4728 +++++++++++++++++ .../templates/hidden-operations-windows.hbs | 566 ++ .../cdmf.unit.effective-policy.view/view.hbs | 88 + .../cdmf.unit.effective-policy.view/view.js | 25 + .../cdmf.unit.effective-policy.view/view.json | 3 + 7 files changed, 9219 insertions(+) create mode 100644 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 create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-android.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-ios.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-windows.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.hbs create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.js create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.json 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 new file mode 100644 index 0000000000..067565db8e --- /dev/null +++ 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 @@ -0,0 +1,2316 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +var validateStep = {}; +var skipStep = {}; +var stepForwardFrom = {}; +var stepBackFrom = {}; +var policy = {}; +var configuredOperations = []; + +var baseApiUrl = "/api/device-mgt/v1.0"; + +// Constants to define platform types available +var platformTypeConstants = { + "ANDROID": "android", + "IOS": "ios", + "WINDOWS": "windows" +}; + +// Constants to define Android Operation Constants +var androidOperationConstants = { + "PASSCODE_POLICY_OPERATION": "passcode-policy", + "PASSCODE_POLICY_OPERATION_CODE": "PASSCODE_POLICY", + "CAMERA_OPERATION": "camera", + "CAMERA_OPERATION_CODE": "CAMERA", + "ENCRYPT_STORAGE_OPERATION": "encrypt-storage", + "ENCRYPT_STORAGE_OPERATION_CODE": "ENCRYPT_STORAGE", + "WIFI_OPERATION": "wifi", + "WIFI_OPERATION_CODE": "WIFI" +}; + +// Constants to define Android Operation Constants +var windowsOperationConstants = { + "PASSCODE_POLICY_OPERATION": "passcode-policy", + "PASSCODE_POLICY_OPERATION_CODE": "PASSCODE_POLICY", + "CAMERA_OPERATION": "camera", + "CAMERA_OPERATION_CODE": "CAMERA", + "ENCRYPT_STORAGE_OPERATION": "encrypt-storage", + "ENCRYPT_STORAGE_OPERATION_CODE": "ENCRYPT_STORAGE" +}; + +// Constants to define iOS Operation Constants +var iosOperationConstants = { + "PASSCODE_POLICY_OPERATION": "passcode-policy", + "PASSCODE_POLICY_OPERATION_CODE": "PASSCODE_POLICY", + "RESTRICTIONS_OPERATION": "restrictions", + "RESTRICTIONS_OPERATION_CODE": "RESTRICTION", + "WIFI_OPERATION": "wifi", + "WIFI_OPERATION_CODE": "WIFI", + "EMAIL_OPERATION": "email", + "EMAIL_OPERATION_CODE": "EMAIL", + "AIRPLAY_OPERATION": "airplay", + "AIRPLAY_OPERATION_CODE": "AIR_PLAY", + "LDAP_OPERATION": "ldap", + "LDAP_OPERATION_CODE": "LDAP", + "CALENDAR_OPERATION": "calendar", + "CALENDAR_OPERATION_CODE": "CALDAV", + "CALENDAR_SUBSCRIPTION_OPERATION": "calendar-subscription", + "CALENDAR_SUBSCRIPTION_OPERATION_CODE": "CALENDAR_SUBSCRIPTION", + "APN_OPERATION": "apn", + "APN_OPERATION_CODE": "APN", + "CELLULAR_OPERATION": "cellular", + "CELLULAR_OPERATION_CODE": "CELLULAR" +}; + +/** + * Method to update the visibility (i.e. disabled or enabled view) + * of grouped input according to the values + * that they currently possess. + * @param domElement HTML grouped-input element with class name "grouped-input" + */ +var updateGroupedInputVisibility = function (domElement) { + if ($(".parent-input:first", domElement).is(":checked")) { + if ($(".grouped-child-input:first", domElement).hasClass("disabled")) { + $(".grouped-child-input:first", domElement).removeClass("disabled"); + } + $(".child-input", domElement).each(function () { + $(this).prop('disabled', false); + }); + } else { + if (!$(".grouped-child-input:first", domElement).hasClass("disabled")) { + $(".grouped-child-input:first", domElement).addClass("disabled"); + } + $(".child-input", domElement).each(function () { + $(this).prop('disabled', true); + }); + } +}; + +skipStep["policy-platform"] = function (policyPayloadObj) { + policy["name"] = policyPayloadObj["policyName"]; + policy["platform"] = policyPayloadObj["profile"]["deviceType"]; + var userRoleInput = $("#user-roles-input"); + var ownershipInput = $("#ownership-input"); + var userInput = $("#users-select-field"); + var actionInput = $("#action-input"); + var policyNameInput = $("#policy-name-input"); + var policyDescriptionInput = $("#policy-description-input"); + userRoleInput.val(policyPayloadObj.roles); + userInput.val(policyPayloadObj.users); + ownershipInput.val(policyPayloadObj.ownershipType); + actionInput.val(policyPayloadObj.compliance); + policyNameInput.val(policyPayloadObj["policyName"]); + 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()); + $("#policy-description").text(policyPayloadObj["description"]); + var policyStatus = "Active"; + if (policyPayloadObj["active"] == true && policyPayloadObj["updated"] == true) { + policyStatus = ' Active/Updated'; + } else if (policyPayloadObj["active"] == true && policyPayloadObj["updated"] == false) { + policyStatus = ' Active'; + } else if (policyPayloadObj["active"] == false && policyPayloadObj["updated"] == true) { + policyStatus = ' Inactive/Updated'; + } else if (policyPayloadObj["active"] == false && policyPayloadObj["updated"] == false) { + policyStatus = ' Inactive'; + } + + $("#policy-status").html(policyStatus); + + // if (policyPayloadObj.users.length > 0) { + // $("#policy-users").text(policyPayloadObj.users.toString().split(",").join(", ")); + // } else { + // $("#users-row").addClass("hidden"); + // } + // + // if (policyPayloadObj.roles.length > 0) { + // $("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", ")); + // } else { + // $("#roles-row").addClass("hidden"); + // } + + var deviceType = "android"; + var hiddenOperationsByDeviceType = $("#hidden-operations-" + "android"); + var hiddenOperationsByDeviceTypeCacheKey = "android" + "HiddenOperations"; + var hiddenOperationsByDeviceTypeSrc = hiddenOperationsByDeviceType.attr("src"); + + setTimeout( + function () { + $.template(hiddenOperationsByDeviceTypeCacheKey, hiddenOperationsByDeviceTypeSrc, function (template) { + var content = template(); + // pushing profile feature input elements + $(".wr-advance-operations").html(content); + // populating values and getting the list of configured features + var configuredOperations = operationModule. + 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); + }); + // enabling previously configured options of last update + 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(); + }); + } + }); + }, + 250 // time delayed for the execution of above function, 250 milliseconds + ); +}; + +/** + * Checks if provided number is valid against a range. + * + * @param numberInput Number Input + * @param min Minimum Limit + * @param max Maximum Limit + * @returns {boolean} Returns true if input is within the specified range + */ +var inputIsValidAgainstRange = function (numberInput, min, max) { + return (numberInput == min || (numberInput > min && numberInput < max) || numberInput == max); +}; + +/** + * Checks if provided input is valid against RegEx input. + * + * @param regExp Regular expression + * @param input Input string to check + * @returns {boolean} Returns true if input matches RegEx + */ +var inputIsValidAgainstRegExp = function (regExp, input) { + return regExp.test(input); +}; + +validateStep["policy-profile"] = function () { + var validationStatusArray = []; + var validationStatus; + var operation; + + // starting validation process and updating validationStatus + if (policy["platform"] == platformTypeConstants["ANDROID"]) { + if (configuredOperations.length == 0) { + // updating validationStatus + validationStatus = { + "error": true, + "mainErrorMsg": "You cannot continue. Zero configured features." + }; + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } else { + // validating each and every configured Operation + // Validating PASSCODE_POLICY + if ($.inArray(androidOperationConstants["PASSCODE_POLICY_OPERATION_CODE"], configuredOperations) != -1) { + // if PASSCODE_POLICY is configured + operation = androidOperationConstants["PASSCODE_POLICY_OPERATION"]; + // initializing continueToCheckNextInputs to true + var continueToCheckNextInputs = true; + + // validating first input: passcodePolicyMaxPasscodeAgeInDays + var passcodePolicyMaxPasscodeAgeInDays = $("input#passcode-policy-max-passcode-age-in-days").val(); + if (passcodePolicyMaxPasscodeAgeInDays) { + if (!$.isNumeric(passcodePolicyMaxPasscodeAgeInDays)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode age is not a number.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(passcodePolicyMaxPasscodeAgeInDays, 1, 730)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode age is not with in the range of 1-to-730.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + + // validating second and last input: passcodePolicyPasscodeHistory + if (continueToCheckNextInputs) { + var passcodePolicyPasscodeHistory = $("input#passcode-policy-passcode-history").val(); + if (passcodePolicyPasscodeHistory) { + if (!$.isNumeric(passcodePolicyPasscodeHistory)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode history is not a number.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(passcodePolicyPasscodeHistory, 1, 50)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode history is not with in the range of 1-to-50.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating CAMERA + if ($.inArray(androidOperationConstants["CAMERA_OPERATION_CODE"], configuredOperations) != -1) { + // if CAMERA is configured + operation = androidOperationConstants["CAMERA_OPERATION"]; + // updating validationStatus + validationStatus = { + "error": false, + "okFeature": operation + }; + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating ENCRYPT_STORAGE + if ($.inArray(androidOperationConstants["ENCRYPT_STORAGE_OPERATION_CODE"], configuredOperations) != -1) { + // if ENCRYPT_STORAGE is configured + operation = androidOperationConstants["ENCRYPT_STORAGE_OPERATION"]; + // updating validationStatus + validationStatus = { + "error": false, + "okFeature": operation + }; + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating WIFI + if ($.inArray(androidOperationConstants["WIFI_OPERATION_CODE"], configuredOperations) != -1) { + // if WIFI is configured + operation = androidOperationConstants["WIFI_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + var wifiSSID = $("input#wifi-ssid").val(); + if (!wifiSSID) { + validationStatus = { + "error": true, + "subErrorMsg": "WIFI SSID is not given. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + } + } + if (policy["platform"] == platformTypeConstants["WINDOWS"]) { + if (configuredOperations.length == 0) { + // updating validationStatus + validationStatus = { + "error": true, + "mainErrorMsg": "You cannot continue. Zero configured features." + }; + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } else { + // validating each and every configured Operation + // Validating PASSCODE_POLICY + if ($.inArray(windowsOperationConstants["PASSCODE_POLICY_OPERATION_CODE"], configuredOperations) != -1) { + // if PASSCODE_POLICY is configured + operation = windowsOperationConstants["PASSCODE_POLICY_OPERATION"]; + // initializing continueToCheckNextInputs to true + var continueToCheckNextInputs = true; + + // validating first input: passcodePolicyMaxPasscodeAgeInDays + var passcodePolicyMaxPasscodeAgeInDays = $("input#passcode-policy-max-passcode-age-in-days").val(); + if (passcodePolicyMaxPasscodeAgeInDays) { + if (!$.isNumeric(passcodePolicyMaxPasscodeAgeInDays)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode age is not a number.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(passcodePolicyMaxPasscodeAgeInDays, 1, 730)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode age is not with in the range of 1-to-730.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + + // validating second and last input: passcodePolicyPasscodeHistory + if (continueToCheckNextInputs) { + var passcodePolicyPasscodeHistory = $("input#passcode-policy-passcode-history").val(); + if (passcodePolicyPasscodeHistory) { + if (!$.isNumeric(passcodePolicyPasscodeHistory)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode history is not a number.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(passcodePolicyPasscodeHistory, 1, 50)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode history is not with in the range of 1-to-50.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating CAMERA + if ($.inArray(windowsOperationConstants["CAMERA_OPERATION_CODE"], configuredOperations) != -1) { + // if CAMERA is configured + operation = windowsOperationConstants["CAMERA_OPERATION"]; + // updating validationStatus + validationStatus = { + "error": false, + "okFeature": operation + }; + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating ENCRYPT_STORAGE + if ($.inArray(windowsOperationConstants["ENCRYPT_STORAGE_OPERATION_CODE"], configuredOperations) != -1) { + // if ENCRYPT_STORAGE is configured + operation = windowsOperationConstants["ENCRYPT_STORAGE_OPERATION"]; + // updating validationStatus + validationStatus = { + "error": false, + "okFeature": operation + }; + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + + } + } else if (policy["platform"] == platformTypeConstants["IOS"]) { + if (configuredOperations.length == 0) { + // updating validationStatus + validationStatus = { + "error": true, + "mainErrorMsg": "You cannot continue. Zero configured features." + }; + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } else { + // validating each and every configured Operation + // Validating PASSCODE_POLICY + if ($.inArray(iosOperationConstants["PASSCODE_POLICY_OPERATION_CODE"], configuredOperations) != -1) { + // if PASSCODE_POLICY is configured + operation = iosOperationConstants["PASSCODE_POLICY_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + // validating first input: passcodePolicyMaxPasscodeAgeInDays + passcodePolicyMaxPasscodeAgeInDays = $("input#passcode-policy-max-passcode-age-in-days").val(); + if (passcodePolicyMaxPasscodeAgeInDays) { + if (!$.isNumeric(passcodePolicyMaxPasscodeAgeInDays)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode age is not a number.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(passcodePolicyMaxPasscodeAgeInDays, 1, 730)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode age is not with in the range of 1-to-730.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + + // validating second and last input: passcodePolicyPasscodeHistory + if (continueToCheckNextInputs) { + passcodePolicyPasscodeHistory = $("input#passcode-policy-passcode-history").val(); + if (passcodePolicyPasscodeHistory) { + if (!$.isNumeric(passcodePolicyPasscodeHistory)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode history is not a number.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(passcodePolicyPasscodeHistory, 1, 50)) { + validationStatus = { + "error": true, + "subErrorMsg": "Provided passcode history is not with in the range of 1-to-50.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating RESTRICTIONS + if ($.inArray(iosOperationConstants["RESTRICTIONS_OPERATION_CODE"], configuredOperations) != -1) { + // if RESTRICTION is configured + operation = iosOperationConstants["RESTRICTIONS_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + // getting input values to be validated + var restrictionsAutonomousSingleAppModePermittedAppIDsGridChildInputs = + "div#restrictions-autonomous-single-app-mode-permitted-app-ids .child-input"; + if ($(restrictionsAutonomousSingleAppModePermittedAppIDsGridChildInputs).length > 0) { + var childInput; + var childInputArray = []; + var emptyChildInputCount = 0; + var duplicatesExist = false; + // looping through each child input + $(restrictionsAutonomousSingleAppModePermittedAppIDsGridChildInputs).each(function () { + childInput = $(this).val(); + childInputArray.push(childInput); + if (!childInput) { + // if child input field is empty + emptyChildInputCount++; + } + }); + // checking for duplicates + var initialChildInputArrayLength = childInputArray.length; + if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { + var m, poppedChildInput; + for (m = 0; m < (initialChildInputArrayLength - 1); m++) { + poppedChildInput = childInputArray.pop(); + var n; + for (n = 0; n < childInputArray.length; n++) { + if (poppedChildInput == childInputArray[n]) { + duplicatesExist = true; + break; + } + } + if (duplicatesExist) { + break; + } + } + } + // updating validationStatus + if (emptyChildInputCount > 0) { + // if empty child inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more permitted App ID entries in " + + "Autonomous Single App Mode are empty.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (duplicatesExist) { + validationStatus = { + "error": true, + "subErrorMsg": "Duplicate values exist with permitted App ID entries in " + + "Autonomous Single App Mode.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating WIFI + if ($.inArray(iosOperationConstants["WIFI_OPERATION_CODE"], configuredOperations) != -1) { + // if WIFI is configured + operation = iosOperationConstants["WIFI_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + // getting input values to be validated + wifiSSID = $("input#wifi-ssid").val(); + var wifiDomainName = $("input#wifi-domain-name").val(); + if (!wifiSSID && !wifiDomainName) { + validationStatus = { + "error": true, + "subErrorMsg": "Both Wi-Fi SSID and Wi-Fi Domain Name are not given. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + + if (continueToCheckNextInputs) { + // getting proxy-setup value + var wifiProxyType = $("select#wifi-proxy-type").find("option:selected").attr("value"); + if (wifiProxyType == "Manual") { + // adds up additional fields to be validated + var wifiProxyServer = $("input#wifi-proxy-server").val(); + if (!wifiProxyServer) { + validationStatus = { + "error": true, + "subErrorMsg": "Wi-Fi Proxy Server is required. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + + if (continueToCheckNextInputs) { + var wifiProxyPort = $("input#wifi-proxy-port").val(); + if (!wifiProxyPort) { + validationStatus = { + "error": true, + "subErrorMsg": "Wi-Fi Proxy Port is required. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!$.isNumeric(wifiProxyPort)) { + validationStatus = { + "error": true, + "subErrorMsg": "Wi-Fi Proxy Port requires a number input.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(wifiProxyPort, 0, 65535)) { + validationStatus = { + "error": true, + "subErrorMsg": "Wi-Fi Proxy Port is not within the range " + + "of valid port numbers.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + } + + if (continueToCheckNextInputs) { + // getting encryption-type value + var wifiEncryptionType = $("select#wifi-encryption-type").find("option:selected").attr("value"); + if (wifiEncryptionType != "None") { + var wifiPayloadCertificateAnchorUUIDsGridChildInputs = + "div#wifi-payload-certificate-anchor-uuids .child-input"; + if ($(wifiPayloadCertificateAnchorUUIDsGridChildInputs).length > 0) { + emptyChildInputCount = 0; + childInputArray = []; + duplicatesExist = false; + // looping through each child input + $(wifiPayloadCertificateAnchorUUIDsGridChildInputs).each(function () { + childInput = $(this).val(); + childInputArray.push(childInput); + if (!childInput) { + // if child input field is empty + emptyChildInputCount++; + } + }); + // checking for duplicates + initialChildInputArrayLength = childInputArray.length; + if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { + for (m = 0; m < (initialChildInputArrayLength - 1); m++) { + poppedChildInput = childInputArray.pop(); + for (n = 0; n < childInputArray.length; n++) { + if (poppedChildInput == childInputArray[n]) { + duplicatesExist = true; + break; + } + } + if (duplicatesExist) { + break; + } + } + } + // updating validationStatus + if (emptyChildInputCount > 0) { + // if empty child inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more Payload Certificate " + + "Anchor UUIDs are empty.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (duplicatesExist) { + validationStatus = { + "error": true, + "subErrorMsg": "Duplicate values exist " + + "with Payload Certificate Anchor UUIDs.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + + if (continueToCheckNextInputs) { + var wifiTLSTrustedServerNamesGridChildInputs = + "div#wifi-tls-trusted-server-names .child-input"; + if ($(wifiTLSTrustedServerNamesGridChildInputs).length > 0) { + emptyChildInputCount = 0; + childInputArray = []; + duplicatesExist = false; + // looping through each child input + $(wifiTLSTrustedServerNamesGridChildInputs).each(function () { + childInput = $(this).val(); + childInputArray.push(childInput); + if (!childInput) { + // if child input field is empty + emptyChildInputCount++; + } + }); + // checking for duplicates + initialChildInputArrayLength = childInputArray.length; + if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { + for (m = 0; m < (initialChildInputArrayLength - 1); m++) { + poppedChildInput = childInputArray.pop(); + for (n = 0; n < childInputArray.length; n++) { + if (poppedChildInput == childInputArray[n]) { + duplicatesExist = true; + break; + } + } + if (duplicatesExist) { + break; + } + } + } + // updating validationStatus + if (emptyChildInputCount > 0) { + // if empty child inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more TLS Trusted Server Names are empty.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (duplicatesExist) { + validationStatus = { + "error": true, + "subErrorMsg": "Duplicate values exist " + + "with TLS Trusted Server Names.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + } + } + + if (continueToCheckNextInputs) { + var wifiRoamingConsortiumOIsGridChildInputs = "div#wifi-roaming-consortium-ois .child-input"; + if ($(wifiRoamingConsortiumOIsGridChildInputs).length > 0) { + emptyChildInputCount = 0; + var outOfAllowedLengthCount = 0; + var invalidAgainstRegExCount = 0; + childInputArray = []; + duplicatesExist = false; + // looping through each child input + $(wifiRoamingConsortiumOIsGridChildInputs).each(function () { + childInput = $(this).val(); + childInputArray.push(childInput); + if (!childInput) { + // if child input field is empty + emptyChildInputCount++; + } else if (!inputIsValidAgainstLength(childInput, 6, 6) && !inputIsValidAgainstLength(childInput, 10, 10)) { + outOfAllowedLengthCount++; + } else if (!inputIsValidAgainstRegExp(/^[a-fA-F0-9]+$/, childInput)) { + invalidAgainstRegExCount++; + } + }); + // checking for duplicates + initialChildInputArrayLength = childInputArray.length; + if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { + for (m = 0; m < (initialChildInputArrayLength - 1); m++) { + poppedChildInput = childInputArray.pop(); + for (n = 0; n < childInputArray.length; n++) { + if (poppedChildInput == childInputArray[n]) { + duplicatesExist = true; + break; + } + } + if (duplicatesExist) { + break; + } + } + } + // updating validationStatus + if (emptyChildInputCount > 0) { + // if empty child inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more Roaming Consortium OIs are empty.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (outOfAllowedLengthCount > 0) { + // if outOfMaxAllowedLength input is present + validationStatus = { + "error": true, + "subErrorMsg": "One or more Roaming Consortium OIs " + + "are out of allowed length.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (invalidAgainstRegExCount > 0) { + // if invalid inputs in terms of hexadecimal format are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more Roaming Consortium OIs " + + "contain non-hexadecimal characters.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (duplicatesExist) { + validationStatus = { + "error": true, + "subErrorMsg": "Duplicate values exist with Roaming Consortium OIs.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + + if (continueToCheckNextInputs) { + var wifiNAIRealmNamesGridChildInputs = "div#wifi-nai-realm-names .child-input"; + if ($(wifiNAIRealmNamesGridChildInputs).length > 0) { + emptyChildInputCount = 0; + childInputArray = []; + duplicatesExist = false; + // looping through each child input + $(wifiNAIRealmNamesGridChildInputs).each(function () { + childInput = $(this).val(); + childInputArray.push(childInput); + if (!childInput) { + // if child input field is empty + emptyChildInputCount++; + } + }); + // checking for duplicates + initialChildInputArrayLength = childInputArray.length; + if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { + for (m = 0; m < (initialChildInputArrayLength - 1); m++) { + poppedChildInput = childInputArray.pop(); + for (n = 0; n < childInputArray.length; n++) { + if (poppedChildInput == childInputArray[n]) { + duplicatesExist = true; + break; + } + } + if (duplicatesExist) { + break; + } + } + } + // updating validationStatus + if (emptyChildInputCount > 0) { + // if empty child inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more NAI Realm Names are empty.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (duplicatesExist) { + validationStatus = { + "error": true, + "subErrorMsg": "Duplicate values exist with NAI Realm Names.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + + if (continueToCheckNextInputs) { + var wifiMCCAndMNCsGridChildInputs = "div#wifi-mcc-and-mncs .child-input"; + if ($(wifiMCCAndMNCsGridChildInputs).length > 0) { + var childInputCount = 0; + var stringPair; + emptyChildInputCount = 0; + outOfAllowedLengthCount = 0; + var notNumericInputCount = 0; + childInputArray = []; + duplicatesExist = false; + // looping through each child input + $(wifiMCCAndMNCsGridChildInputs).each(function () { + childInput = $(this).val(); + // pushing each string pair to childInputArray + childInputCount++; + if (childInputCount % 2 == 1) { + // initialize stringPair value + stringPair = ""; + // append first part of the string + stringPair += childInput; + } else { + // append second part of the string + stringPair += childInput; + childInputArray.push(stringPair); + } + // updating emptyChildInputCount & outOfAllowedLengthCount + if (!childInput) { + // if child input field is empty + emptyChildInputCount++; + } else if (!$.isNumeric(childInput)) { + notNumericInputCount++; + } else if (!inputIsValidAgainstLength(childInput, 3, 3)) { + outOfAllowedLengthCount++; + } + }); + // checking for duplicates + initialChildInputArrayLength = childInputArray.length; + if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { + for (m = 0; m < (initialChildInputArrayLength - 1); m++) { + poppedChildInput = childInputArray.pop(); + for (n = 0; n < childInputArray.length; n++) { + if (poppedChildInput == childInputArray[n]) { + duplicatesExist = true; + break; + } + } + if (duplicatesExist) { + break; + } + } + } + // updating validationStatus + if (emptyChildInputCount > 0) { + // if empty child inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more MCC/MNC pairs are empty.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (notNumericInputCount > 0) { + // if notNumeric input is present + validationStatus = { + "error": true, + "subErrorMsg": "One or more MCC/MNC pairs are not numeric.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (outOfAllowedLengthCount > 0) { + // if outOfAllowedLength input is present + validationStatus = { + "error": true, + "subErrorMsg": "One or more MCC/MNC pairs " + + "do not fulfill the accepted length of 6 digits.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (duplicatesExist) { + validationStatus = { + "error": true, + "subErrorMsg": "Duplicate values exist with MCC/MNC pairs.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating EMAIL + if ($.inArray(iosOperationConstants["EMAIL_OPERATION_CODE"], configuredOperations) != -1) { + // if EMAIL is configured + operation = iosOperationConstants["EMAIL_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + var emailAddress = $("input#email-address").val(); + if (emailAddress && !inputIsValidAgainstRegExp(/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/, emailAddress)) { + validationStatus = { + "error": true, + "subErrorMsg": "Email Address is not valid.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + + if (continueToCheckNextInputs) { + var emailIncomingMailServerHostname = $("input#email-incoming-mail-server-hostname").val(); + if (!emailIncomingMailServerHostname) { + validationStatus = { + "error": true, + "subErrorMsg": "Incoming Mail Server Hostname is empty. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + + if (continueToCheckNextInputs) { + var emailIncomingMailServerPort = $("input#email-incoming-mail-server-port").val(); + if (!emailIncomingMailServerPort) { + validationStatus = { + "error": true, + "subErrorMsg": "Incoming Mail Server Port is empty. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!$.isNumeric(emailIncomingMailServerPort)) { + validationStatus = { + "error": true, + "subErrorMsg": "Incoming Mail Server Port requires a number input.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(emailIncomingMailServerPort, 0, 65535)) { + validationStatus = { + "error": true, + "subErrorMsg": "Incoming Mail Server Port is not within the range " + + "of valid port numbers.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + + if (continueToCheckNextInputs) { + var emailOutgoingMailServerHostname = $("input#email-outgoing-mail-server-hostname").val(); + if (!emailOutgoingMailServerHostname) { + validationStatus = { + "error": true, + "subErrorMsg": "Outgoing Mail Server Hostname is empty. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + + if (continueToCheckNextInputs) { + var emailOutgoingMailServerPort = $("input#email-outgoing-mail-server-port").val(); + if (!emailOutgoingMailServerPort) { + validationStatus = { + "error": true, + "subErrorMsg": "Outgoing Mail Server Port is empty. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!$.isNumeric(emailOutgoingMailServerPort)) { + validationStatus = { + "error": true, + "subErrorMsg": "Outgoing Mail Server Port requires a number input.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(emailOutgoingMailServerPort, 0, 65535)) { + validationStatus = { + "error": true, + "subErrorMsg": "Outgoing Mail Server Port is not within the range " + + "of valid port numbers.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating AIRPLAY + if ($.inArray(iosOperationConstants["AIRPLAY_OPERATION_CODE"], configuredOperations) != -1) { + // if AIRPLAY is configured + operation = iosOperationConstants["AIRPLAY_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + var airplayCredentialsGridChildInputs = "div#airplay-credentials .child-input"; + var airplayDestinationsGridChildInputs = "div#airplay-destinations .child-input"; + if ($(airplayCredentialsGridChildInputs).length == 0 && + $(airplayDestinationsGridChildInputs).length == 0) { + validationStatus = { + "error": true, + "subErrorMsg": "AirPlay settings have zero configurations attached.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + + if (continueToCheckNextInputs) { + if ($(airplayCredentialsGridChildInputs).length > 0) { + childInputCount = 0; + childInputArray = []; + emptyChildInputCount = 0; + duplicatesExist = false; + // looping through each child input + $(airplayCredentialsGridChildInputs).each(function () { + childInputCount++; + if (childInputCount % 2 == 1) { + // if child input is of first column + childInput = $(this).val(); + childInputArray.push(childInput); + // updating emptyChildInputCount + if (!childInput) { + // if child input field is empty + emptyChildInputCount++; + } + } + }); + // checking for duplicates + initialChildInputArrayLength = childInputArray.length; + if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { + for (m = 0; m < (initialChildInputArrayLength - 1); m++) { + poppedChildInput = childInputArray.pop(); + for (n = 0; n < childInputArray.length; n++) { + if (poppedChildInput == childInputArray[n]) { + duplicatesExist = true; + break; + } + } + if (duplicatesExist) { + break; + } + } + } + // updating validationStatus + if (emptyChildInputCount > 0) { + // if empty child inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more Device Names of " + + "AirPlay Credentials are empty.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (duplicatesExist) { + // if duplicate input is present + validationStatus = { + "error": true, + "subErrorMsg": "Duplicate values exist with " + + "Device Names of AirPlay Credentials.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + + if (continueToCheckNextInputs) { + if ($(airplayDestinationsGridChildInputs).length > 0) { + childInputArray = []; + emptyChildInputCount = 0; + invalidAgainstRegExCount = 0; + duplicatesExist = false; + // looping through each child input + $(airplayDestinationsGridChildInputs).each(function () { + childInput = $(this).val(); + childInputArray.push(childInput); + // updating emptyChildInputCount + if (!childInput) { + // 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)) { + // if child input field is invalid against RegEx + invalidAgainstRegExCount++ + } + }); + // checking for duplicates + initialChildInputArrayLength = childInputArray.length; + if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { + for (m = 0; m < (initialChildInputArrayLength - 1); m++) { + poppedChildInput = childInputArray.pop(); + for (n = 0; n < childInputArray.length; n++) { + if (poppedChildInput == childInputArray[n]) { + duplicatesExist = true; + break; + } + } + if (duplicatesExist) { + break; + } + } + } + // updating validationStatus + if (emptyChildInputCount > 0) { + // if empty child inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more AirPlay Destination fields are empty.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (invalidAgainstRegExCount > 0) { + // if invalidAgainstRegEx inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more AirPlay Destination fields " + + "do not fulfill expected format.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (duplicatesExist) { + // if duplicate input is present + validationStatus = { + "error": true, + "subErrorMsg": "Duplicate values exist with AirPlay Destinations.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating LDAP + if ($.inArray(iosOperationConstants["LDAP_OPERATION_CODE"], configuredOperations) != -1) { + // if LDAP is configured + operation = iosOperationConstants["LDAP_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + var ldapAccountHostname = $("input#ldap-account-hostname").val(); + if (!ldapAccountHostname) { + validationStatus = { + "error": true, + "subErrorMsg": "LDAP Account Hostname URL is empty. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + + if (continueToCheckNextInputs) { + var ldapSearchSettingsGridChildInputs = "div#ldap-search-settings .child-input"; + if ($(ldapSearchSettingsGridChildInputs).length > 0) { + childInputCount = 0; + childInputArray = []; + emptyChildInputCount = 0; + duplicatesExist = false; + // looping through each child input + $(ldapSearchSettingsGridChildInputs).each(function () { + childInputCount++; + if (childInputCount % 3 == 2) { + // if child input is of second column + childInput = $(this).find("option:selected").attr("value"); + stringPair = ""; + stringPair += (childInput + " "); + } else if (childInputCount % 3 == 0) { + // if child input is of third column + childInput = $(this).val(); + stringPair += childInput; + childInputArray.push(stringPair); + // updating emptyChildInputCount + if (!childInput) { + // if child input field is empty + emptyChildInputCount++; + } + } + }); + // checking for duplicates + initialChildInputArrayLength = childInputArray.length; + if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { + for (m = 0; m < (initialChildInputArrayLength - 1); m++) { + poppedChildInput = childInputArray.pop(); + for (n = 0; n < childInputArray.length; n++) { + if (poppedChildInput == childInputArray[n]) { + duplicatesExist = true; + break; + } + } + if (duplicatesExist) { + break; + } + } + } + // updating validationStatus + if (emptyChildInputCount > 0) { + // if empty child inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more Search Setting Scope fields are empty.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (duplicatesExist) { + // if duplicate input is present + validationStatus = { + "error": true, + "subErrorMsg": "Duplicate values exist with " + + "Search Setting Search Base and Scope pairs.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating CALENDAR + if ($.inArray(iosOperationConstants["CALENDAR_OPERATION_CODE"], configuredOperations) != -1) { + // if CALENDAR is configured + operation = iosOperationConstants["CALENDAR_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + var calendarAccountHostname = $("input#calendar-account-hostname").val(); + if (!calendarAccountHostname) { + validationStatus = { + "error": true, + "subErrorMsg": "Account Hostname URL is empty. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + + if (continueToCheckNextInputs) { + var calendarAccountPort = $("input#calendar-account-port").val(); + if (!calendarAccountPort) { + validationStatus = { + "error": true, + "subErrorMsg": "Account Port is empty. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!$.isNumeric(calendarAccountPort)) { + validationStatus = { + "error": true, + "subErrorMsg": "Account Port requires a number input.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(calendarAccountPort, 0, 65535)) { + validationStatus = { + "error": true, + "subErrorMsg": "Account Port is not within the range " + + "of valid port numbers.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating CALENDAR_SUBSCRIPTION + if ($.inArray(iosOperationConstants["CALENDAR_SUBSCRIPTION_OPERATION_CODE"], configuredOperations) != -1) { + // if CALENDAR_SUBSCRIPTION is configured + operation = iosOperationConstants["CALENDAR_SUBSCRIPTION_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + var calendarSubscriptionHostname = $("input#calendar-subscription-hostname").val(); + if (!calendarSubscriptionHostname) { + validationStatus = { + "error": true, + "subErrorMsg": "Account Hostname URL is empty. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating APN + if ($.inArray(iosOperationConstants["APN_OPERATION_CODE"], configuredOperations) != -1) { + // if APN is configured + operation = iosOperationConstants["APN_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + var apnConfigurationsGridChildInputs = "div#apn-configurations .child-input"; + if ($(apnConfigurationsGridChildInputs).length == 0) { + validationStatus = { + "error": true, + "subErrorMsg": "APN Settings have zero configurations attached.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if ($(apnConfigurationsGridChildInputs).length > 0) { + childInputCount = 0; + childInputArray = []; + // checking empty APN field count + emptyChildInputCount = 0; + duplicatesExist = false; + // looping through each child input + $(apnConfigurationsGridChildInputs).each(function () { + childInputCount++; + if (childInputCount % 5 == 1) { + // if child input is of first column + childInput = $(this).val(); + childInputArray.push(childInput); + // updating emptyChildInputCount + if (!childInput) { + // if child input field is empty + emptyChildInputCount++; + } + } + }); + // checking for duplicates + initialChildInputArrayLength = childInputArray.length; + if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { + for (m = 0; m < (initialChildInputArrayLength - 1); m++) { + poppedChildInput = childInputArray.pop(); + for (n = 0; n < childInputArray.length; n++) { + if (poppedChildInput == childInputArray[n]) { + duplicatesExist = true; + break; + } + } + if (duplicatesExist) { + break; + } + } + } + // updating validationStatus + if (emptyChildInputCount > 0) { + // if empty child inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more APN fields of Configurations are empty.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (duplicatesExist) { + // if duplicate input is present + validationStatus = { + "error": true, + "subErrorMsg": "Duplicate values exist with " + + "APN fields of Configurations.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + // Validating CELLULAR + if ($.inArray(iosOperationConstants["CELLULAR_OPERATION_CODE"], configuredOperations) != -1) { + // if CELLULAR is configured + operation = iosOperationConstants["CELLULAR_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + var cellularAttachAPNName = $("input#cellular-attach-apn-name").val(); + if (!cellularAttachAPNName) { + validationStatus = { + "error": true, + "subErrorMsg": "Cellular Configuration Name is empty. You cannot proceed.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + + if (continueToCheckNextInputs) { + var cellularAPNConfigurationsGridChildInputs = "div#cellular-apn-configurations .child-input"; + if ($(cellularAPNConfigurationsGridChildInputs).length > 0) { + childInputCount = 0; + childInputArray = []; + // checking empty APN field count + emptyChildInputCount = 0; + duplicatesExist = false; + // looping through each child input + $(cellularAPNConfigurationsGridChildInputs).each(function () { + childInputCount++; + if (childInputCount % 6 == 1) { + // if child input is of first column + childInput = $(this).val(); + childInputArray.push(childInput); + // updating emptyChildInputCount + if (!childInput) { + // if child input field is empty + emptyChildInputCount++; + } + } + }); + // checking for duplicates + initialChildInputArrayLength = childInputArray.length; + if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { + for (m = 0; m < (initialChildInputArrayLength - 1); m++) { + poppedChildInput = childInputArray.pop(); + for (n = 0; n < childInputArray.length; n++) { + if (poppedChildInput == childInputArray[n]) { + duplicatesExist = true; + break; + } + } + if (duplicatesExist) { + break; + } + } + } + // updating validationStatus + if (emptyChildInputCount > 0) { + // if empty child inputs are present + validationStatus = { + "error": true, + "subErrorMsg": "One or more APN fields of APN Configurations are empty.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (duplicatesExist) { + // if duplicate input is present + validationStatus = { + "error": true, + "subErrorMsg": "Duplicate values exist with " + + "APN fields of APN Configurations.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } + } + + // at-last, if the value of continueToCheckNextInputs is still true + // this means that no error is found + if (continueToCheckNextInputs) { + validationStatus = { + "error": false, + "okFeature": operation + }; + } + + // updating validationStatusArray with validationStatus + validationStatusArray.push(validationStatus); + } + } + } + // ending validation process + + // start taking specific notifying actions upon validation + var wizardIsToBeContinued; + var errorCount = 0; + var mainErrorMsgWrapper, mainErrorMsg, + subErrorMsgWrapper, subErrorMsg, subErrorIcon, subOkIcon, featureConfiguredIcon; + var i; + for (i = 0; i < validationStatusArray.length; i++) { + validationStatus = validationStatusArray[i]; + if (validationStatus["error"]) { + errorCount++; + if (validationStatus["mainErrorMsg"]) { + mainErrorMsgWrapper = "#policy-profile-main-error-msg"; + mainErrorMsg = mainErrorMsgWrapper + " span"; + $(mainErrorMsg).text(validationStatus["mainErrorMsg"]); + $(mainErrorMsgWrapper).removeClass("hidden"); + } else if (validationStatus["subErrorMsg"]) { + subErrorMsgWrapper = "#" + validationStatus["erroneousFeature"] + "-feature-error-msg"; + subErrorMsg = subErrorMsgWrapper + " span"; + subErrorIcon = "#" + validationStatus["erroneousFeature"] + "-error"; + subOkIcon = "#" + validationStatus["erroneousFeature"] + "-ok"; + featureConfiguredIcon = "#" + validationStatus["erroneousFeature"] + "-configured"; + // hiding featureConfiguredState as the first step + if (!$(featureConfiguredIcon).hasClass("hidden")) { + $(featureConfiguredIcon).addClass("hidden"); + } + // updating error state and corresponding messages + $(subErrorMsg).text(validationStatus["subErrorMsg"]); + if ($(subErrorMsgWrapper).hasClass("hidden")) { + $(subErrorMsgWrapper).removeClass("hidden"); + } + if (!$(subOkIcon).hasClass("hidden")) { + $(subOkIcon).addClass("hidden"); + } + if ($(subErrorIcon).hasClass("hidden")) { + $(subErrorIcon).removeClass("hidden"); + } + } + } else { + if (validationStatus["okFeature"]) { + subErrorMsgWrapper = "#" + validationStatus["okFeature"] + "-feature-error-msg"; + subErrorIcon = "#" + validationStatus["okFeature"] + "-error"; + subOkIcon = "#" + validationStatus["okFeature"] + "-ok"; + featureConfiguredIcon = "#" + validationStatus["okFeature"] + "-configured"; + // hiding featureConfiguredState as the first step + if (!$(featureConfiguredIcon).hasClass("hidden")) { + $(featureConfiguredIcon).addClass("hidden"); + } + // updating success state and corresponding messages + if (!$(subErrorMsgWrapper).hasClass("hidden")) { + $(subErrorMsgWrapper).addClass("hidden"); + } + if (!$(subErrorIcon).hasClass("hidden")) { + $(subErrorIcon).addClass("hidden"); + } + if ($(subOkIcon).hasClass("hidden")) { + $(subOkIcon).removeClass("hidden"); + } + } + } + } + + wizardIsToBeContinued = (errorCount == 0); + return wizardIsToBeContinued; +}; + +stepForwardFrom["policy-profile"] = function () { + policy["profile"] = operationModule.generateProfile(policy["platform"], configuredOperations); + // updating next-page wizard title with selected platform + $("#policy-criteria-page-wizard-title").text(policy["platform"] + " POLICY - " + policy["name"]); +}; + +stepForwardFrom["policy-criteria"] = function () { + $("input[type='radio'].select-users-radio").each(function () { + if ($(this).is(':radio')) { + if ($(this).is(":checked")) { + if ($(this).attr("id") == "users-radio-btn") { + policy["selectedUsers"] = $("#users-input").val(); + } else if ($(this).attr("id") == "user-roles-radio-btn") { + policy["selectedUserRoles"] = $("#user-roles-input").val(); + } + } + } + }); + policy["selectedNonCompliantAction"] = $("#action-input").find(":selected").data("action"); + policy["selectedOwnership"] = $("#ownership-input").val(); + // updating next-page wizard title with selected platform + $("#policy-naming-page-wizard-title").text(policy["platform"] + " POLICY - " + policy["name"]); +}; + +/** + * Checks if provided input is valid against provided length range. + * + * @param input Alphanumeric or non-alphanumeric input + * @param minLength Minimum Required Length + * @param maxLength Maximum Required Length + * @returns {boolean} Returns true if input matches the provided minimum length and maximum length + */ +var inputIsValidAgainstLength = function (input, minLength, maxLength) { + var length = input.length; + return (length == minLength || (length > minLength && length < maxLength) || length == maxLength); +}; + +validateStep["policy-naming"] = function () { + var validationStatus = {}; + + // taking values of inputs to be validated + var policyName = $("input#policy-name-input").val(); + // starting validation process and updating validationStatus + if (!policyName) { + validationStatus["error"] = true; + validationStatus["mainErrorMsg"] = "Policy name is empty. You cannot proceed."; + } else if (!inputIsValidAgainstLength(policyName, 1, 30)) { + validationStatus["error"] = true; + validationStatus["mainErrorMsg"] = + "Policy name exceeds maximum allowed length."; + } else { + validationStatus["error"] = false; + } + // ending validation process + + // start taking specific actions upon validation + var wizardIsToBeContinued; + if (validationStatus["error"]) { + wizardIsToBeContinued = false; + var mainErrorMsgWrapper = "#policy-naming-main-error-msg"; + var mainErrorMsg = mainErrorMsgWrapper + " span"; + $(mainErrorMsg).text(validationStatus["mainErrorMsg"]); + $(mainErrorMsgWrapper).removeClass("hidden"); + } else { + wizardIsToBeContinued = true; + } + + return wizardIsToBeContinued; +}; + +validateStep["policy-naming-publish"] = function () { + var validationStatus = {}; + + // taking values of inputs to be validated + var policyName = $("input#policy-name-input").val(); + // starting validation process and updating validationStatus + if (!policyName) { + validationStatus["error"] = true; + validationStatus["mainErrorMsg"] = "Policy name is empty. You cannot proceed."; + } else if (!inputIsValidAgainstLength(policyName, 1, 30)) { + validationStatus["error"] = true; + validationStatus["mainErrorMsg"] = + "Policy name exceeds maximum allowed length."; + } else { + validationStatus["error"] = false; + } + // ending validation process + + // start taking specific actions upon validation + var wizardIsToBeContinued; + if (validationStatus["error"]) { + wizardIsToBeContinued = false; + var mainErrorMsgWrapper = "#policy-naming-main-error-msg"; + var mainErrorMsg = mainErrorMsgWrapper + " span"; + $(mainErrorMsg).text(validationStatus["mainErrorMsg"]); + $(mainErrorMsgWrapper).removeClass("hidden"); + } else { + wizardIsToBeContinued = true; + } + + return wizardIsToBeContinued; +}; + +stepForwardFrom["policy-naming-publish"] = function () { + policy["policyName"] = $("#policy-name-input").val(); + policy["description"] = $("#policy-description-input").val(); + //All data is collected. Policy can now be updated. + updatePolicy(policy, "publish"); +}; +stepForwardFrom["policy-naming"] = function () { + policy["policyName"] = $("#policy-name-input").val(); + policy["description"] = $("#policy-description-input").val(); + //All data is collected. Policy can now be updated. + updatePolicy(policy, "save"); +}; + +var updatePolicy = function (policy, state) { + var profilePayloads = []; + // traverses key by key in policy["profile"] + var key; + for (key in policy["profile"]) { + if (policy["profile"].hasOwnProperty(key)) { + profilePayloads.push({ + "featureCode": key, + "deviceType": policy["platform"], + "content": policy["profile"][key] + }); + } + } + var payload = { + "policyName": policy["policyName"], + "description": policy["description"], + "compliance": policy["selectedNonCompliantAction"], + "ownershipType": policy["selectedOwnership"], + "profile": { + "profileName": policy["policyName"], + "deviceType": policy["platform"], + "profileFeaturesList": profilePayloads + } + }; + + if (policy["selectedUsers"]) { + payload["users"] = policy["selectedUsers"]; + } else if (policy["selectedUserRoles"]) { + payload["roles"] = policy["selectedUserRoles"]; + } else { + 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"); + invokerUtil.put( + serviceURL, + payload, + // on success + function () { + if (state == "save") { + var policyList = []; + policyList.push(getParameterByName("id")); + serviceURL = baseApiUrl + "/policies/deactivate-policy"; + invokerUtil.post( + serviceURL, + policyList, + // on success + function () { + $(".policy-message").removeClass("hidden"); + $(".add-policy").addClass("hidden"); + }, + // on error + function (data) { + console.log(data); + } + ); + } else if (state == "publish") { + var policyList = []; + policyList.push(getParameterByName("id")); + serviceURL = baseApiUrl + "/policies/activate-policy"; + invokerUtil.post( + serviceURL, + policyList, + // on success + function () { + $(".policy-message").removeClass("hidden"); + $(".add-policy").addClass("hidden"); + }, + // on error + function (data) { + console.log(data); + } + ); + } + }, + // on error + function (data) { + console.log(data); + } + ); +}; + +// Start of HTML embedded invoke methods +var showAdvanceOperation = function (operation, button) { + $(button).addClass('selected'); + $(button).siblings().removeClass('selected'); + var hiddenOperation = ".wr-hidden-operations-content > div"; + $(hiddenOperation + '[data-operation="' + operation + '"]').show(); + $(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide(); +}; + +/** + * Method to slide down a provided pane upon provided value set. + * + * @param selectElement Select HTML Element to consider + * @param paneID HTML ID of div element to slide down + * @param valueSet Applicable Value Set + */ +var slideDownPaneAgainstValueSet = function (selectElement, paneID, valueSet) { + var selectedValueOnChange = $(selectElement).find("option:selected").val(); + if ($(selectElement).is("input:checkbox")) { + selectedValueOnChange = $(selectElement).is(":checked").toString(); + } + + var i, slideDownVotes = 0; + for (i = 0; i < valueSet.length; i++) { + if (selectedValueOnChange == valueSet[i]) { + slideDownVotes++; + } + } + var paneSelector = "#" + paneID; + if (slideDownVotes > 0) { + if (!$(paneSelector).hasClass("expanded")) { + $(paneSelector).addClass("expanded"); + } + $(paneSelector).slideDown(); + } else { + if ($(paneSelector).hasClass("expanded")) { + $(paneSelector).removeClass("expanded"); + } + $(paneSelector).slideUp(); + /* now follows the code to reinitialize all inputs of the slidable pane. + reinitializing input fields into the defaults.*/ + $(paneSelector + " input").each( + function () { + if ($(this).is("input:text")) { + $(this).val($(this).data("default")); + } else if ($(this).is("input:password")) { + $(this).val(""); + } else if ($(this).is("input:checkbox")) { + $(this).prop("checked", $(this).data("default")); + // if this checkbox is the parent input of a grouped-input + if ($(this).hasClass("parent-input")) { + var groupedInput = $(this).parent().parent().parent(); + updateGroupedInputVisibility(groupedInput); + } + } + } + ); + // reinitializing select fields into the defaults + $(paneSelector + " select").each( + function () { + var defaultOption = $(this).data("default"); + $("option:eq(" + defaultOption + ")", this).prop("selected", "selected"); + } + ); + // collapsing expanded-panes (upon the selection of html-select-options) if any + $(paneSelector + " .expanded").each( + function () { + if ($(this).hasClass("expanded")) { + $(this).removeClass("expanded"); + } + $(this).slideUp(); + } + ); + // removing all entries of grid-input elements if exist + $(paneSelector + " .grouped-array-input").each( + function () { + var gridInputs = $(this).find("[data-add-form-clone]"); + if (gridInputs.length > 0) { + gridInputs.remove(); + } + var helpTexts = $(this).find("[data-help-text=add-form]"); + if (helpTexts.length > 0) { + helpTexts.show(); + } + } + ); + } +}; + +var slideDownPaneAgainstValueSetForRadioButtons = function (selectElement, paneID, valueSet) { + var selectedValueOnChange = selectElement.value; + + var i, slideDownVotes = 0; + for (i = 0; i < valueSet.length; i++) { + if (selectedValueOnChange == valueSet[i]) { + slideDownVotes++; + } + } + + var paneSelector = "#" + paneID; + if(slideDownVotes > 0) { + $(paneSelector).removeClass("hidden"); + } else { + $(paneSelector).addClass("hidden"); + } +}; +// End of HTML embedded invoke methods + + +// Start of functions related to grid-input-view + +/** + * Method to set count id to cloned elements. + * @param {object} addFormContainer + */ +var setId = function (addFormContainer) { + $(addFormContainer).find("[data-add-form-clone]").each(function (i) { + $(this).attr("id", $(this).attr("data-add-form-clone").slice(1) + "-" + (i + 1)); + if ($(this).find(".index").length > 0) { + $(this).find(".index").html(i + 1); + } + }); +}; + +/** + * Method to set count id to cloned elements. + * @param {object} addFormContainer + */ +var showHideHelpText = function (addFormContainer) { + var helpText = "[data-help-text=add-form]"; + if ($(addFormContainer).find("[data-add-form-clone]").length > 0) { + $(addFormContainer).find(helpText).hide(); + } else { + $(addFormContainer).find(helpText).show(); + } +}; + +/** + * This method will display appropriate fields based on wifi type + * @param {object} wifi type select object + */ +var changeAndroidWifiPolicy = function (select) { + slideDownPaneAgainstValueSet(select, 'control-wifi-password', ['wep', 'wpa', '802eap']); + slideDownPaneAgainstValueSet(select, 'control-wifi-eap', ['802eap']); + slideDownPaneAgainstValueSet(select, 'control-wifi-phase2', ['802eap']); + slideDownPaneAgainstValueSet(select, 'control-wifi-identity', ['802eap']); + slideDownPaneAgainstValueSet(select, 'control-wifi-anoidentity', ['802eap']); + slideDownPaneAgainstValueSet(select, 'control-wifi-cacert', ['802eap']); +}; + +/** + * This method will display appropriate fields based on wifi EAP type + * @param {object} wifi eap select object + * @param {object} wifi type select object + */ +var changeAndroidWifiPolicyEAP = function (select, superSelect) { + slideDownPaneAgainstValueSet(select, 'control-wifi-password', ['peap', 'ttls', 'pwd' , 'fast', 'leap']); + slideDownPaneAgainstValueSet(select, 'control-wifi-phase2', ['peap', 'ttls', 'fast']); + slideDownPaneAgainstValueSet(select, 'control-wifi-provisioning', ['fast']); + slideDownPaneAgainstValueSet(select, 'control-wifi-identity', ['peap', 'tls', 'ttls', 'pwd', 'fast', 'leap']); + slideDownPaneAgainstValueSet(select, 'control-wifi-anoidentity', ['peap', 'ttls']); + slideDownPaneAgainstValueSet(select, 'control-wifi-cacert', ['peap', 'tls', 'ttls']); + if (superSelect.value != '802eap') { + changeAndroidWifiPolicy(superSelect); + } +}; + +// End of functions related to grid-input-view + +/** + * This method will return query parameter value given its name. + * @param name Query parameter name + * @returns {string} Query parameter value + */ +var getParameterByName = function (name) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), + results = regex.exec(location.search); + return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); +}; + +$(document).ready(function () { + $('#appbar-btn-apply-changes').addClass('hidden'); + // Adding initial state of wizard-steps. + $("#policy-profile-wizard-steps").html($(".wr-steps").html()); + + var policyPayloadObj; + invokerUtil.get( + // baseApiUrl + "/policies/" + getParameterByName("id"), + + + baseApiUrl + "/policies/effective-policy/" + getParameterByName("type") + "/" + getParameterByName("id"), + // on success + function (data, textStatus, jqXHR) { + if (jqXHR.status == 200 && data) { + policyPayloadObj = JSON.parse(data); + skipStep["policy-platform"](policyPayloadObj); + } + }, + // on error + function (jqXHR) { + console.log(jqXHR); + // should be redirected to an error page + } + ); + + $("select.select2[multiple=multiple]").select2({ + "tags": true + }); + + $("#users-select-field").hide(); + $("#user-roles-select-field").show(); + + $("input[type='radio'].select-users-radio").change(function () { + if ($("#users-radio-btn").is(":checked")) { + $("#user-roles-select-field").hide(); + $("#users-select-field").show(); + } + if ($("#user-roles-radio-btn").is(":checked")) { + $("#users-select-field").hide(); + $("#user-roles-select-field").show(); + } + }); + + // Support for special input type "ANY" on user(s) & user-role(s) selection + $("#users-input, #user-roles-input").select2({ + "tags": true + }).on("select2:select", function (e) { + if (e.params.data.id == "ANY") { + $(this).val("ANY").trigger("change"); + } else { + $("option[value=ANY]", this).prop("selected", false).parent().trigger("change"); + } + }); + + // Maintains an array of configured features of the profile + var advanceOperations = ".wr-advance-operations"; + $(advanceOperations).on("click", ".wr-input-control.switch", function (event) { + var operationCode = $(this).parents(".operation-data").data("operation-code"); + var operation = $(this).parents(".operation-data").data("operation"); + var operationDataWrapper = $(this).data("target"); + // prevents event bubbling by figuring out what element it's being called from. + if (event.target.tagName == "INPUT") { + var featureConfiguredIcon; + if ($("input[type='checkbox']", this).is(":checked")) { + configuredOperations.push(operationCode); + // when a feature is enabled, if "zero-configured-features" msg is available, hide that. + var zeroConfiguredOperationsErrorMsg = "#policy-profile-main-error-msg"; + if (!$(zeroConfiguredOperationsErrorMsg).hasClass("hidden")) { + $(zeroConfiguredOperationsErrorMsg).addClass("hidden"); + } + // add configured-state-icon to the feature + featureConfiguredIcon = "#" + operation + "-configured"; + if ($(featureConfiguredIcon).hasClass("hidden")) { + $(featureConfiguredIcon).removeClass("hidden"); + } + } else { + //splicing the array if operation is present. + var index = $.inArray(operationCode, configuredOperations); + if (index != -1) { + configuredOperations.splice(index, 1); + } + // when a feature is disabled, clearing all its current configured, error or success states + var subErrorMsgWrapper = "#" + operation + "-feature-error-msg"; + var subErrorIcon = "#" + operation + "-error"; + var subOkIcon = "#" + operation + "-ok"; + featureConfiguredIcon = "#" + operation + "-configured"; + + if (!$(subErrorMsgWrapper).hasClass("hidden")) { + $(subErrorMsgWrapper).addClass("hidden"); + } + if (!$(subErrorIcon).hasClass("hidden")) { + $(subErrorIcon).addClass("hidden"); + } + if (!$(subOkIcon).hasClass("hidden")) { + $(subOkIcon).addClass("hidden"); + } + if (!$(featureConfiguredIcon).hasClass("hidden")) { + $(featureConfiguredIcon).addClass("hidden"); + } + // reinitializing input fields into the defaults + $(operationDataWrapper + " input").each( + function () { + if ($(this).is("input:text")) { + $(this).val($(this).data("default")); + } else if ($(this).is("input:password")) { + $(this).val(""); + } else if ($(this).is("input:checkbox")) { + $(this).prop("checked", $(this).data("default")); + // if this checkbox is the parent input of a grouped-input + if ($(this).hasClass("parent-input")) { + var groupedInput = $(this).parent().parent().parent(); + updateGroupedInputVisibility(groupedInput); + } + } + } + ); + // reinitializing select fields into the defaults + $(operationDataWrapper + " select").each( + function () { + var defaultOption = $(this).data("default"); + $("option:eq(" + defaultOption + ")", this).prop("selected", "selected"); + } + ); + // collapsing expanded-panes (upon the selection of html-select-options) if any + $(operationDataWrapper + " .expanded").each( + function () { + if ($(this).hasClass("expanded")) { + $(this).removeClass("expanded"); + } + $(this).slideUp(); + } + ); + // removing all entries of grid-input elements if exist + $(operationDataWrapper + " .grouped-array-input").each( + function () { + var gridInputs = $(this).find("[data-add-form-clone]"); + if (gridInputs.length > 0) { + gridInputs.remove(); + } + var helpTexts = $(this).find("[data-help-text=add-form]"); + if (helpTexts.length > 0) { + helpTexts.show(); + } + } + ); + } + } + }); + + // adding support for cloning multiple profiles per feature with cloneable class definitions + $(advanceOperations).on("click", ".multi-view.add.enabled", function () { + // get a copy of .cloneable and create new .cloned div element + var cloned = "

    " + $(".cloneable", $(this).parent().parent()).html() + "
    "; + // append newly created .cloned div element to panel-body + $(this).parent().parent().append(cloned); + // enable remove action of newly cloned div element + $(".cloned", $(this).parent().parent()).each( + function () { + if ($(".multi-view.remove", this).hasClass("disabled")) { + $(".multi-view.remove", this).removeClass("disabled"); + } + if (!$(".multi-view.remove", this).hasClass("enabled")) { + $(".multi-view.remove", this).addClass("enabled"); + } + } + ); + }); + + $(advanceOperations).on("click", ".multi-view.remove.enabled", function () { + $(this).parent().remove(); + }); + + // enabling or disabling grouped-input based on the status of a parent check-box + $(advanceOperations).on("click", ".grouped-input", function () { + updateGroupedInputVisibility(this); + }); + + // add form entry click function for grid inputs + $(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")); + + // adding class .child-input to capture text-input-array-values + $("input, select", clonedForm).addClass("child-input"); + + $(addFormContainer).append(clonedForm); + setId(addFormContainer); + showHideHelpText(addFormContainer); + }); + + // remove form entry click function for grid inputs + $(advanceOperations).on("click", "[data-click-event=remove-form]", function () { + var addFormContainer = $("[data-add-form-container=" + $(this).attr("href") + "]"); + + $(this).closest("[data-add-form-element=clone]").remove(); + setId(addFormContainer); + showHideHelpText(addFormContainer); + }); + + $(".wizard-stepper").click(function () { + // button clicked here can be either a continue button or a back button. + var currentStep = $(this).data("current"); + var validationIsRequired = $(this).data("validate"); + var wizardIsToBeContinued; + + if (validationIsRequired) { + wizardIsToBeContinued = validateStep[currentStep](); + } else { + wizardIsToBeContinued = true; + } + + if (wizardIsToBeContinued) { + // When moving back and forth, following code segment will + // remove if there are any visible error-messages. + var errorMsgWrappers = ".alert.alert-danger"; + $(errorMsgWrappers).each( + function () { + if (!$(this).hasClass("hidden")) { + $(this).addClass("hidden"); + } + } + ); + + var nextStep = $(this).data("next"); + var isBackBtn = $(this).data("is-back-btn"); + + // if current button is a continuation... + if (!isBackBtn) { + // initiate stepForwardFrom[*] functions to gather form data. + if (stepForwardFrom[currentStep]) { + stepForwardFrom[currentStep](this); + } + } else { + // initiate stepBackFrom[*] functions to rollback. + if (stepBackFrom[currentStep]) { + stepBackFrom[currentStep](); + } + } + + // following step occurs only at the last stage of the wizard. + if (!nextStep) { + window.location.href = $(this).data("direct"); + } + + // updating next wizard step as current. + $(".itm-wiz").each(function () { + var step = $(this).data("step"); + if (step == nextStep) { + $(this).addClass("itm-wiz-current"); + } else { + $(this).removeClass("itm-wiz-current"); + } + }); + + // adding next update of wizard-steps. + $("#" + nextStep + "-wizard-steps").html($(".wr-steps").html()); + + // hiding current section of the wizard and showing next section. + $("." + currentStep).addClass("hidden"); + $("." + nextStep).removeClass("hidden"); + } + }); +}); 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/templates/hidden-operations-android.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-android.hbs new file mode 100644 index 0000000000..2017870949 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-android.hbs @@ -0,0 +1,1493 @@ +
    + + +
    + +
    +
    + +
    +
    + + +
    + +
    + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    +
    +
    +
    + + + +
    +
    + +
    +
    + +
    +
    + +
    + +
    +
    + Bellow restrictions will be applied on devices with Android version 5.0 Lollipop onwards only + +

    +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    +
    + Bellow restrictions will be applied on devices with Android version 6.0 Marshmallow onwards only. + +

    +
    + +
    +
    +
    +
    +
    + + + +
    +
    + +
    +
    + + Un-check following checkbox in case you do not need the device to be encrypted. +
    +
    +
    + +
    +
    +
    +
    +
    + + + +
    +
    + +
    +
    + + + + + + + + + + + + + + + + + Please note that * sign represents required fields of data. +
    +
    + +
    + + +
    +
    + + +
    + + + + + + + + +
    +
    +
    + + +
    +
    + +
    +
    + + + +
    +
    + +
    + +
    + + + + + + + + + + + + + + +
    No:Application Name/DescriptionPackage Name
    + No entries added yet . +
    + + + + + + + + + + +
    +
    +
    +
    +
    + + + +
    +
    + +
    +
    + Please note that * sign represents required fields of data. +
    +
    + +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + +
    +
    + + + +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    +
    +
    + + +
    +
    + + +
    + + + +
    + +

    + + + +
    + + + +
    +
    +
    + + +
    +
    + + +
    + + + +
    + +
    + + + + + + + + + + + + + + +
    No:Application Name / DescriptionPackage Name
    + No entries added yet . +
    + + + + + + + + + + +
    +
    +
    +
    +
    +
    +
    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/templates/hidden-operations-ios.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-ios.hbs new file mode 100644 index 0000000000..37a776b6f8 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-ios.hbs @@ -0,0 +1,4728 @@ +
    + + +
    + +
    +
    + +
    + + + +
    + +
    + +
    + +
    + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    +
    +
    +
    + + + +
    +
    + +
    +
    +Please note that * sign represents required fields of data. +
    +
    + + +
    + + +
    +
    + +
    +
    + +
    + +
    + +
    + + + + + + + + + + + + + + +
    No:KeyValue
    + No entries added yet . +
    + + + + + + + + + + +
    +
    +
    + + +
    + + + + +
    +
    +
    + + + +
    +
    + +
    +
    + Please note that * sign represents required fields of data. +
    +
    + + +
    + + +
    +
    + +
    +
    + + +
    + + + + + + + + + + + + + +
    No:Safari Domain
    + No entries added yet . +
    + + + + + + + + + + +
    +
    +
    +
    +
    + +
    + Please note that * sign represents required fields of data. +
    +
    + + +
    + + +
    + + + + + + + + + + + + + + +
    No:App IdentifierVPN UUID
    + No entries added yet . +
    + + + + + + + + + + +
    +
    +
    +
    +
    + + + +
    +
    + +
    +
    + + + +
    + +
    + + +
    + + + + + + + + + + + + + + +
    No:Application Name/DescriptionPackage Name
    + No entries added yet . +
    + + + + + + + + + + +
    +
    +
    +
    +
    + + + +
    +
    + +
    +
    + + +
    + + +
    + +
    + + +
    + +
    + +
    + +
    + +
    + +
    + +
    + +
    + +
    + +
    + + +
    + +
    + + +
    + + + +
    + + +
    + + + +
    + + +
    + + + + + + + + + + + + + +
    No:Roaming Consortium OI
    + No entries added yet . +
    + + + + + + + + + +
    +
    + +
    + +
    + + +
    + + + + + + + + + + + + + +
    No:NAI Realm Name
    + No entries added yet . +
    + + + + + + + + + +
    +
    + +
    + +
    + + +
    + + + + + + + + + + + + + + +
    No:Mobile Country Code ( MCC )Mobile Network Code ( MNC )
    + No entries added yet . +
    + + + + + + + + + + +
    +
    +
    +
    +
    + + + +
    +
    + +
    +
    + + +
    + + +
    + +
    + + +
    + +
    + +
    + + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    + +
    + +
    + +
    + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    + +
    + +
    + +
    + +
    +Incoming Mail Settings : +
    + +
    + + +
    + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    +Outgoing Mail Settings : +
    + +
    + + +
    + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + +
    + +
    + + +
    + +
    +
    +
    + + + +
    +
    + +
    +
    + + +
    + + +
    + + + + + + + + + + + + + + +
    No:Device NamePassword
    + No entries added yet . +
    + + + + + + + + + + +
    +
    + +
    + +
    + + +
    + + + + + + + + + + + + + +
    No:Destination
    + No entries added yet . +
    + + + + + + + + + +
    +
    + +
    +
    +
    + + + +
    +
    + +
    +
    + + +
    + + +
    + +
    + + +
    + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + + + + + + + + + + + + + + + +
    No:DescriptionSearch BaseScope
    + No entries added yet . +
    + + + + + + + + + + + +
    +
    + +
    +
    +
    + + + +
    +
    + +
    +
    + + +
    + + +
    + +
    + + +
    + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    +
    +
    + + + +
    +
    + +
    +
    + + +
    + + +
    + +
    + + +
    + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    +
    +
    + + + +
    +
    + +
    +
    + + +
    + + +
    + + + + + + + + + + + + + + + + + +
    No:APNUsernamePasswordProxyPort
    + No entries added yet . +
    + + + + + + + + + + + + + +
    +
    + +
    +
    +
    + + + +
    +
    + +
    +
    + + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + + + + + + + + + + + + + + + + + + +
    No:APNAuth.TypeUsernamePasswordProxyPort
    + No entries added yet . +
    + + + + + + + + + + + + + + +
    +
    + +
    +
    +
    + + + +
    +
    + +
    +
    + + +Restrictions on Device Functionality : +
    +
    +
      +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
        +
      • +
        + +
        +
      • +
      • +
        + +
        +
      • +
      • +
        + +
        +
      • +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    +
    +
    +Restrictions on Applications : +
    +
    +
      +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
        +
      • +
        + +
        +
      • +
      • +
        + +
        +
      • +
      • +
        + +
        +
      • +
      • +
        + +
        +
      • +
      • +
        + + +
        +
      • +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    • +
      + +
      +
    • +
    +
    + + + +
    +
    +
    + +
    +
    \ No newline at end of file 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/templates/hidden-operations-windows.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-windows.hbs new file mode 100644 index 0000000000..c05725b89d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-windows.hbs @@ -0,0 +1,566 @@ +
    + + +
    + +
    +
    + +
    +
    + + +
    + +
    + +
    + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    +
    +
    +
    + + + +
    +
    + +
    +
    + + Un-check following checkbox in case you need to disable camera. +
    +
    +
    + +
    +
    +
    +
    +
    + + + +
    +
    + +
    +
    + + Un-check following checkbox in case you need to disable storage-encryption. +
    +
    +
    + +
    +
    +
    +
    +
    + + + +
    +
    + +
    +
    + + + +
    +
    + +
    + + + + + + + + + + + + + + +
    No:Application Name/DescriptionPackage Name
    + No entries added yet . +
    + + + + + + + + + + +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.hbs new file mode 100644 index 0000000000..b7f2adf56d --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.hbs @@ -0,0 +1,88 @@ +{{#zone "content"}} + {{#defineZone "policy-profile-top"}} +
    +
    + +
    +
    + {{/defineZone}} + + +
    +
    +
    +
    +
    + Policy Overview +
    + {{#defineZone "policy-detail-properties"}} + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Platform
    Ownership
    Action upon non-compliance
    Status
    Assigned Users
    Assigned Roles
    + {{/defineZone}} +
    Description
    +
    +
    +
    +
    +
    + Profile Information +
    +
    + +
    +
    +
    + + Loading platform features . . . +
    +
    +
    +
    +
    +
    +
    +
    +
    +{{/zone}} +{{#zone "bottomJs"}} + + + + + + + {{js "js/view.js"}} +{{/zone}} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.js new file mode 100644 index 0000000000..2d2a438263 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.js @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +function onRequest(context) { +// var log = new Log("policy-view-edit-unit backend js"); + +// var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; +// context.roles = userModule.getRoles(); + return context; +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.json new file mode 100644 index 0000000000..f706ffceea --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.json @@ -0,0 +1,3 @@ +{ + "version" : "1.0.0" +} \ No newline at end of file From 652d77667291176fc9cf5d3b46e4207cf453a46d Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 8 Nov 2016 11:00:00 +0530 Subject: [PATCH 07/22] Adding effective policy details --- .../pom.xml | 1 + .../decision/point/SimpleEvaluationPoint.java | 23 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml index 4690ad5c49..79ffd12b1e 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml @@ -35,6 +35,7 @@ Simple Policy Decision Point Bundle org.wso2.carbon.simple.policy.decision.point.internal + org.wso2.carbon.context.*; org.osgi.framework, org.osgi.service.component, org.apache.commons.logging, diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java index 137d95c3aa..3c5e8b3275 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java +++ b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java @@ -20,24 +20,21 @@ package org.wso2.carbon.simple.policy.decision.point; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.*; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.simple.policy.decision.point.internal.PolicyDecisionPointDataHolder; +import java.sql.Timestamp; import java.util.*; public class SimpleEvaluationPoint implements PolicyEvaluationPoint { private static final Log log = LogFactory.getLog(SimpleEvaluationPoint.class); - //TODO : to revove the stale reference private PolicyManagerService policyManagerService; private List policyList; PIPDevice pipDevice; -// public SimpleEvaluationPoint() { -// policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); -// } - @Override public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { @@ -88,6 +85,21 @@ public class SimpleEvaluationPoint implements PolicyEvaluationPoint { Profile profile = new Profile(); profile.setProfileFeaturesList(getEffectiveFeatures(deviceIdentifier)); 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.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()); return policy; } catch (PolicyManagementException e) { String msg = "Error occurred when retrieving the policy related data from policy management service."; @@ -126,7 +138,6 @@ public class SimpleEvaluationPoint implements PolicyEvaluationPoint { } public void sortPolicies() throws PolicyEvaluationException { - //Collections.sort(policyList); Collections.sort(policyList, Collections.reverseOrder()); } From 367fa927b0da1bc0b805e9056d8a49adf989eda2 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 8 Nov 2016 13:05:02 +0530 Subject: [PATCH 08/22] Changed policy decision point package structure --- .../pom.xml | 12 ++++++------ .../internal/PolicyDecisionPointDataHolder.java | 2 +- .../internal/PolicyEvaluationServiceComponent.java | 6 +++--- .../point/merged/MergedEvaluationPoint.java} | 8 ++++---- components/policy-mgt/pom.xml | 2 +- .../pom.xml | 4 ++-- pom.xml | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) rename components/policy-mgt/{org.wso2.carbon.simple.policy.decision.point => org.wso2.carbon.policy.decision.point}/pom.xml (85%) rename components/policy-mgt/{org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple => org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon}/policy/decision/point/internal/PolicyDecisionPointDataHolder.java (96%) rename components/policy-mgt/{org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple => org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon}/policy/decision/point/internal/PolicyEvaluationServiceComponent.java (95%) rename components/policy-mgt/{org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java => org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java} (95%) diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml similarity index 85% rename from components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml rename to components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml index 79ffd12b1e..809f31731d 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml @@ -9,11 +9,11 @@ 4.0.0 org.wso2.carbon.devicemgt - org.wso2.carbon.simple.policy.decision.point + org.wso2.carbon.policy.decision.point 2.0.4-SNAPSHOT bundle - WSO2 Carbon - Simple Policy Decision Point - WSO2 Carbon - Simple Policy Decision Point + WSO2 Carbon - Policy Decision Point + WSO2 Carbon - Policy Decision Point http://wso2.org @@ -32,8 +32,8 @@ ${project.artifactId} ${project.artifactId} ${carbon.device.mgt.version} - Simple Policy Decision Point Bundle - org.wso2.carbon.simple.policy.decision.point.internal + Policy Decision Point Bundle + org.wso2.carbon.policy.decision.point.internal org.wso2.carbon.context.*; org.osgi.framework, @@ -45,7 +45,7 @@ org.wso2.carbon.device.mgt.common.* - org.wso2.carbon.simple.policy.decision.point.* + org.wso2.carbon.policy.decision.point.* diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyDecisionPointDataHolder.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyDecisionPointDataHolder.java similarity index 96% rename from components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyDecisionPointDataHolder.java rename to components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyDecisionPointDataHolder.java index 7b5d104ea1..41909fbd49 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyDecisionPointDataHolder.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyDecisionPointDataHolder.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.simple.policy.decision.point.internal; +package org.wso2.carbon.policy.decision.point.internal; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.user.core.service.RealmService; diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyEvaluationServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java similarity index 95% rename from components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyEvaluationServiceComponent.java rename to components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java index 74dcca1eec..1ede6cb522 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyEvaluationServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java @@ -16,14 +16,14 @@ * under the License. */ -package org.wso2.carbon.simple.policy.decision.point.internal; +package org.wso2.carbon.policy.decision.point.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; -import org.wso2.carbon.simple.policy.decision.point.SimpleEvaluationPoint; import org.wso2.carbon.user.core.service.RealmService; /** @@ -54,7 +54,7 @@ public class PolicyEvaluationServiceComponent { try { //TODO: fetch PEP class from config componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(), - new SimpleEvaluationPoint(), null); + new MergedEvaluationPoint(), null); } catch (Throwable t) { log.error("Error occurred while initializing the simple policy evaluation bundle"); } diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java similarity index 95% rename from components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java rename to components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java index 3c5e8b3275..b56c459992 100644 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationPoint.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/merged/MergedEvaluationPoint.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.simple.policy.decision.point; +package org.wso2.carbon.policy.decision.point.merged; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -24,14 +24,14 @@ import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.policy.mgt.common.*; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; -import org.wso2.carbon.simple.policy.decision.point.internal.PolicyDecisionPointDataHolder; +import org.wso2.carbon.policy.decision.point.internal.PolicyDecisionPointDataHolder; import java.sql.Timestamp; import java.util.*; -public class SimpleEvaluationPoint implements PolicyEvaluationPoint { +public class MergedEvaluationPoint implements PolicyEvaluationPoint { - private static final Log log = LogFactory.getLog(SimpleEvaluationPoint.class); + private static final Log log = LogFactory.getLog(MergedEvaluationPoint.class); private PolicyManagerService policyManagerService; private List policyList; PIPDevice pipDevice; diff --git a/components/policy-mgt/pom.xml b/components/policy-mgt/pom.xml index 97d2d59b09..e7451e8627 100644 --- a/components/policy-mgt/pom.xml +++ b/components/policy-mgt/pom.xml @@ -38,7 +38,7 @@ org.wso2.carbon.policy.mgt.common org.wso2.carbon.policy.mgt.core org.wso2.carbon.policy.information.point - org.wso2.carbon.simple.policy.decision.point + org.wso2.carbon.policy.decision.point org.wso2.carbon.complex.policy.decision.point diff --git a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml index 2c140da41f..8740cff8d6 100644 --- a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml +++ b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml @@ -47,7 +47,7 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.simple.policy.decision.point + org.wso2.carbon.policy.decision.point org.wso2.carbon.devicemgt @@ -118,7 +118,7 @@ org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.common:${carbon.device.mgt.version} - org.wso2.carbon.devicemgt:org.wso2.carbon.simple.policy.decision.point:${carbon.device.mgt.version} + org.wso2.carbon.devicemgt:org.wso2.carbon.policy.decision.point:${carbon.device.mgt.version} org.wso2.carbon.devicemgt:org.wso2.carbon.policy.information.point:${carbon.device.mgt.version} diff --git a/pom.xml b/pom.xml index cb38b4867c..2f3b5f5c42 100644 --- a/pom.xml +++ b/pom.xml @@ -195,7 +195,7 @@ org.wso2.carbon.devicemgt - org.wso2.carbon.simple.policy.decision.point + org.wso2.carbon.policy.decision.point ${carbon.device.mgt.version} From 272ba7b012633a422a3a63d59971984cf1267481 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 8 Nov 2016 14:01:32 +0530 Subject: [PATCH 09/22] Changed getEffectiveFeatures method --- .../point/merged/MergedEvaluationPoint.java | 25 +++++++++++-------- .../mgt/common/PolicyEvaluationPoint.java | 2 +- .../policy/mgt/core/PolicyManagerService.java | 2 +- .../mgt/core/PolicyManagerServiceImpl.java | 11 +++++--- .../services/SimplePolicyEvaluationTest.java | 2 +- 5 files changed, 26 insertions(+), 16 deletions(-) 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 b56c459992..88b9a36ad4 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 @@ -37,24 +37,16 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { PIPDevice pipDevice; @Override - public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + public List getEffectiveFeatures(List policyList, DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { PolicyAdministratorPoint policyAdministratorPoint; - PolicyInformationPoint policyInformationPoint; policyManagerService = getPolicyManagerService(); try { if (policyManagerService != null) { - policyInformationPoint = policyManagerService.getPIP(); - PIPDevice pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier); - policyList = policyInformationPoint.getRelatedPolicies(pipDevice); - if (!policyList.isEmpty()) { - //policy = policyList.get(0); - //policyList = new ArrayList(); Policy effectivePolicy = policyResolve(policyList); effectivePolicy.setActive(true); - //TODO : UNCOMMENT THE FOLLOWING CASE policyAdministratorPoint = policyManagerService.getPAP(); policyAdministratorPoint.setPolicyUsed(deviceIdentifier, effectivePolicy); return effectivePolicy.getProfile().getProfileFeaturesList(); @@ -83,7 +75,7 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { Policy policy = new Policy(); Profile profile = new Profile(); - profile.setProfileFeaturesList(getEffectiveFeatures(deviceIdentifier)); + profile.setProfileFeaturesList(getEffectiveFeatures(policyList, deviceIdentifier)); policy.setProfile(profile); Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime()); profile.setCreatedDate(currentTimestamp); @@ -113,6 +105,8 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { // 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(); @@ -124,6 +118,16 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { 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 @@ -133,6 +137,7 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { Policy effectivePolicy = new Policy(); effectivePolicy.setProfile(profile); + //effectivePolicy.setRoles(rolesList); return effectivePolicy; } 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 ef4f84988d..3fbf83ff9c 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 @@ -42,5 +42,5 @@ public interface PolicyEvaluationPoint { * @param deviceIdentifier device information. * @return returns the effective feature set. */ - List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; + List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java index 96d7aac4d2..c8bd6e1d2f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java @@ -51,7 +51,7 @@ public interface PolicyManagerService { Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; - List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException; + List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws FeatureManagementException; List getPolicies(String deviceType) throws PolicyManagementException; 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 89c244f55a..1cd88a72d0 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 @@ -133,11 +133,16 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { } @Override - public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws + public List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws FeatureManagementException { try { - return PolicyManagementDataHolder.getInstance(). - getPolicyEvaluationPoint().getEffectiveFeatures(deviceIdentifier); + PolicyEvaluationPoint policyEvaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); + if (policyEvaluationPoint != null) { + return policyEvaluationPoint.getEffectiveFeatures(policyList, deviceIdentifier); + } else { + throw new FeatureManagementException("Error occurred while getting the policy evaluation point " + + deviceIdentifier.getId() + " - " + deviceIdentifier.getType()); + } } catch (PolicyEvaluationException e) { String msg = "Error occurred while getting the effective features from the PEP service " + deviceIdentifier.getId() + " - " + deviceIdentifier.getType(); 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 b4bed5da4d..ee62eb3ad7 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 @@ -72,7 +72,7 @@ public class SimplePolicyEvaluationTest implements PolicyEvaluationPoint { } @Override - public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + public List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { return null; } From 936e71a7435f699e41d383bac1d9818449e1b353 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 8 Nov 2016 14:28:18 +0530 Subject: [PATCH 10/22] Adding configurations for different policy evaluation service components --- .../mgt/core/config/policy/PolicyConfiguration.java | 10 ++++++++++ .../carbon-home/repository/conf/cdm-config.xml | 2 ++ .../src/main/resources/conf/cdm-config.xml | 2 ++ 3 files changed, 14 insertions(+) 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 73d3517d83..56a5fe4cf2 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,6 +33,7 @@ public class PolicyConfiguration { private int minRetriesToMarkUnreachable; private int minRetriesToMarkInactive; private List platforms; + private String policyEvaluationPointName; @XmlElement(name = "MonitoringClass", required = true) public String getMonitoringClass() { @@ -98,4 +99,13 @@ public class PolicyConfiguration { this.platforms = platforms; } + @XmlElement(name = "PolicyEvaluationPointName", required = true) + public String getPolicyEvaluationPointName() { + return policyEvaluationPointName; + } + + public void setPolicyEvaluationPointName(String policyEvaluationPointName) { + this.policyEvaluationPointName = policyEvaluationPointName; + } + } 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 0f5861cc1d..559cc3edd5 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,6 +42,8 @@ 5 8 20 + + MergedPolicyEvaluationServiceComponent 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 1f76b3dacd..9e326a4f03 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,6 +43,8 @@ 5 8 20 + + MergedPolicyEvaluationServiceComponent android ios From 6565e14051bf7cdcebc27efb29dee3175c42e80f Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 8 Nov 2016 14:40:20 +0530 Subject: [PATCH 11/22] Adding simple policy evaluation decision point --- .../simple/PolicyEvaluationServiceImpl.java | 62 +++++++++++++ .../point/simple/SimpleEvaluation.java | 32 +++++++ .../point/simple/SimpleEvaluationImpl.java | 86 +++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluation.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluationImpl.java 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 new file mode 100644 index 0000000000..3b3727cff0 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.policy.decision.point.simple; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; +import org.wso2.carbon.policy.mgt.common.ProfileFeature; + +import java.util.List; + +public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { + + private SimpleEvaluationImpl evaluation; + + public PolicyEvaluationServiceImpl() { + evaluation = new SimpleEvaluationImpl(); + } + + @Override + public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + return evaluation.getEffectivePolicy(deviceIdentifier); + } + + @Override + public List getEffectiveFeatures(List policyList, DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + + List effectiveFeatures = evaluation.getEffectivePolicy(deviceIdentifier). + getProfile().getProfileFeaturesList(); + +/* PolicyOperation policyOperation = new PolicyOperation(); + + List profileOperationList = new ArrayList(); + for (ProfileFeature feature : effectiveFeatures) { + ProfileOperation operation = new ProfileOperation(); + + operation.setCode(feature.getFeatureCode()); + operation.setPayLoad(feature.getContent()); + profileOperationList.add(operation); + } + policyOperation.setProfileOperations(profileOperationList); + policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE);*/ + return effectiveFeatures; + } +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluation.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluation.java new file mode 100644 index 0000000000..f8fd2a7bb7 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluation.java @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + + +package org.wso2.carbon.policy.decision.point.simple; + +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.mgt.common.Policy; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; + +public interface SimpleEvaluation { + + void sortPolicies() throws PolicyEvaluationException; + + Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; + +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluationImpl.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluationImpl.java new file mode 100644 index 0000000000..aa1d02e58f --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluationImpl.java @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.policy.decision.point.simple; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.policy.decision.point.internal.PolicyDecisionPointDataHolder; +import org.wso2.carbon.policy.mgt.common.*; +import org.wso2.carbon.policy.mgt.core.PolicyManagerService; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class SimpleEvaluationImpl implements SimpleEvaluation { + + private static final Log log = LogFactory.getLog(SimpleEvaluationImpl.class); + //TODO : to revove the stale reference + private PolicyManagerService policyManagerService; + private List policyList = new ArrayList(); + +// public SimpleEvaluationImpl() { +// policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); +// } + + @Override + public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + Policy policy = new Policy(); + PolicyAdministratorPoint policyAdministratorPoint; + PolicyInformationPoint policyInformationPoint; + policyManagerService = getPolicyManagerService(); + + try { + if (policyManagerService != null) { + + policyInformationPoint = policyManagerService.getPIP(); + PIPDevice pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier); + policyList = policyInformationPoint.getRelatedPolicies(pipDevice); + policyAdministratorPoint = policyManagerService.getPAP(); + sortPolicies(); + if(!policyList.isEmpty()) { + policy = policyList.get(0); + } else { + policyAdministratorPoint.removePolicyUsed(deviceIdentifier); + return null; + } + //TODO : UNCOMMENT THE FOLLOWING CASE + policyAdministratorPoint.setPolicyUsed(deviceIdentifier, policy); + + } + + } 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); + } + return policy; + } + + + @Override + public void sortPolicies() throws PolicyEvaluationException { + Collections.sort(policyList); + } + + private PolicyManagerService getPolicyManagerService() { + return PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); + } +} From 62acc2ebf2b2a3d98b36990b4b67b1c8837aefaa Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 8 Nov 2016 15:06:18 +0530 Subject: [PATCH 12/22] Adding merged policy evaluation service component --- ...ergedPolicyEvaluationServiceComponent.java | 114 ++++++++++++++++++ .../point/merged/MergedEvaluationPoint.java | 5 + .../simple/PolicyEvaluationServiceImpl.java | 5 + .../mgt/common/PolicyEvaluationPoint.java | 2 + .../services/SimplePolicyEvaluationTest.java | 8 +- 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java 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 new file mode 100644 index 0000000000..6ea320442c --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java @@ -0,0 +1,114 @@ +/* +* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 Inc. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + +package org.wso2.carbon.policy.decision.point.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; +import org.wso2.carbon.policy.mgt.core.PolicyManagerService; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * @scr.component name="org.wso2.carbon.policy.decision.MergedPolicyEvaluationServiceComponent" immediate="true" + * @scr.reference name="user.realmservice.default" + * interface="org.wso2.carbon.user.core.service.RealmService" + * cardinality="1..1" + * policy="dynamic" + * bind="setRealmService" + * unbind="unsetRealmService" + * @scr.reference name="org.wso2.carbon.devicemgt.policy.manager" + * interface="org.wso2.carbon.policy.mgt.core.PolicyManagerService" + * cardinality="0..1" + * policy="dynamic" + * bind="setPolicyManagerService" + * unbind="unsetPolicyManagerService" + */ + +public class MergedPolicyEvaluationServiceComponent { + + private static Log log = LogFactory.getLog(MergedPolicyEvaluationServiceComponent.class); + + protected void activate(ComponentContext componentContext) { + if (log.isDebugEnabled()) { + log.debug("Activating the policy evaluation bundle."); + } + + try { + //TODO: fetch PEP class from config + + + componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(), + new MergedPolicyEvaluationServiceComponent(), null); + } catch (Throwable t) { + log.error("Error occurred while initializing the policy evaluation bundle"); + } + } + + protected void deactivate(ComponentContext componentContext) { + if (log.isDebugEnabled()) { + log.debug("De-activating the policy evaluation bundle."); + } + } + + /** + * Sets Realm Service + * + * @param realmService An instance of RealmService + */ + protected void setRealmService(RealmService realmService) { + + if (log.isDebugEnabled()) { + log.debug("Setting Realm Service"); + } + PolicyDecisionPointDataHolder.getInstance().setRealmService(realmService); + } + + /** + * Unsets Realm Service + * + * @param realmService An instance of RealmService + */ + protected void unsetRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting Realm Service"); + } + PolicyDecisionPointDataHolder.getInstance().setRealmService(null); + } + + protected void setPolicyManagerService(PolicyManagerService policyManagerService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting PolicyManagerService Service"); + } + PolicyDecisionPointDataHolder.getInstance().setPolicyManagerService(policyManagerService); + } + + protected void unsetPolicyManagerService(PolicyManagerService policyManagerService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting PolicyManagerService Service"); + } + PolicyDecisionPointDataHolder.getInstance().setPolicyManagerService(null); + } + + 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 88b9a36ad4..d88ca9fb14 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 @@ -60,6 +60,11 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { } } + @Override + public String getName() { + return "MergedPolicyEvaluationServiceComponent"; + } + @Override public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { 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 3b3727cff0..7229bfc747 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 @@ -59,4 +59,9 @@ public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE);*/ return effectiveFeatures; } + + @Override + public String getName() { + return "SimplePolicyEvaluationServiceComponent"; + } } 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 3fbf83ff9c..7b497ccb6e 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 @@ -43,4 +43,6 @@ public interface PolicyEvaluationPoint { * @return returns the effective feature set. */ List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; + + String getName(); } 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 ee62eb3ad7..62741ba503 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 @@ -29,7 +29,8 @@ import org.wso2.carbon.policy.mgt.core.PolicyManagerServiceImpl; import java.util.Collections; import java.util.List; -public class SimplePolicyEvaluationTest implements PolicyEvaluationPoint { +public class +SimplePolicyEvaluationTest implements PolicyEvaluationPoint { private static final Log log = LogFactory.getLog(SimplePolicyEvaluationTest.class); @@ -76,6 +77,11 @@ public class SimplePolicyEvaluationTest implements PolicyEvaluationPoint { return null; } + @Override + public String getName() { + return "MergedPolicyEvaluationServiceComponent"; + } + public void sortPolicies(List policyList) throws PolicyEvaluationException { Collections.sort(policyList); } From 35f3fcc8f978e8733fd168b4dbe35a50b5299a5b Mon Sep 17 00:00:00 2001 From: Supun94 Date: Tue, 8 Nov 2016 22:14:13 +0530 Subject: [PATCH 13/22] Changed policy evaluation point --- .../config/policy/PolicyConfiguration.java | 2 +- ...ergedPolicyEvaluationServiceComponent.java | 6 ++---- .../PolicyEvaluationServiceComponent.java | 5 +++-- .../mgt/core/PolicyManagerServiceImpl.java | 1 + .../internal/PolicyManagementDataHolder.java | 19 ++++++++++++++++--- .../PolicyManagementServiceComponent.java | 8 ++++---- .../mgt/core/PolicyEvaluationTestCase.java | 5 ++--- .../services/SimplePolicyEvaluationTest.java | 2 +- .../repository/conf/cdm-config.xml | 4 ++-- .../src/main/resources/conf/cdm-config.xml | 4 ++-- 10 files changed, 34 insertions(+), 22 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java index 56a5fe4cf2..a9522c9c2e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/policy/PolicyConfiguration.java @@ -33,7 +33,7 @@ public class PolicyConfiguration { private int minRetriesToMarkUnreachable; private int minRetriesToMarkInactive; private List platforms; - private String policyEvaluationPointName; + private String policyEvaluationPointName; @XmlElement(name = "MonitoringClass", required = true) public String getMonitoringClass() { diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java index 6ea320442c..906e3d0a4d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/MergedPolicyEvaluationServiceComponent.java @@ -21,6 +21,7 @@ package org.wso2.carbon.policy.decision.point.internal; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.user.core.service.RealmService; @@ -51,11 +52,8 @@ public class MergedPolicyEvaluationServiceComponent { } try { - //TODO: fetch PEP class from config - - componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(), - new MergedPolicyEvaluationServiceComponent(), null); + new MergedEvaluationPoint(), null); } catch (Throwable t) { log.error("Error occurred while initializing the policy evaluation bundle"); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java index 1ede6cb522..b331cbcef2 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java @@ -22,6 +22,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; import org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint; +import org.wso2.carbon.policy.decision.point.simple.PolicyEvaluationServiceImpl; +import org.wso2.carbon.policy.decision.point.simple.SimpleEvaluationImpl; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.user.core.service.RealmService; @@ -52,9 +54,8 @@ public class PolicyEvaluationServiceComponent { } try { - //TODO: fetch PEP class from config componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(), - new MergedEvaluationPoint(), null); + new PolicyEvaluationServiceImpl(), null); } catch (Throwable t) { log.error("Error occurred while initializing the simple policy evaluation bundle"); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java index 1cd88a72d0..24659bb421 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java @@ -173,6 +173,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { @Override public PolicyEvaluationPoint getPEP() throws PolicyManagementException { + PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java index 584bd2ec08..f089d81185 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java @@ -18,6 +18,8 @@ package org.wso2.carbon.policy.mgt.core.internal; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.ntask.core.service.TaskService; import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; @@ -36,6 +38,7 @@ public class PolicyManagementDataHolder { private RealmService realmService; private TenantManager tenantManager; private PolicyEvaluationPoint policyEvaluationPoint; + private Map policyEvaluationPoints = new HashMap<>(); private PolicyInformationPoint policyInformationPoint; private DeviceManagementProviderService deviceManagementService; private MonitoringManager monitoringManager; @@ -88,13 +91,23 @@ public class PolicyManagementDataHolder { } public PolicyEvaluationPoint getPolicyEvaluationPoint() { - return policyEvaluationPoint; + PolicyConfiguration policyConfiguration = DeviceConfigurationManager.getInstance(). + getDeviceManagementConfig().getPolicyConfiguration(); + String policyEvaluationPointName = policyConfiguration.getPolicyEvaluationPointName(); + return policyEvaluationPoints.get(policyEvaluationPointName); } - public void setPolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) { - this.policyEvaluationPoint = policyEvaluationPoint; + public void putPolicyEvaluationPoint(String name, PolicyEvaluationPoint policyEvaluationPoint) { + policyEvaluationPoints.put(name,policyEvaluationPoint); +// this.policyEvaluationPoint = policyEvaluationPoint; } + public void removePolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) { + policyEvaluationPoints.put(policyEvaluationPoint.getName(), this.policyEvaluationPoint); +// this.policyEvaluationPoint = policyEvaluationPoint; + } + + public PolicyInformationPoint getPolicyInformationPoint() { return policyInformationPoint; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java index 0c456fce28..427109e1d0 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementServiceComponent.java @@ -46,9 +46,9 @@ import org.wso2.carbon.user.core.service.RealmService; * policy="dynamic" * bind="setRealmService" * unbind="unsetRealmService" - * @scr.reference name="org.wso2.carbon.devicemgt.simple.policy.evaluation.manager" + * @scr.reference name="org.wso2.carbon.devicemgt.policy.evaluation.manager" * interface="org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint" - * cardinality="1..1" + * cardinality="1..n" * policy="dynamic" * bind="setPEPService" * unbind="unsetPEPService" @@ -159,14 +159,14 @@ public class PolicyManagementServiceComponent { if (log.isDebugEnabled()) { log.debug("Setting Policy Information Service"); } - PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(pepService); + PolicyManagementDataHolder.getInstance().putPolicyEvaluationPoint(pepService.getName(), pepService); } protected void unsetPEPService(PolicyEvaluationPoint pepService) { if (log.isDebugEnabled()) { log.debug("Removing Policy Information Service"); } - PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(null); + PolicyManagementDataHolder.getInstance().removePolicyEvaluationPoint(null); } protected void setDeviceManagementService(DeviceManagementProviderService deviceManagerService) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java index af0c3d604c..821526f2a5 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java @@ -51,7 +51,7 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest { @Override public void init() throws Exception { PolicyEvaluationPoint evaluationPoint = new SimplePolicyEvaluationTest(); - PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(evaluationPoint); + PolicyManagementDataHolder.getInstance().putPolicyEvaluationPoint(evaluationPoint.getName(), evaluationPoint); } @Test @@ -93,7 +93,7 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest { } @Test(dependsOnMethods = ("activatePolicies")) - public void getEffectivePolicy() throws DeviceManagementException, PolicyEvaluationException { + public void getEffectivePolicy(DeviceIdentifier identifier) throws DeviceManagementException, PolicyEvaluationException { log.debug("Getting effective policy for device started .........."); @@ -103,7 +103,6 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest { PolicyEvaluationPoint evaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); for (Device device : devices) { - DeviceIdentifier identifier = new DeviceIdentifier(); identifier.setType(device.getType()); identifier.setId(device.getDeviceIdentifier()); Policy policy = evaluationPoint.getEffectivePolicy(identifier); diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java index 62741ba503..3a1c674413 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/services/SimplePolicyEvaluationTest.java @@ -79,7 +79,7 @@ SimplePolicyEvaluationTest implements PolicyEvaluationPoint { @Override public String getName() { - return "MergedPolicyEvaluationServiceComponent"; + return "SimplePolicyEvaluationServiceComponent"; } public void sortPolicies(List policyList) throws PolicyEvaluationException { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml index 559cc3edd5..5dbad500c4 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/carbon-home/repository/conf/cdm-config.xml @@ -42,8 +42,8 @@ 5 8 20 - - MergedPolicyEvaluationServiceComponent + SimplePolicyEvaluationServiceComponent + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index 9e326a4f03..d115d0b74f 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -43,8 +43,8 @@ 5 8 20 - - MergedPolicyEvaluationServiceComponent + SimplePolicyEvaluationServiceComponent + android ios From 02fb952cc08d614b075a52677f427cafab2aa310 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Thu, 10 Nov 2016 10:51:50 +0530 Subject: [PATCH 14/22] Minor refactoring on policy decision point --- .../simple/PolicyEvaluationServiceImpl.java | 16 ++-------------- .../point/simple/SimpleEvaluationImpl.java | 6 ------ .../mgt/core/PolicyManagerServiceImpl.java | 1 - .../internal/PolicyManagementDataHolder.java | 2 -- .../carbon-home/repository/conf/cdm-config.xml | 4 ++-- .../src/main/resources/conf/cdm-config.xml | 4 ++-- 6 files changed, 6 insertions(+), 27 deletions(-) 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 7229bfc747..24ec30dc84 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 @@ -40,23 +40,11 @@ public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { } @Override - public List getEffectiveFeatures(List policyList, DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + public List getEffectiveFeatures(List policyList, DeviceIdentifier deviceIdentifier) + throws PolicyEvaluationException { List effectiveFeatures = evaluation.getEffectivePolicy(deviceIdentifier). getProfile().getProfileFeaturesList(); - -/* PolicyOperation policyOperation = new PolicyOperation(); - - List profileOperationList = new ArrayList(); - for (ProfileFeature feature : effectiveFeatures) { - ProfileOperation operation = new ProfileOperation(); - - operation.setCode(feature.getFeatureCode()); - operation.setPayLoad(feature.getContent()); - profileOperationList.add(operation); - } - policyOperation.setProfileOperations(profileOperationList); - policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE);*/ return effectiveFeatures; } diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluationImpl.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluationImpl.java index aa1d02e58f..f8c75e3105 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluationImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluationImpl.java @@ -32,14 +32,9 @@ import java.util.List; public class SimpleEvaluationImpl implements SimpleEvaluation { private static final Log log = LogFactory.getLog(SimpleEvaluationImpl.class); - //TODO : to revove the stale reference private PolicyManagerService policyManagerService; private List policyList = new ArrayList(); -// public SimpleEvaluationImpl() { -// policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); -// } - @Override public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { Policy policy = new Policy(); @@ -74,7 +69,6 @@ public class SimpleEvaluationImpl implements SimpleEvaluation { return policy; } - @Override public void sortPolicies() throws PolicyEvaluationException { Collections.sort(policyList); 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 24659bb421..1cd88a72d0 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java @@ -173,7 +173,6 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { @Override public PolicyEvaluationPoint getPEP() throws PolicyManagementException { - PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/internal/PolicyManagementDataHolder.java index f089d81185..5809468694 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 @@ -99,12 +99,10 @@ public class PolicyManagementDataHolder { public void putPolicyEvaluationPoint(String name, PolicyEvaluationPoint policyEvaluationPoint) { policyEvaluationPoints.put(name,policyEvaluationPoint); -// this.policyEvaluationPoint = policyEvaluationPoint; } public void removePolicyEvaluationPoint(PolicyEvaluationPoint policyEvaluationPoint) { policyEvaluationPoints.put(policyEvaluationPoint.getName(), this.policyEvaluationPoint); -// this.policyEvaluationPoint = policyEvaluationPoint; } 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 5dbad500c4..559cc3edd5 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 - SimplePolicyEvaluationServiceComponent - + + MergedPolicyEvaluationServiceComponent 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 d115d0b74f..9e326a4f03 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 - SimplePolicyEvaluationServiceComponent - + + MergedPolicyEvaluationServiceComponent android ios From 451b2fd1dc8c42f026f208310dcf6b7069b2e740 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Thu, 10 Nov 2016 12:34:44 +0530 Subject: [PATCH 15/22] Minor refactoring on policy evaluation --- .../mgt/core/internal/PolicyManagementDataHolder.java | 2 +- .../mgt/core/internal/PolicyManagementServiceComponent.java | 2 +- .../carbon/policy/mgt/core/PolicyEvaluationTestCase.java | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) 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 5809468694..a85928b063 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 @@ -97,7 +97,7 @@ public class PolicyManagementDataHolder { return policyEvaluationPoints.get(policyEvaluationPointName); } - public void putPolicyEvaluationPoint(String name, PolicyEvaluationPoint policyEvaluationPoint) { + public void setPolicyEvaluationPoint(String name, PolicyEvaluationPoint policyEvaluationPoint) { policyEvaluationPoints.put(name,policyEvaluationPoint); } 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 427109e1d0..0d8b41a64c 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 @@ -159,7 +159,7 @@ public class PolicyManagementServiceComponent { if (log.isDebugEnabled()) { log.debug("Setting Policy Information Service"); } - PolicyManagementDataHolder.getInstance().putPolicyEvaluationPoint(pepService.getName(), pepService); + PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(pepService.getName(), pepService); } protected void unsetPEPService(PolicyEvaluationPoint pepService) { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java index 821526f2a5..e97030301d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/java/org/wso2/carbon/policy/mgt/core/PolicyEvaluationTestCase.java @@ -27,14 +27,10 @@ import org.testng.annotations.Test; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; -import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl; -import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; import org.wso2.carbon.ntask.common.TaskException; import org.wso2.carbon.policy.mgt.common.*; -import org.wso2.carbon.policy.mgt.core.enforcement.DelegationTask; import org.wso2.carbon.policy.mgt.core.internal.PolicyManagementDataHolder; import org.wso2.carbon.policy.mgt.core.services.SimplePolicyEvaluationTest; @@ -51,7 +47,7 @@ public class PolicyEvaluationTestCase extends BasePolicyManagementDAOTest { @Override public void init() throws Exception { PolicyEvaluationPoint evaluationPoint = new SimplePolicyEvaluationTest(); - PolicyManagementDataHolder.getInstance().putPolicyEvaluationPoint(evaluationPoint.getName(), evaluationPoint); + PolicyManagementDataHolder.getInstance().setPolicyEvaluationPoint(evaluationPoint.getName(), evaluationPoint); } @Test From eb1575126f4c5ef3b2ef091e591951eb267be3d4 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Fri, 25 Nov 2016 11:14:53 +0530 Subject: [PATCH 16/22] 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 be9d318e3e..73ed8523a2 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 a9522c9c2e..1f52150f3f 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 067565db8e..d990e1ef1a 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 906e3d0a4d..3ec27e3918 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 d88ca9fb14..678705d9ed 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 24ec30dc84..ac1f6ebf89 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 7b497ccb6e..bf668f8531 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 1cd88a72d0..d06c3cb0ee 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 2fa70bb3af..fb3c8143f3 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 a85928b063..27f9487ac6 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 0d8b41a64c..85bce85332 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 2fbb9d84e1..78bb608890 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 3a1c674413..7fe3561ec2 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 559cc3edd5..3e2078ad11 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 0000000000..151a40c3e7 --- /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 From 2751d4b8564807ead4c9071ef85eef6ac092e26b Mon Sep 17 00:00:00 2001 From: Supun94 Date: Fri, 2 Dec 2016 12:11:30 +0530 Subject: [PATCH 17/22] Code refactoring --- .../pages/cdmf.page.effective-policy.view/view.js | 2 -- .../decision/point/merged/MergedEvaluationPoint.java | 12 +++++++++++- .../policy/mgt/core/PolicyManagerServiceImpl.java | 1 + .../enforcement/PolicyEnforcementDelegatorImpl.java | 7 ++++++- .../policy/mgt/core/mgt/impl/PolicyManagerImpl.java | 6 ++---- .../src/main/resources/conf/cdm-config.xml | 4 +++- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.js index b7056d8c03..46b4ed70b7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.effective-policy.view/view.js @@ -20,7 +20,5 @@ function onRequest(context) { var utility = require("/app/modules/utility.js")["utility"]; var deviceType = context.uriParams.deviceType; var deviceId = context.uriParams.deviceId; - new Log().info("Device Type : "+deviceType); - new Log().info("Device ID : "+deviceId); return {"deviceTypePolicyView": utility.getTenantedDeviceUnitName(deviceType, deviceId,"policy-view")}; } 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 678705d9ed..0223ed73bc 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 @@ -78,13 +78,23 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { profile.setUpdatedDate(currentTimestamp); profile.setDeviceType(deviceIdentifier.getType()); profile.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + // Set effective policy name policy.setPolicyName(effectivePolicyName); policy.setOwnershipType(pipDevice.getOwnershipType()); + // Set effective policy Active and Updated policy.setActive(true); policy.setUpdated(true); policy.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); - policy.setDescription("This is a system generated effective policy by merging relevant policies."); + String policyIds = ""; + Collections.sort(policyList); + for (Policy appliedPolicy : policyList) { + policyIds += appliedPolicy.getId() + ", "; + } + policyIds = policyIds.substring(0, policyIds.length() - 2); + policy.setDescription("This is a system generated effective policy by merging Policy Id : " + policyIds); + // Need to set compliance of the effective policy. Get compliance of first policy using priority order policy.setCompliance(policyList.get(0).getCompliance()); + // Change default 0 effective policy id to (-1) policy.setId(-1); return policy; } catch (PolicyManagementException e) { 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 d06c3cb0ee..eae94ce7c8 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 @@ -98,6 +98,7 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { policy = policyEvaluationPoint. getEffectivePolicy(deviceIdentifier); if (policy == null) { + policyAdministratorPoint.removePolicyUsed(deviceIdentifier); return null; } this.getPAP().setPolicyUsed(deviceIdentifier, policy); 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 fb3c8143f3..2d681cf93c 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 @@ -89,7 +89,12 @@ public class PolicyEnforcementDelegatorImpl implements PolicyEnforcementDelegato Policy policy = policyManagerService.getPEP().getEffectivePolicy(identifier); policyAdministratorPoint = policyManagerService.getPAP(); - policyAdministratorPoint.setPolicyUsed(identifier, policy); + if (policy != null) { + policyAdministratorPoint.setPolicyUsed(identifier, policy); + } else { + policyAdministratorPoint.removePolicyUsed(identifier); + return null; + } return policy; //return PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint().getEffectivePolicy(identifier); } catch (PolicyEvaluationException e) { 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 78bb608890..23b1a29420 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,8 @@ public class PolicyManagerImpl implements PolicyManager { PolicyManagementDAOFactory.beginTransaction(); Policy policySaved = policyDAO.getAppliedPolicy(deviceId, device.getEnrolmentInfo().getId()); - if (policySaved != null) { - if (policySaved.getId() != 0) { - policyDAO.updateEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy); - } + if (policySaved != null && policySaved.getId() != 0) { + policyDAO.updateEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy); } else { policyDAO.addEffectivePolicyToDevice(deviceId, device.getEnrolmentInfo().getId(), policy); } 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 39b4b0fedd..44d131dea2 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,7 +43,9 @@ 5 8 20 - + + + Merged android From d82a70f841ba467498f66a64e364b989c5ea55e7 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Fri, 2 Dec 2016 15:04:54 +0530 Subject: [PATCH 18/22] Changing simple policy decision point --- .../PolicyEvaluationServiceComponent.java | 6 +- .../decision/point/SimpleEvaluationImpl.java | 86 ------------------- 2 files changed, 3 insertions(+), 89 deletions(-) delete mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java index b331cbcef2..931d1ec552 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java @@ -50,20 +50,20 @@ public class PolicyEvaluationServiceComponent { protected void activate(ComponentContext componentContext) { if (log.isDebugEnabled()) { - log.debug("Activating the simple policy evaluation bundle."); + log.debug("Activating the policy evaluation bundle."); } try { componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(), new PolicyEvaluationServiceImpl(), null); } catch (Throwable t) { - log.error("Error occurred while initializing the simple policy evaluation bundle"); + log.error("Error occurred while initializing the policy evaluation bundle"); } } protected void deactivate(ComponentContext componentContext) { if (log.isDebugEnabled()) { - log.debug("De-activating the simple policy evaluation bundle."); + log.debug("De-activating the policy evaluation bundle."); } } diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java deleted file mode 100644 index 13cde3e181..0000000000 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java +++ /dev/null @@ -1,86 +0,0 @@ -/* -* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* WSO2 Inc. licenses this file to you under the Apache License, -* Version 2.0 (the "License"); you may not use this file except -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ - -package org.wso2.carbon.simple.policy.decision.point; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.policy.mgt.common.*; -import org.wso2.carbon.policy.mgt.core.PolicyManagerService; -import org.wso2.carbon.simple.policy.decision.point.internal.PolicyDecisionPointDataHolder; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class SimpleEvaluationImpl implements SimpleEvaluation { - - private static final Log log = LogFactory.getLog(SimpleEvaluationImpl.class); - //TODO : to revove the stale reference - private PolicyManagerService policyManagerService; - private List policyList = new ArrayList(); - -// public SimpleEvaluationImpl() { -// policyManagerService = PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); -// } - - @Override - public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { - Policy policy = new Policy(); - PolicyAdministratorPoint policyAdministratorPoint; - PolicyInformationPoint policyInformationPoint; - policyManagerService = getPolicyManagerService(); - - try { - if (policyManagerService != null) { - - policyInformationPoint = policyManagerService.getPIP(); - PIPDevice pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier); - policyList = policyInformationPoint.getRelatedPolicies(pipDevice); - policyAdministratorPoint = policyManagerService.getPAP(); - sortPolicies(); - if(!policyList.isEmpty()) { - policy = policyList.get(0); - } else { - policyAdministratorPoint.removePolicyUsed(deviceIdentifier); - return null; - } - //TODO : UNCOMMENT THE FOLLOWING CASE - policyAdministratorPoint.setPolicyUsed(deviceIdentifier, policy); - - } - - } 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); - } - return policy; - } - - - @Override - public void sortPolicies() throws PolicyEvaluationException { - Collections.sort(policyList); - } - - private PolicyManagerService getPolicyManagerService() { - return PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService(); - } -} From 89410dfae4847d2b4cb2f7e0cb609e1e19423847 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Mon, 5 Dec 2016 10:25:35 +0530 Subject: [PATCH 19/22] Changing getEffectiveFeatures method --- .../policy/decision/point/merged/MergedEvaluationPoint.java | 2 +- .../decision/point/simple/PolicyEvaluationServiceImpl.java | 2 +- .../wso2/carbon/policy/mgt/common/PolicyEvaluationPoint.java | 2 +- .../org/wso2/carbon/policy/mgt/core/PolicyManagerService.java | 2 +- .../wso2/carbon/policy/mgt/core/PolicyManagerServiceImpl.java | 4 ++-- .../policy/mgt/core/services/SimplePolicyEvaluationTest.java | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) 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 0223ed73bc..07fd0b68d3 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 @@ -40,7 +40,7 @@ public class MergedEvaluationPoint implements PolicyEvaluationPoint { private static final String policyEvaluationPoint = "Merged"; @Override - public List getEffectiveFeatures(List policyList, DeviceIdentifier deviceIdentifier) + public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { return this.getEffectivePolicy(deviceIdentifier).getProfile().getProfileFeaturesList(); } 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 ac1f6ebf89..d737cbaa3f 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 @@ -41,7 +41,7 @@ public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { } @Override - public List getEffectiveFeatures(List policyList, DeviceIdentifier deviceIdentifier) + public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { List effectiveFeatures = evaluation.getEffectivePolicy(deviceIdentifier). 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 bf668f8531..74ce2adf1a 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 @@ -43,7 +43,7 @@ public interface PolicyEvaluationPoint { * @param deviceIdentifier device information. * @return returns the effective feature set. */ - List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; + List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; /** * This method returns the name of the Policy Evaluation Point diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java index c8bd6e1d2f..96d7aac4d2 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/PolicyManagerService.java @@ -51,7 +51,7 @@ public interface PolicyManagerService { Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyManagementException; - List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws FeatureManagementException; + List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException; List getPolicies(String deviceType) throws PolicyManagementException; 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 eae94ce7c8..7f00319052 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 @@ -135,12 +135,12 @@ public class PolicyManagerServiceImpl implements PolicyManagerService { } @Override - public List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws + public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws FeatureManagementException { try { PolicyEvaluationPoint policyEvaluationPoint = PolicyManagementDataHolder.getInstance().getPolicyEvaluationPoint(); if (policyEvaluationPoint != null) { - return policyEvaluationPoint.getEffectiveFeatures(policyList, deviceIdentifier); + return policyEvaluationPoint.getEffectiveFeatures(deviceIdentifier); } else { throw new FeatureManagementException("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/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 7fe3561ec2..32f4efc212 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 @@ -73,7 +73,7 @@ SimplePolicyEvaluationTest implements PolicyEvaluationPoint { } @Override - public List getEffectiveFeatures(List policyList,DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { + public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { return null; } From 09572a997774e8e6d56181cc948377d50867e43a Mon Sep 17 00:00:00 2001 From: Supun94 Date: Mon, 12 Dec 2016 03:19:37 +0530 Subject: [PATCH 20/22] Removed redundant classes --- .../service/api/PolicyManagementService.java | 1 + .../point/PolicyEvaluationServiceImpl.java | 62 ------------------- .../decision/point/SimpleEvaluation.java | 32 ---------- 3 files changed, 1 insertion(+), 94 deletions(-) delete mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java delete mode 100644 components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java index 9226fd61dc..c4c3d60294 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java @@ -31,6 +31,7 @@ import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import io.swagger.annotations.ResponseHeader; +import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper; diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java deleted file mode 100644 index f6fbd82d69..0000000000 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/* -* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* WSO2 Inc. licenses this file to you under the Apache License, -* Version 2.0 (the "License"); you may not use this file except -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ - -package org.wso2.carbon.simple.policy.decision.point; - -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; -import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint; -import org.wso2.carbon.policy.mgt.common.ProfileFeature; - -import java.util.List; - -public class PolicyEvaluationServiceImpl implements PolicyEvaluationPoint { - - private SimpleEvaluationImpl evaluation; - - public PolicyEvaluationServiceImpl() { - evaluation = new SimpleEvaluationImpl(); - } - - @Override - public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { - return evaluation.getEffectivePolicy(deviceIdentifier); - } - - @Override - public List getEffectiveFeatures(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException { - - List effectiveFeatures = evaluation.getEffectivePolicy(deviceIdentifier). - getProfile().getProfileFeaturesList(); - -/* PolicyOperation policyOperation = new PolicyOperation(); - - List profileOperationList = new ArrayList(); - for (ProfileFeature feature : effectiveFeatures) { - ProfileOperation operation = new ProfileOperation(); - - operation.setCode(feature.getFeatureCode()); - operation.setPayLoad(feature.getContent()); - profileOperationList.add(operation); - } - policyOperation.setProfileOperations(profileOperationList); - policyOperation.setCode(PolicyManagementConstants.POLICY_BUNDLE);*/ - return effectiveFeatures; - } -} diff --git a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java b/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java deleted file mode 100644 index fb96100a06..0000000000 --- a/components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluation.java +++ /dev/null @@ -1,32 +0,0 @@ -/* -* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* WSO2 Inc. licenses this file to you under the Apache License, -* Version 2.0 (the "License"); you may not use this file except -* in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ - - -package org.wso2.carbon.simple.policy.decision.point; - -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.policy.mgt.common.Policy; -import org.wso2.carbon.policy.mgt.common.PolicyEvaluationException; - -public interface SimpleEvaluation { - - void sortPolicies() throws PolicyEvaluationException; - - Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException; - -} From 3d6f5ee64db3c99ca5d854a044d4f59113fac723 Mon Sep 17 00:00:00 2001 From: Supun94 Date: Fri, 16 Dec 2016 20:09:36 +0530 Subject: [PATCH 21/22] Changing policy compliance view --- .../public/js/device-view.js | 7 + .../public/templates/policy-compliance.hbs | 2 +- .../public/js/view.js | 2271 +------- .../templates/hidden-operations-android.hbs | 1493 ------ .../templates/hidden-operations-ios.hbs | 4728 ----------------- .../templates/hidden-operations-windows.hbs | 566 -- .../cdmf.unit.effective-policy.view/view.hbs | 121 +- .../cdmf.unit.effective-policy.view/view.js | 12 +- ...hanges or stash them before you can merge. | 15 - 9 files changed, 128 insertions(+), 9087 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-android.hbs delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-ios.hbs delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-windows.hbs delete mode 100644 e, commit your changes or stash them before you can merge. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js index 0ca5ddc820..0241ceefcf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js @@ -49,6 +49,7 @@ function loadOperationsLog(update) { var operationsLogTable = "#operations-log-table"; + if (update) { operationTable = $(operationsLogTable).DataTable(); $("#operations-spinner").removeClass("hidden"); @@ -135,9 +136,13 @@ function loadPolicyCompliance() { var policyCompliance = $("#policy-view"); var policyComplianceTemplate = policyCompliance.attr("src"); + console.log("deviceId:"+deviceId); + console.log("deviceType:"+deviceType); var deviceId = policyCompliance.data("device-id"); var deviceType = policyCompliance.data("device-type"); var activePolicy = null; + console.log("deviceId:"+deviceId); + console.log("deviceType:"+deviceType); $.template( "policy-view", @@ -163,6 +168,8 @@ var viewModel = {}; viewModel["policy"] = activePolicy; viewModel["deviceType"] = deviceType; + viewModel["deviceId"] = deviceId; + viewModel["appContext"] = context; data = JSON.parse(data); var content; if (data["complianceData"]) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/templates/policy-compliance.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/templates/policy-compliance.hbs index 3313320afd..198741bc57 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/templates/policy-compliance.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/templates/policy-compliance.hbs @@ -37,7 +37,7 @@
    - 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 d990e1ef1a..cebbaef87f 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 @@ -16,111 +16,14 @@ * under the License. */ -var validateStep = {}; -var skipStep = {}; -var stepForwardFrom = {}; -var stepBackFrom = {}; var policy = {}; -var configuredOperations = []; - -var base_api_url = "/api/device-mgt/v1.0"; - -// Constants to define platform types available -var platformTypeConstants = { - "ANDROID": "android", - "IOS": "ios", - "WINDOWS": "windows" -}; - -// Constants to define Android Operation Constants -var androidOperationConstants = { - "PASSCODE_POLICY_OPERATION": "passcode-policy", - "PASSCODE_POLICY_OPERATION_CODE": "PASSCODE_POLICY", - "CAMERA_OPERATION": "camera", - "CAMERA_OPERATION_CODE": "CAMERA", - "ENCRYPT_STORAGE_OPERATION": "encrypt-storage", - "ENCRYPT_STORAGE_OPERATION_CODE": "ENCRYPT_STORAGE", - "WIFI_OPERATION": "wifi", - "WIFI_OPERATION_CODE": "WIFI" -}; - -// Constants to define Android Operation Constants -var windowsOperationConstants = { - "PASSCODE_POLICY_OPERATION": "passcode-policy", - "PASSCODE_POLICY_OPERATION_CODE": "PASSCODE_POLICY", - "CAMERA_OPERATION": "camera", - "CAMERA_OPERATION_CODE": "CAMERA", - "ENCRYPT_STORAGE_OPERATION": "encrypt-storage", - "ENCRYPT_STORAGE_OPERATION_CODE": "ENCRYPT_STORAGE" -}; - -// Constants to define iOS Operation Constants -var iosOperationConstants = { - "PASSCODE_POLICY_OPERATION": "passcode-policy", - "PASSCODE_POLICY_OPERATION_CODE": "PASSCODE_POLICY", - "RESTRICTIONS_OPERATION": "restrictions", - "RESTRICTIONS_OPERATION_CODE": "RESTRICTION", - "WIFI_OPERATION": "wifi", - "WIFI_OPERATION_CODE": "WIFI", - "EMAIL_OPERATION": "email", - "EMAIL_OPERATION_CODE": "EMAIL", - "AIRPLAY_OPERATION": "airplay", - "AIRPLAY_OPERATION_CODE": "AIR_PLAY", - "LDAP_OPERATION": "ldap", - "LDAP_OPERATION_CODE": "LDAP", - "CALENDAR_OPERATION": "calendar", - "CALENDAR_OPERATION_CODE": "CALDAV", - "CALENDAR_SUBSCRIPTION_OPERATION": "calendar-subscription", - "CALENDAR_SUBSCRIPTION_OPERATION_CODE": "CALENDAR_SUBSCRIPTION", - "APN_OPERATION": "apn", - "APN_OPERATION_CODE": "APN", - "CELLULAR_OPERATION": "cellular", - "CELLULAR_OPERATION_CODE": "CELLULAR" -}; - -/** - * Method to update the visibility (i.e. disabled or enabled view) - * of grouped input according to the values - * that they currently possess. - * @param domElement HTML grouped-input element with class name "grouped-input" - */ -var updateGroupedInputVisibility = function (domElement) { - if ($(".parent-input:first", domElement).is(":checked")) { - if ($(".grouped-child-input:first", domElement).hasClass("disabled")) { - $(".grouped-child-input:first", domElement).removeClass("disabled"); - } - $(".child-input", domElement).each(function () { - $(this).prop('disabled', false); - }); - } else { - if (!$(".grouped-child-input:first", domElement).hasClass("disabled")) { - $(".grouped-child-input:first", domElement).addClass("disabled"); - } - $(".child-input", domElement).each(function () { - $(this).prop('disabled', true); - }); - } -}; - -skipStep["policy-platform"] = function (policyPayloadObj) { +var displayPolicy = function (policyPayloadObj) { policy["name"] = policyPayloadObj["policyName"]; policy["platform"] = policyPayloadObj["profile"]["deviceType"]; - var userRoleInput = $("#user-roles-input"); - var ownershipInput = $("#ownership-input"); - var userInput = $("#users-select-field"); - var actionInput = $("#action-input"); - var policyNameInput = $("#policy-name-input"); - var policyDescriptionInput = $("#policy-description-input"); - userRoleInput.val(policyPayloadObj.roles); - userInput.val(policyPayloadObj.users); - ownershipInput.val(policyPayloadObj.ownershipType); - actionInput.val(policyPayloadObj.compliance); - policyNameInput.val(policyPayloadObj["policyName"]); - policyDescriptionInput.val(policyPayloadObj["description"]); // updating next-page wizard title with selected platform $("#policy-heading").text(policy["platform"].toUpperCase() + " POLICY - " + policy["name"].toUpperCase()); $("#policy-platform").text(policy["platform"].toUpperCase()); - $("#policy-assignment").text(policyPayloadObj.ownershipType); + $("#policy-assignment").text(policyPayloadObj.deviceGroups); $("#policy-action").text(policyPayloadObj.compliance.toUpperCase()); $("#policy-description").text(policyPayloadObj["description"]); var policyStatus = "Active"; @@ -135,13 +38,27 @@ skipStep["policy-platform"] = function (policyPayloadObj) { } $("#policy-status").html(policyStatus); + console.log(policyPayloadObj); // if (policyPayloadObj.users.length > 0) { // $("#policy-users").text(policyPayloadObj.users.toString().split(",").join(", ")); // } else { // $("#users-row").addClass("hidden"); // } - // + // if (policyPayloadObj.deviceGroups.length > 0) { + // debugger; + // var deviceGroups = policyPayloadObj.deviceGroups; + // var assignedGroups = []; + // for (var index in deviceGroups) { + // if (deviceGroups.hasOwnProperty(index)) { + // assignedGroups.push(deviceGroups[index].name); + // } + // } + // $("#policy-groups").text(assignedGroups.toString().split(",").join(", ")); + // } else { + // $("#policy-groups").text("NONE"); + // } + // if (policyPayloadObj.roles.length > 0) { // $("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", ")); // } else { @@ -149,1887 +66,51 @@ skipStep["policy-platform"] = function (policyPayloadObj) { // } var deviceType = policy["platform"]; - var hiddenOperationsByDeviceType = $("#hidden-operations-" + deviceType); - var hiddenOperationsByDeviceTypeCacheKey = deviceType + "HiddenOperations"; - var hiddenOperationsByDeviceTypeSrc = hiddenOperationsByDeviceType.attr("src"); - - setTimeout( - function () { - $.template(hiddenOperationsByDeviceTypeCacheKey, hiddenOperationsByDeviceTypeSrc, function (template) { + var policyOperationsTemplateSrc = context + '/public/cdmf.unit.device.type.' + deviceType + + '.policy-view/templates/' + deviceType + '-policy-view.hbs'; + var policyOperationsScriptSrc = context + '/public/cdmf.unit.device.type.' + deviceType + + '.policy-view/js/' + deviceType + '-policy-view.js'; + var policyOperationsStylesSrc = context + '/public/cdmf.unit.device.type.' + deviceType + + '.policy-view/css/' + deviceType + '-policy-view.css'; + var policyOperationsTemplateCacheKey = deviceType + '-policy-operations'; + + $.isResourceExists(policyOperationsTemplateSrc, function (status) { + if (status) { + $.template(policyOperationsTemplateCacheKey, policyOperationsTemplateSrc, function (template) { var content = template(); - // pushing profile feature input elements - $(".wr-advance-operations").html(content); - // populating values and getting the list of configured features - var configuredOperations = operationModule. - 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); + $("#device-type-policy-operations").html(content).removeClass("hidden"); + $(".policy-platform").addClass("hidden"); + $.isResourceExists(policyOperationsScriptSrc, function (status) { + if (status) { + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = policyOperationsScriptSrc; + $(".wr-advance-operations").prepend(script); + /* + This method should be implemented in the relevant plugin side and should include the logic to + populate the policy profile in the plugin specific UI. + */ + polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]); + } }); - // enabling previously configured options of last update - 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(); - }); - } }); - }, - 250 // time delayed for the execution of above function, 250 milliseconds - ); -}; - -/** - * Checks if provided number is valid against a range. - * - * @param numberInput Number Input - * @param min Minimum Limit - * @param max Maximum Limit - * @returns {boolean} Returns true if input is within the specified range - */ -var inputIsValidAgainstRange = function (numberInput, min, max) { - return (numberInput == min || (numberInput > min && numberInput < max) || numberInput == max); -}; - -/** - * Checks if provided input is valid against RegEx input. - * - * @param regExp Regular expression - * @param input Input string to check - * @returns {boolean} Returns true if input matches RegEx - */ -var inputIsValidAgainstRegExp = function (regExp, input) { - return regExp.test(input); -}; - -validateStep["policy-profile"] = function () { - var validationStatusArray = []; - var validationStatus; - var operation; - - // starting validation process and updating validationStatus - if (policy["platform"] == platformTypeConstants["ANDROID"]) { - if (configuredOperations.length == 0) { - // updating validationStatus - validationStatus = { - "error": true, - "mainErrorMsg": "You cannot continue. Zero configured features." - }; - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } else { - // validating each and every configured Operation - // Validating PASSCODE_POLICY - if ($.inArray(androidOperationConstants["PASSCODE_POLICY_OPERATION_CODE"], configuredOperations) != -1) { - // if PASSCODE_POLICY is configured - operation = androidOperationConstants["PASSCODE_POLICY_OPERATION"]; - // initializing continueToCheckNextInputs to true - var continueToCheckNextInputs = true; - - // validating first input: passcodePolicyMaxPasscodeAgeInDays - var passcodePolicyMaxPasscodeAgeInDays = $("input#passcode-policy-max-passcode-age-in-days").val(); - if (passcodePolicyMaxPasscodeAgeInDays) { - if (!$.isNumeric(passcodePolicyMaxPasscodeAgeInDays)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode age is not a number.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(passcodePolicyMaxPasscodeAgeInDays, 1, 730)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode age is not with in the range of 1-to-730.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - - // validating second and last input: passcodePolicyPasscodeHistory - if (continueToCheckNextInputs) { - var passcodePolicyPasscodeHistory = $("input#passcode-policy-passcode-history").val(); - if (passcodePolicyPasscodeHistory) { - if (!$.isNumeric(passcodePolicyPasscodeHistory)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode history is not a number.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(passcodePolicyPasscodeHistory, 1, 50)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode history is not with in the range of 1-to-50.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating CAMERA - if ($.inArray(androidOperationConstants["CAMERA_OPERATION_CODE"], configuredOperations) != -1) { - // if CAMERA is configured - operation = androidOperationConstants["CAMERA_OPERATION"]; - // updating validationStatus - validationStatus = { - "error": false, - "okFeature": operation - }; - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating ENCRYPT_STORAGE - if ($.inArray(androidOperationConstants["ENCRYPT_STORAGE_OPERATION_CODE"], configuredOperations) != -1) { - // if ENCRYPT_STORAGE is configured - operation = androidOperationConstants["ENCRYPT_STORAGE_OPERATION"]; - // updating validationStatus - validationStatus = { - "error": false, - "okFeature": operation - }; - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating WIFI - if ($.inArray(androidOperationConstants["WIFI_OPERATION_CODE"], configuredOperations) != -1) { - // if WIFI is configured - operation = androidOperationConstants["WIFI_OPERATION"]; - // initializing continueToCheckNextInputs to true - continueToCheckNextInputs = true; - - var wifiSSID = $("input#wifi-ssid").val(); - if (!wifiSSID) { - validationStatus = { - "error": true, - "subErrorMsg": "WIFI SSID is not given. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - } - } - if (policy["platform"] == platformTypeConstants["WINDOWS"]) { - if (configuredOperations.length == 0) { - // updating validationStatus - validationStatus = { - "error": true, - "mainErrorMsg": "You cannot continue. Zero configured features." - }; - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } else { - // validating each and every configured Operation - // Validating PASSCODE_POLICY - if ($.inArray(windowsOperationConstants["PASSCODE_POLICY_OPERATION_CODE"], configuredOperations) != -1) { - // if PASSCODE_POLICY is configured - operation = windowsOperationConstants["PASSCODE_POLICY_OPERATION"]; - // initializing continueToCheckNextInputs to true - var continueToCheckNextInputs = true; - - // validating first input: passcodePolicyMaxPasscodeAgeInDays - var passcodePolicyMaxPasscodeAgeInDays = $("input#passcode-policy-max-passcode-age-in-days").val(); - if (passcodePolicyMaxPasscodeAgeInDays) { - if (!$.isNumeric(passcodePolicyMaxPasscodeAgeInDays)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode age is not a number.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(passcodePolicyMaxPasscodeAgeInDays, 1, 730)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode age is not with in the range of 1-to-730.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - - // validating second and last input: passcodePolicyPasscodeHistory - if (continueToCheckNextInputs) { - var passcodePolicyPasscodeHistory = $("input#passcode-policy-passcode-history").val(); - if (passcodePolicyPasscodeHistory) { - if (!$.isNumeric(passcodePolicyPasscodeHistory)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode history is not a number.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(passcodePolicyPasscodeHistory, 1, 50)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode history is not with in the range of 1-to-50.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating CAMERA - if ($.inArray(windowsOperationConstants["CAMERA_OPERATION_CODE"], configuredOperations) != -1) { - // if CAMERA is configured - operation = windowsOperationConstants["CAMERA_OPERATION"]; - // updating validationStatus - validationStatus = { - "error": false, - "okFeature": operation - }; - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating ENCRYPT_STORAGE - if ($.inArray(windowsOperationConstants["ENCRYPT_STORAGE_OPERATION_CODE"], configuredOperations) != -1) { - // if ENCRYPT_STORAGE is configured - operation = windowsOperationConstants["ENCRYPT_STORAGE_OPERATION"]; - // updating validationStatus - validationStatus = { - "error": false, - "okFeature": operation - }; - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - - } - } else if (policy["platform"] == platformTypeConstants["IOS"]) { - if (configuredOperations.length == 0) { - // updating validationStatus - validationStatus = { - "error": true, - "mainErrorMsg": "You cannot continue. Zero configured features." - }; - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } else { - // validating each and every configured Operation - // Validating PASSCODE_POLICY - if ($.inArray(iosOperationConstants["PASSCODE_POLICY_OPERATION_CODE"], configuredOperations) != -1) { - // if PASSCODE_POLICY is configured - operation = iosOperationConstants["PASSCODE_POLICY_OPERATION"]; - // initializing continueToCheckNextInputs to true - continueToCheckNextInputs = true; - - // validating first input: passcodePolicyMaxPasscodeAgeInDays - passcodePolicyMaxPasscodeAgeInDays = $("input#passcode-policy-max-passcode-age-in-days").val(); - if (passcodePolicyMaxPasscodeAgeInDays) { - if (!$.isNumeric(passcodePolicyMaxPasscodeAgeInDays)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode age is not a number.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(passcodePolicyMaxPasscodeAgeInDays, 1, 730)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode age is not with in the range of 1-to-730.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - - // validating second and last input: passcodePolicyPasscodeHistory - if (continueToCheckNextInputs) { - passcodePolicyPasscodeHistory = $("input#passcode-policy-passcode-history").val(); - if (passcodePolicyPasscodeHistory) { - if (!$.isNumeric(passcodePolicyPasscodeHistory)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode history is not a number.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(passcodePolicyPasscodeHistory, 1, 50)) { - validationStatus = { - "error": true, - "subErrorMsg": "Provided passcode history is not with in the range of 1-to-50.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating RESTRICTIONS - if ($.inArray(iosOperationConstants["RESTRICTIONS_OPERATION_CODE"], configuredOperations) != -1) { - // if RESTRICTION is configured - operation = iosOperationConstants["RESTRICTIONS_OPERATION"]; - // initializing continueToCheckNextInputs to true - continueToCheckNextInputs = true; - - // getting input values to be validated - var restrictionsAutonomousSingleAppModePermittedAppIDsGridChildInputs = - "div#restrictions-autonomous-single-app-mode-permitted-app-ids .child-input"; - if ($(restrictionsAutonomousSingleAppModePermittedAppIDsGridChildInputs).length > 0) { - var childInput; - var childInputArray = []; - var emptyChildInputCount = 0; - var duplicatesExist = false; - // looping through each child input - $(restrictionsAutonomousSingleAppModePermittedAppIDsGridChildInputs).each(function () { - childInput = $(this).val(); - childInputArray.push(childInput); - if (!childInput) { - // if child input field is empty - emptyChildInputCount++; - } - }); - // checking for duplicates - var initialChildInputArrayLength = childInputArray.length; - if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { - var m, poppedChildInput; - for (m = 0; m < (initialChildInputArrayLength - 1); m++) { - poppedChildInput = childInputArray.pop(); - var n; - for (n = 0; n < childInputArray.length; n++) { - if (poppedChildInput == childInputArray[n]) { - duplicatesExist = true; - break; - } - } - if (duplicatesExist) { - break; - } - } - } - // updating validationStatus - if (emptyChildInputCount > 0) { - // if empty child inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more permitted App ID entries in " + - "Autonomous Single App Mode are empty.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (duplicatesExist) { - validationStatus = { - "error": true, - "subErrorMsg": "Duplicate values exist with permitted App ID entries in " + - "Autonomous Single App Mode.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating WIFI - if ($.inArray(iosOperationConstants["WIFI_OPERATION_CODE"], configuredOperations) != -1) { - // if WIFI is configured - operation = iosOperationConstants["WIFI_OPERATION"]; - // initializing continueToCheckNextInputs to true - continueToCheckNextInputs = true; - - // getting input values to be validated - wifiSSID = $("input#wifi-ssid").val(); - var wifiDomainName = $("input#wifi-domain-name").val(); - if (!wifiSSID && !wifiDomainName) { - validationStatus = { - "error": true, - "subErrorMsg": "Both Wi-Fi SSID and Wi-Fi Domain Name are not given. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - - if (continueToCheckNextInputs) { - // getting proxy-setup value - var wifiProxyType = $("select#wifi-proxy-type").find("option:selected").attr("value"); - if (wifiProxyType == "Manual") { - // adds up additional fields to be validated - var wifiProxyServer = $("input#wifi-proxy-server").val(); - if (!wifiProxyServer) { - validationStatus = { - "error": true, - "subErrorMsg": "Wi-Fi Proxy Server is required. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - - if (continueToCheckNextInputs) { - var wifiProxyPort = $("input#wifi-proxy-port").val(); - if (!wifiProxyPort) { - validationStatus = { - "error": true, - "subErrorMsg": "Wi-Fi Proxy Port is required. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!$.isNumeric(wifiProxyPort)) { - validationStatus = { - "error": true, - "subErrorMsg": "Wi-Fi Proxy Port requires a number input.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(wifiProxyPort, 0, 65535)) { - validationStatus = { - "error": true, - "subErrorMsg": "Wi-Fi Proxy Port is not within the range " + - "of valid port numbers.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - } - - if (continueToCheckNextInputs) { - // getting encryption-type value - var wifiEncryptionType = $("select#wifi-encryption-type").find("option:selected").attr("value"); - if (wifiEncryptionType != "None") { - var wifiPayloadCertificateAnchorUUIDsGridChildInputs = - "div#wifi-payload-certificate-anchor-uuids .child-input"; - if ($(wifiPayloadCertificateAnchorUUIDsGridChildInputs).length > 0) { - emptyChildInputCount = 0; - childInputArray = []; - duplicatesExist = false; - // looping through each child input - $(wifiPayloadCertificateAnchorUUIDsGridChildInputs).each(function () { - childInput = $(this).val(); - childInputArray.push(childInput); - if (!childInput) { - // if child input field is empty - emptyChildInputCount++; - } - }); - // checking for duplicates - initialChildInputArrayLength = childInputArray.length; - if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { - for (m = 0; m < (initialChildInputArrayLength - 1); m++) { - poppedChildInput = childInputArray.pop(); - for (n = 0; n < childInputArray.length; n++) { - if (poppedChildInput == childInputArray[n]) { - duplicatesExist = true; - break; - } - } - if (duplicatesExist) { - break; - } - } - } - // updating validationStatus - if (emptyChildInputCount > 0) { - // if empty child inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more Payload Certificate " + - "Anchor UUIDs are empty.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (duplicatesExist) { - validationStatus = { - "error": true, - "subErrorMsg": "Duplicate values exist " + - "with Payload Certificate Anchor UUIDs.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - - if (continueToCheckNextInputs) { - var wifiTLSTrustedServerNamesGridChildInputs = - "div#wifi-tls-trusted-server-names .child-input"; - if ($(wifiTLSTrustedServerNamesGridChildInputs).length > 0) { - emptyChildInputCount = 0; - childInputArray = []; - duplicatesExist = false; - // looping through each child input - $(wifiTLSTrustedServerNamesGridChildInputs).each(function () { - childInput = $(this).val(); - childInputArray.push(childInput); - if (!childInput) { - // if child input field is empty - emptyChildInputCount++; - } - }); - // checking for duplicates - initialChildInputArrayLength = childInputArray.length; - if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { - for (m = 0; m < (initialChildInputArrayLength - 1); m++) { - poppedChildInput = childInputArray.pop(); - for (n = 0; n < childInputArray.length; n++) { - if (poppedChildInput == childInputArray[n]) { - duplicatesExist = true; - break; - } - } - if (duplicatesExist) { - break; - } - } - } - // updating validationStatus - if (emptyChildInputCount > 0) { - // if empty child inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more TLS Trusted Server Names are empty.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (duplicatesExist) { - validationStatus = { - "error": true, - "subErrorMsg": "Duplicate values exist " + - "with TLS Trusted Server Names.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - } - } - - if (continueToCheckNextInputs) { - var wifiRoamingConsortiumOIsGridChildInputs = "div#wifi-roaming-consortium-ois .child-input"; - if ($(wifiRoamingConsortiumOIsGridChildInputs).length > 0) { - emptyChildInputCount = 0; - var outOfAllowedLengthCount = 0; - var invalidAgainstRegExCount = 0; - childInputArray = []; - duplicatesExist = false; - // looping through each child input - $(wifiRoamingConsortiumOIsGridChildInputs).each(function () { - childInput = $(this).val(); - childInputArray.push(childInput); - if (!childInput) { - // if child input field is empty - emptyChildInputCount++; - } else if (!inputIsValidAgainstLength(childInput, 6, 6) && !inputIsValidAgainstLength(childInput, 10, 10)) { - outOfAllowedLengthCount++; - } else if (!inputIsValidAgainstRegExp(/^[a-fA-F0-9]+$/, childInput)) { - invalidAgainstRegExCount++; - } - }); - // checking for duplicates - initialChildInputArrayLength = childInputArray.length; - if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { - for (m = 0; m < (initialChildInputArrayLength - 1); m++) { - poppedChildInput = childInputArray.pop(); - for (n = 0; n < childInputArray.length; n++) { - if (poppedChildInput == childInputArray[n]) { - duplicatesExist = true; - break; - } - } - if (duplicatesExist) { - break; - } - } - } - // updating validationStatus - if (emptyChildInputCount > 0) { - // if empty child inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more Roaming Consortium OIs are empty.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (outOfAllowedLengthCount > 0) { - // if outOfMaxAllowedLength input is present - validationStatus = { - "error": true, - "subErrorMsg": "One or more Roaming Consortium OIs " + - "are out of allowed length.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (invalidAgainstRegExCount > 0) { - // if invalid inputs in terms of hexadecimal format are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more Roaming Consortium OIs " + - "contain non-hexadecimal characters.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (duplicatesExist) { - validationStatus = { - "error": true, - "subErrorMsg": "Duplicate values exist with Roaming Consortium OIs.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - - if (continueToCheckNextInputs) { - var wifiNAIRealmNamesGridChildInputs = "div#wifi-nai-realm-names .child-input"; - if ($(wifiNAIRealmNamesGridChildInputs).length > 0) { - emptyChildInputCount = 0; - childInputArray = []; - duplicatesExist = false; - // looping through each child input - $(wifiNAIRealmNamesGridChildInputs).each(function () { - childInput = $(this).val(); - childInputArray.push(childInput); - if (!childInput) { - // if child input field is empty - emptyChildInputCount++; - } - }); - // checking for duplicates - initialChildInputArrayLength = childInputArray.length; - if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { - for (m = 0; m < (initialChildInputArrayLength - 1); m++) { - poppedChildInput = childInputArray.pop(); - for (n = 0; n < childInputArray.length; n++) { - if (poppedChildInput == childInputArray[n]) { - duplicatesExist = true; - break; - } - } - if (duplicatesExist) { - break; - } - } - } - // updating validationStatus - if (emptyChildInputCount > 0) { - // if empty child inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more NAI Realm Names are empty.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (duplicatesExist) { - validationStatus = { - "error": true, - "subErrorMsg": "Duplicate values exist with NAI Realm Names.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - - if (continueToCheckNextInputs) { - var wifiMCCAndMNCsGridChildInputs = "div#wifi-mcc-and-mncs .child-input"; - if ($(wifiMCCAndMNCsGridChildInputs).length > 0) { - var childInputCount = 0; - var stringPair; - emptyChildInputCount = 0; - outOfAllowedLengthCount = 0; - var notNumericInputCount = 0; - childInputArray = []; - duplicatesExist = false; - // looping through each child input - $(wifiMCCAndMNCsGridChildInputs).each(function () { - childInput = $(this).val(); - // pushing each string pair to childInputArray - childInputCount++; - if (childInputCount % 2 == 1) { - // initialize stringPair value - stringPair = ""; - // append first part of the string - stringPair += childInput; - } else { - // append second part of the string - stringPair += childInput; - childInputArray.push(stringPair); - } - // updating emptyChildInputCount & outOfAllowedLengthCount - if (!childInput) { - // if child input field is empty - emptyChildInputCount++; - } else if (!$.isNumeric(childInput)) { - notNumericInputCount++; - } else if (!inputIsValidAgainstLength(childInput, 3, 3)) { - outOfAllowedLengthCount++; - } - }); - // checking for duplicates - initialChildInputArrayLength = childInputArray.length; - if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { - for (m = 0; m < (initialChildInputArrayLength - 1); m++) { - poppedChildInput = childInputArray.pop(); - for (n = 0; n < childInputArray.length; n++) { - if (poppedChildInput == childInputArray[n]) { - duplicatesExist = true; - break; - } - } - if (duplicatesExist) { - break; - } - } - } - // updating validationStatus - if (emptyChildInputCount > 0) { - // if empty child inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more MCC/MNC pairs are empty.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (notNumericInputCount > 0) { - // if notNumeric input is present - validationStatus = { - "error": true, - "subErrorMsg": "One or more MCC/MNC pairs are not numeric.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (outOfAllowedLengthCount > 0) { - // if outOfAllowedLength input is present - validationStatus = { - "error": true, - "subErrorMsg": "One or more MCC/MNC pairs " + - "do not fulfill the accepted length of 6 digits.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (duplicatesExist) { - validationStatus = { - "error": true, - "subErrorMsg": "Duplicate values exist with MCC/MNC pairs.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating EMAIL - if ($.inArray(iosOperationConstants["EMAIL_OPERATION_CODE"], configuredOperations) != -1) { - // if EMAIL is configured - operation = iosOperationConstants["EMAIL_OPERATION"]; - // initializing continueToCheckNextInputs to true - continueToCheckNextInputs = true; - - var emailAddress = $("input#email-address").val(); - if (emailAddress && !inputIsValidAgainstRegExp(/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/, emailAddress)) { - validationStatus = { - "error": true, - "subErrorMsg": "Email Address is not valid.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - - if (continueToCheckNextInputs) { - var emailIncomingMailServerHostname = $("input#email-incoming-mail-server-hostname").val(); - if (!emailIncomingMailServerHostname) { - validationStatus = { - "error": true, - "subErrorMsg": "Incoming Mail Server Hostname is empty. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - - if (continueToCheckNextInputs) { - var emailIncomingMailServerPort = $("input#email-incoming-mail-server-port").val(); - if (!emailIncomingMailServerPort) { - validationStatus = { - "error": true, - "subErrorMsg": "Incoming Mail Server Port is empty. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!$.isNumeric(emailIncomingMailServerPort)) { - validationStatus = { - "error": true, - "subErrorMsg": "Incoming Mail Server Port requires a number input.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(emailIncomingMailServerPort, 0, 65535)) { - validationStatus = { - "error": true, - "subErrorMsg": "Incoming Mail Server Port is not within the range " + - "of valid port numbers.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - - if (continueToCheckNextInputs) { - var emailOutgoingMailServerHostname = $("input#email-outgoing-mail-server-hostname").val(); - if (!emailOutgoingMailServerHostname) { - validationStatus = { - "error": true, - "subErrorMsg": "Outgoing Mail Server Hostname is empty. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - - if (continueToCheckNextInputs) { - var emailOutgoingMailServerPort = $("input#email-outgoing-mail-server-port").val(); - if (!emailOutgoingMailServerPort) { - validationStatus = { - "error": true, - "subErrorMsg": "Outgoing Mail Server Port is empty. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!$.isNumeric(emailOutgoingMailServerPort)) { - validationStatus = { - "error": true, - "subErrorMsg": "Outgoing Mail Server Port requires a number input.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(emailOutgoingMailServerPort, 0, 65535)) { - validationStatus = { - "error": true, - "subErrorMsg": "Outgoing Mail Server Port is not within the range " + - "of valid port numbers.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating AIRPLAY - if ($.inArray(iosOperationConstants["AIRPLAY_OPERATION_CODE"], configuredOperations) != -1) { - // if AIRPLAY is configured - operation = iosOperationConstants["AIRPLAY_OPERATION"]; - // initializing continueToCheckNextInputs to true - continueToCheckNextInputs = true; - - var airplayCredentialsGridChildInputs = "div#airplay-credentials .child-input"; - var airplayDestinationsGridChildInputs = "div#airplay-destinations .child-input"; - if ($(airplayCredentialsGridChildInputs).length == 0 && - $(airplayDestinationsGridChildInputs).length == 0) { - validationStatus = { - "error": true, - "subErrorMsg": "AirPlay settings have zero configurations attached.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - - if (continueToCheckNextInputs) { - if ($(airplayCredentialsGridChildInputs).length > 0) { - childInputCount = 0; - childInputArray = []; - emptyChildInputCount = 0; - duplicatesExist = false; - // looping through each child input - $(airplayCredentialsGridChildInputs).each(function () { - childInputCount++; - if (childInputCount % 2 == 1) { - // if child input is of first column - childInput = $(this).val(); - childInputArray.push(childInput); - // updating emptyChildInputCount - if (!childInput) { - // if child input field is empty - emptyChildInputCount++; - } - } - }); - // checking for duplicates - initialChildInputArrayLength = childInputArray.length; - if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { - for (m = 0; m < (initialChildInputArrayLength - 1); m++) { - poppedChildInput = childInputArray.pop(); - for (n = 0; n < childInputArray.length; n++) { - if (poppedChildInput == childInputArray[n]) { - duplicatesExist = true; - break; - } - } - if (duplicatesExist) { - break; - } - } - } - // updating validationStatus - if (emptyChildInputCount > 0) { - // if empty child inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more Device Names of " + - "AirPlay Credentials are empty.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (duplicatesExist) { - // if duplicate input is present - validationStatus = { - "error": true, - "subErrorMsg": "Duplicate values exist with " + - "Device Names of AirPlay Credentials.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - - if (continueToCheckNextInputs) { - if ($(airplayDestinationsGridChildInputs).length > 0) { - childInputArray = []; - emptyChildInputCount = 0; - invalidAgainstRegExCount = 0; - duplicatesExist = false; - // looping through each child input - $(airplayDestinationsGridChildInputs).each(function () { - childInput = $(this).val(); - childInputArray.push(childInput); - // updating emptyChildInputCount - if (!childInput) { - // 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)) { - // if child input field is invalid against RegEx - invalidAgainstRegExCount++ - } - }); - // checking for duplicates - initialChildInputArrayLength = childInputArray.length; - if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { - for (m = 0; m < (initialChildInputArrayLength - 1); m++) { - poppedChildInput = childInputArray.pop(); - for (n = 0; n < childInputArray.length; n++) { - if (poppedChildInput == childInputArray[n]) { - duplicatesExist = true; - break; - } - } - if (duplicatesExist) { - break; - } - } - } - // updating validationStatus - if (emptyChildInputCount > 0) { - // if empty child inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more AirPlay Destination fields are empty.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (invalidAgainstRegExCount > 0) { - // if invalidAgainstRegEx inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more AirPlay Destination fields " + - "do not fulfill expected format.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (duplicatesExist) { - // if duplicate input is present - validationStatus = { - "error": true, - "subErrorMsg": "Duplicate values exist with AirPlay Destinations.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating LDAP - if ($.inArray(iosOperationConstants["LDAP_OPERATION_CODE"], configuredOperations) != -1) { - // if LDAP is configured - operation = iosOperationConstants["LDAP_OPERATION"]; - // initializing continueToCheckNextInputs to true - continueToCheckNextInputs = true; - - var ldapAccountHostname = $("input#ldap-account-hostname").val(); - if (!ldapAccountHostname) { - validationStatus = { - "error": true, - "subErrorMsg": "LDAP Account Hostname URL is empty. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - - if (continueToCheckNextInputs) { - var ldapSearchSettingsGridChildInputs = "div#ldap-search-settings .child-input"; - if ($(ldapSearchSettingsGridChildInputs).length > 0) { - childInputCount = 0; - childInputArray = []; - emptyChildInputCount = 0; - duplicatesExist = false; - // looping through each child input - $(ldapSearchSettingsGridChildInputs).each(function () { - childInputCount++; - if (childInputCount % 3 == 2) { - // if child input is of second column - childInput = $(this).find("option:selected").attr("value"); - stringPair = ""; - stringPair += (childInput + " "); - } else if (childInputCount % 3 == 0) { - // if child input is of third column - childInput = $(this).val(); - stringPair += childInput; - childInputArray.push(stringPair); - // updating emptyChildInputCount - if (!childInput) { - // if child input field is empty - emptyChildInputCount++; - } - } - }); - // checking for duplicates - initialChildInputArrayLength = childInputArray.length; - if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { - for (m = 0; m < (initialChildInputArrayLength - 1); m++) { - poppedChildInput = childInputArray.pop(); - for (n = 0; n < childInputArray.length; n++) { - if (poppedChildInput == childInputArray[n]) { - duplicatesExist = true; - break; - } - } - if (duplicatesExist) { - break; - } - } - } - // updating validationStatus - if (emptyChildInputCount > 0) { - // if empty child inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more Search Setting Scope fields are empty.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (duplicatesExist) { - // if duplicate input is present - validationStatus = { - "error": true, - "subErrorMsg": "Duplicate values exist with " + - "Search Setting Search Base and Scope pairs.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating CALENDAR - if ($.inArray(iosOperationConstants["CALENDAR_OPERATION_CODE"], configuredOperations) != -1) { - // if CALENDAR is configured - operation = iosOperationConstants["CALENDAR_OPERATION"]; - // initializing continueToCheckNextInputs to true - continueToCheckNextInputs = true; - - var calendarAccountHostname = $("input#calendar-account-hostname").val(); - if (!calendarAccountHostname) { - validationStatus = { - "error": true, - "subErrorMsg": "Account Hostname URL is empty. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - - if (continueToCheckNextInputs) { - var calendarAccountPort = $("input#calendar-account-port").val(); - if (!calendarAccountPort) { - validationStatus = { - "error": true, - "subErrorMsg": "Account Port is empty. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!$.isNumeric(calendarAccountPort)) { - validationStatus = { - "error": true, - "subErrorMsg": "Account Port requires a number input.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(calendarAccountPort, 0, 65535)) { - validationStatus = { - "error": true, - "subErrorMsg": "Account Port is not within the range " + - "of valid port numbers.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating CALENDAR_SUBSCRIPTION - if ($.inArray(iosOperationConstants["CALENDAR_SUBSCRIPTION_OPERATION_CODE"], configuredOperations) != -1) { - // if CALENDAR_SUBSCRIPTION is configured - operation = iosOperationConstants["CALENDAR_SUBSCRIPTION_OPERATION"]; - // initializing continueToCheckNextInputs to true - continueToCheckNextInputs = true; - - var calendarSubscriptionHostname = $("input#calendar-subscription-hostname").val(); - if (!calendarSubscriptionHostname) { - validationStatus = { - "error": true, - "subErrorMsg": "Account Hostname URL is empty. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating APN - if ($.inArray(iosOperationConstants["APN_OPERATION_CODE"], configuredOperations) != -1) { - // if APN is configured - operation = iosOperationConstants["APN_OPERATION"]; - // initializing continueToCheckNextInputs to true - continueToCheckNextInputs = true; - - var apnConfigurationsGridChildInputs = "div#apn-configurations .child-input"; - if ($(apnConfigurationsGridChildInputs).length == 0) { - validationStatus = { - "error": true, - "subErrorMsg": "APN Settings have zero configurations attached.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if ($(apnConfigurationsGridChildInputs).length > 0) { - childInputCount = 0; - childInputArray = []; - // checking empty APN field count - emptyChildInputCount = 0; - duplicatesExist = false; - // looping through each child input - $(apnConfigurationsGridChildInputs).each(function () { - childInputCount++; - if (childInputCount % 5 == 1) { - // if child input is of first column - childInput = $(this).val(); - childInputArray.push(childInput); - // updating emptyChildInputCount - if (!childInput) { - // if child input field is empty - emptyChildInputCount++; - } - } - }); - // checking for duplicates - initialChildInputArrayLength = childInputArray.length; - if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { - for (m = 0; m < (initialChildInputArrayLength - 1); m++) { - poppedChildInput = childInputArray.pop(); - for (n = 0; n < childInputArray.length; n++) { - if (poppedChildInput == childInputArray[n]) { - duplicatesExist = true; - break; - } - } - if (duplicatesExist) { - break; - } - } - } - // updating validationStatus - if (emptyChildInputCount > 0) { - // if empty child inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more APN fields of Configurations are empty.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (duplicatesExist) { - // if duplicate input is present - validationStatus = { - "error": true, - "subErrorMsg": "Duplicate values exist with " + - "APN fields of Configurations.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; - } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - // Validating CELLULAR - if ($.inArray(iosOperationConstants["CELLULAR_OPERATION_CODE"], configuredOperations) != -1) { - // if CELLULAR is configured - operation = iosOperationConstants["CELLULAR_OPERATION"]; - // initializing continueToCheckNextInputs to true - continueToCheckNextInputs = true; - - var cellularAttachAPNName = $("input#cellular-attach-apn-name").val(); - if (!cellularAttachAPNName) { - validationStatus = { - "error": true, - "subErrorMsg": "Cellular Configuration Name is empty. You cannot proceed.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - - if (continueToCheckNextInputs) { - var cellularAPNConfigurationsGridChildInputs = "div#cellular-apn-configurations .child-input"; - if ($(cellularAPNConfigurationsGridChildInputs).length > 0) { - childInputCount = 0; - childInputArray = []; - // checking empty APN field count - emptyChildInputCount = 0; - duplicatesExist = false; - // looping through each child input - $(cellularAPNConfigurationsGridChildInputs).each(function () { - childInputCount++; - if (childInputCount % 6 == 1) { - // if child input is of first column - childInput = $(this).val(); - childInputArray.push(childInput); - // updating emptyChildInputCount - if (!childInput) { - // if child input field is empty - emptyChildInputCount++; - } - } - }); - // checking for duplicates - initialChildInputArrayLength = childInputArray.length; - if (emptyChildInputCount == 0 && initialChildInputArrayLength > 1) { - for (m = 0; m < (initialChildInputArrayLength - 1); m++) { - poppedChildInput = childInputArray.pop(); - for (n = 0; n < childInputArray.length; n++) { - if (poppedChildInput == childInputArray[n]) { - duplicatesExist = true; - break; - } - } - if (duplicatesExist) { - break; - } - } - } - // updating validationStatus - if (emptyChildInputCount > 0) { - // if empty child inputs are present - validationStatus = { - "error": true, - "subErrorMsg": "One or more APN fields of APN Configurations are empty.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (duplicatesExist) { - // if duplicate input is present - validationStatus = { - "error": true, - "subErrorMsg": "Duplicate values exist with " + - "APN fields of APN Configurations.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } - } - } - // at-last, if the value of continueToCheckNextInputs is still true - // this means that no error is found - if (continueToCheckNextInputs) { - validationStatus = { - "error": false, - "okFeature": operation - }; + $.isResourceExists(policyOperationsStylesSrc, function (status) { + if (status) { + var style = document.createElement('link'); + style.type = 'text/css'; + style.rel = 'stylesheet'; + style.href = policyOperationsStylesSrc; + $(".wr-advance-operations").prepend(style); } - - // updating validationStatusArray with validationStatus - validationStatusArray.push(validationStatus); - } - } - } - // ending validation process - - // start taking specific notifying actions upon validation - var wizardIsToBeContinued; - var errorCount = 0; - var mainErrorMsgWrapper, mainErrorMsg, - subErrorMsgWrapper, subErrorMsg, subErrorIcon, subOkIcon, featureConfiguredIcon; - var i; - for (i = 0; i < validationStatusArray.length; i++) { - validationStatus = validationStatusArray[i]; - if (validationStatus["error"]) { - errorCount++; - if (validationStatus["mainErrorMsg"]) { - mainErrorMsgWrapper = "#policy-profile-main-error-msg"; - mainErrorMsg = mainErrorMsgWrapper + " span"; - $(mainErrorMsg).text(validationStatus["mainErrorMsg"]); - $(mainErrorMsgWrapper).removeClass("hidden"); - } else if (validationStatus["subErrorMsg"]) { - subErrorMsgWrapper = "#" + validationStatus["erroneousFeature"] + "-feature-error-msg"; - subErrorMsg = subErrorMsgWrapper + " span"; - subErrorIcon = "#" + validationStatus["erroneousFeature"] + "-error"; - subOkIcon = "#" + validationStatus["erroneousFeature"] + "-ok"; - featureConfiguredIcon = "#" + validationStatus["erroneousFeature"] + "-configured"; - // hiding featureConfiguredState as the first step - if (!$(featureConfiguredIcon).hasClass("hidden")) { - $(featureConfiguredIcon).addClass("hidden"); - } - // updating error state and corresponding messages - $(subErrorMsg).text(validationStatus["subErrorMsg"]); - if ($(subErrorMsgWrapper).hasClass("hidden")) { - $(subErrorMsgWrapper).removeClass("hidden"); - } - if (!$(subOkIcon).hasClass("hidden")) { - $(subOkIcon).addClass("hidden"); - } - if ($(subErrorIcon).hasClass("hidden")) { - $(subErrorIcon).removeClass("hidden"); - } - } - } else { - if (validationStatus["okFeature"]) { - subErrorMsgWrapper = "#" + validationStatus["okFeature"] + "-feature-error-msg"; - subErrorIcon = "#" + validationStatus["okFeature"] + "-error"; - subOkIcon = "#" + validationStatus["okFeature"] + "-ok"; - featureConfiguredIcon = "#" + validationStatus["okFeature"] + "-configured"; - // hiding featureConfiguredState as the first step - if (!$(featureConfiguredIcon).hasClass("hidden")) { - $(featureConfiguredIcon).addClass("hidden"); - } - // updating success state and corresponding messages - if (!$(subErrorMsgWrapper).hasClass("hidden")) { - $(subErrorMsgWrapper).addClass("hidden"); - } - if (!$(subErrorIcon).hasClass("hidden")) { - $(subErrorIcon).addClass("hidden"); - } - if ($(subOkIcon).hasClass("hidden")) { - $(subOkIcon).removeClass("hidden"); - } - } - } - } - - wizardIsToBeContinued = (errorCount == 0); - return wizardIsToBeContinued; -}; - -stepForwardFrom["policy-profile"] = function () { - policy["profile"] = operationModule.generateProfile(policy["platform"], configuredOperations); - // updating next-page wizard title with selected platform - $("#policy-criteria-page-wizard-title").text(policy["platform"] + " POLICY - " + policy["name"]); -}; - -stepForwardFrom["policy-criteria"] = function () { - $("input[type='radio'].select-users-radio").each(function () { - if ($(this).is(':radio')) { - if ($(this).is(":checked")) { - if ($(this).attr("id") == "users-radio-btn") { - policy["selectedUsers"] = $("#users-input").val(); - } else if ($(this).attr("id") == "user-roles-radio-btn") { - policy["selectedUserRoles"] = $("#user-roles-input").val(); - } - } - } - }); - policy["selectedNonCompliantAction"] = $("#action-input").find(":selected").data("action"); - policy["selectedOwnership"] = $("#ownership-input").val(); - // updating next-page wizard title with selected platform - $("#policy-naming-page-wizard-title").text(policy["platform"] + " POLICY - " + policy["name"]); -}; - -/** - * Checks if provided input is valid against provided length range. - * - * @param input Alphanumeric or non-alphanumeric input - * @param minLength Minimum Required Length - * @param maxLength Maximum Required Length - * @returns {boolean} Returns true if input matches the provided minimum length and maximum length - */ -var inputIsValidAgainstLength = function (input, minLength, maxLength) { - var length = input.length; - return (length == minLength || (length > minLength && length < maxLength) || length == maxLength); -}; - -validateStep["policy-naming"] = function () { - var validationStatus = {}; - - // taking values of inputs to be validated - var policyName = $("input#policy-name-input").val(); - // starting validation process and updating validationStatus - if (!policyName) { - validationStatus["error"] = true; - validationStatus["mainErrorMsg"] = "Policy name is empty. You cannot proceed."; - } else if (!inputIsValidAgainstLength(policyName, 1, 30)) { - validationStatus["error"] = true; - validationStatus["mainErrorMsg"] = - "Policy name exceeds maximum allowed length."; - } else { - validationStatus["error"] = false; - } - // ending validation process - - // start taking specific actions upon validation - var wizardIsToBeContinued; - if (validationStatus["error"]) { - wizardIsToBeContinued = false; - var mainErrorMsgWrapper = "#policy-naming-main-error-msg"; - var mainErrorMsg = mainErrorMsgWrapper + " span"; - $(mainErrorMsg).text(validationStatus["mainErrorMsg"]); - $(mainErrorMsgWrapper).removeClass("hidden"); - } else { - wizardIsToBeContinued = true; - } - - return wizardIsToBeContinued; -}; - -validateStep["policy-naming-publish"] = function () { - var validationStatus = {}; - - // taking values of inputs to be validated - var policyName = $("input#policy-name-input").val(); - // starting validation process and updating validationStatus - if (!policyName) { - validationStatus["error"] = true; - validationStatus["mainErrorMsg"] = "Policy name is empty. You cannot proceed."; - } else if (!inputIsValidAgainstLength(policyName, 1, 30)) { - validationStatus["error"] = true; - validationStatus["mainErrorMsg"] = - "Policy name exceeds maximum allowed length."; - } else { - validationStatus["error"] = false; - } - // ending validation process - - // start taking specific actions upon validation - var wizardIsToBeContinued; - if (validationStatus["error"]) { - wizardIsToBeContinued = false; - var mainErrorMsgWrapper = "#policy-naming-main-error-msg"; - var mainErrorMsg = mainErrorMsgWrapper + " span"; - $(mainErrorMsg).text(validationStatus["mainErrorMsg"]); - $(mainErrorMsgWrapper).removeClass("hidden"); - } else { - wizardIsToBeContinued = true; - } - - return wizardIsToBeContinued; -}; - -stepForwardFrom["policy-naming-publish"] = function () { - policy["policyName"] = $("#policy-name-input").val(); - policy["description"] = $("#policy-description-input").val(); - //All data is collected. Policy can now be updated. - updatePolicy(policy, "publish"); -}; -stepForwardFrom["policy-naming"] = function () { - policy["policyName"] = $("#policy-name-input").val(); - policy["description"] = $("#policy-description-input").val(); - //All data is collected. Policy can now be updated. - updatePolicy(policy, "save"); -}; - -var updatePolicy = function (policy, state) { - var profilePayloads = []; - // traverses key by key in policy["profile"] - var key; - for (key in policy["profile"]) { - if (policy["profile"].hasOwnProperty(key)) { - profilePayloads.push({ - "featureCode": key, - "deviceType": policy["platform"], - "content": policy["profile"][key] }); + } else { + $("#generic-policy-operations").removeClass("hidden"); } - } - var payload = { - "policyName": policy["policyName"], - "description": policy["description"], - "compliance": policy["selectedNonCompliantAction"], - "ownershipType": policy["selectedOwnership"], - "profile": { - "profileName": policy["policyName"], - "deviceType": policy["platform"], - "profileFeaturesList": profilePayloads - } - }; - - if (policy["selectedUsers"]) { - payload["users"] = policy["selectedUsers"]; - } else if (policy["selectedUserRoles"]) { - payload["roles"] = policy["selectedUserRoles"]; - } else { - payload["users"] = []; - payload["roles"] = []; - } - var serviceURL = base_api_url + "/policy/effective-policy/" + policy["platform"] + "/" + getParameterByName("id"); - invokerUtil.put( - serviceURL, - payload, - // on success - function () { - if (state == "save") { - var policyList = []; - policyList.push(getParameterByName("id")); - serviceURL = base_api_url + "/policies/deactivate-policy"; - invokerUtil.post( - serviceURL, - policyList, - // on success - function () { - $(".policy-message").removeClass("hidden"); - $(".add-policy").addClass("hidden"); - }, - // on error - function (data) { - console.log(data); - } - ); - } else if (state == "publish") { - var policyList = []; - policyList.push(getParameterByName("id")); - serviceURL = base_api_url + "/policies/activate-policy"; - invokerUtil.post( - serviceURL, - policyList, - // on success - function () { - $(".policy-message").removeClass("hidden"); - $(".add-policy").addClass("hidden"); - }, - // on error - function (data) { - console.log(data); - } - ); - } - }, - // on error - function (data) { - console.log(data); - } - ); -}; - -// Start of HTML embedded invoke methods -var showAdvanceOperation = function (operation, button) { - $(button).addClass('selected'); - $(button).siblings().removeClass('selected'); - var hiddenOperation = ".wr-hidden-operations-content > div"; - $(hiddenOperation + '[data-operation="' + operation + '"]').show(); - $(hiddenOperation + '[data-operation="' + operation + '"]').siblings().hide(); -}; - -/** - * Method to slide down a provided pane upon provided value set. - * - * @param selectElement Select HTML Element to consider - * @param paneID HTML ID of div element to slide down - * @param valueSet Applicable Value Set - */ -var slideDownPaneAgainstValueSet = function (selectElement, paneID, valueSet) { - var selectedValueOnChange = $(selectElement).find("option:selected").val(); - if ($(selectElement).is("input:checkbox")) { - selectedValueOnChange = $(selectElement).is(":checked").toString(); - } - - var i, slideDownVotes = 0; - for (i = 0; i < valueSet.length; i++) { - if (selectedValueOnChange == valueSet[i]) { - slideDownVotes++; - } - } - var paneSelector = "#" + paneID; - if (slideDownVotes > 0) { - if (!$(paneSelector).hasClass("expanded")) { - $(paneSelector).addClass("expanded"); - } - $(paneSelector).slideDown(); - } else { - if ($(paneSelector).hasClass("expanded")) { - $(paneSelector).removeClass("expanded"); - } - $(paneSelector).slideUp(); - /* now follows the code to reinitialize all inputs of the slidable pane. - reinitializing input fields into the defaults.*/ - $(paneSelector + " input").each( - function () { - if ($(this).is("input:text")) { - $(this).val($(this).data("default")); - } else if ($(this).is("input:password")) { - $(this).val(""); - } else if ($(this).is("input:checkbox")) { - $(this).prop("checked", $(this).data("default")); - // if this checkbox is the parent input of a grouped-input - if ($(this).hasClass("parent-input")) { - var groupedInput = $(this).parent().parent().parent(); - updateGroupedInputVisibility(groupedInput); - } - } - } - ); - // reinitializing select fields into the defaults - $(paneSelector + " select").each( - function () { - var defaultOption = $(this).data("default"); - $("option:eq(" + defaultOption + ")", this).prop("selected", "selected"); - } - ); - // collapsing expanded-panes (upon the selection of html-select-options) if any - $(paneSelector + " .expanded").each( - function () { - if ($(this).hasClass("expanded")) { - $(this).removeClass("expanded"); - } - $(this).slideUp(); - } - ); - // removing all entries of grid-input elements if exist - $(paneSelector + " .grouped-array-input").each( - function () { - var gridInputs = $(this).find("[data-add-form-clone]"); - if (gridInputs.length > 0) { - gridInputs.remove(); - } - var helpTexts = $(this).find("[data-help-text=add-form]"); - if (helpTexts.length > 0) { - helpTexts.show(); - } - } - ); - } -}; - -var slideDownPaneAgainstValueSetForRadioButtons = function (selectElement, paneID, valueSet) { - var selectedValueOnChange = selectElement.value; - 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"); - } else { - $(paneSelector).addClass("hidden"); - } -}; -// End of HTML embedded invoke methods - - -// Start of functions related to grid-input-view - -/** - * Method to set count id to cloned elements. - * @param {object} addFormContainer - */ -var setId = function (addFormContainer) { - $(addFormContainer).find("[data-add-form-clone]").each(function (i) { - $(this).attr("id", $(this).attr("data-add-form-clone").slice(1) + "-" + (i + 1)); - if ($(this).find(".index").length > 0) { - $(this).find(".index").html(i + 1); - } + $(".wr-advance-operations-init").addClass("hidden"); }); }; -/** - * Method to set count id to cloned elements. - * @param {object} addFormContainer - */ -var showHideHelpText = function (addFormContainer) { - var helpText = "[data-help-text=add-form]"; - if ($(addFormContainer).find("[data-add-form-clone]").length > 0) { - $(addFormContainer).find(helpText).hide(); - } else { - $(addFormContainer).find(helpText).show(); - } -}; - -/** - * This method will display appropriate fields based on wifi type - * @param {object} wifi type select object - */ -var changeAndroidWifiPolicy = function (select) { - slideDownPaneAgainstValueSet(select, 'control-wifi-password', ['wep', 'wpa', '802eap']); - slideDownPaneAgainstValueSet(select, 'control-wifi-eap', ['802eap']); - slideDownPaneAgainstValueSet(select, 'control-wifi-phase2', ['802eap']); - slideDownPaneAgainstValueSet(select, 'control-wifi-identity', ['802eap']); - slideDownPaneAgainstValueSet(select, 'control-wifi-anoidentity', ['802eap']); - slideDownPaneAgainstValueSet(select, 'control-wifi-cacert', ['802eap']); -}; - -/** - * This method will display appropriate fields based on wifi EAP type - * @param {object} wifi eap select object - * @param {object} wifi type select object - */ -var changeAndroidWifiPolicyEAP = function (select, superSelect) { - slideDownPaneAgainstValueSet(select, 'control-wifi-password', ['peap', 'ttls', 'pwd' , 'fast', 'leap']); - slideDownPaneAgainstValueSet(select, 'control-wifi-phase2', ['peap', 'ttls', 'fast']); - slideDownPaneAgainstValueSet(select, 'control-wifi-provisioning', ['fast']); - slideDownPaneAgainstValueSet(select, 'control-wifi-identity', ['peap', 'tls', 'ttls', 'pwd', 'fast', 'leap']); - slideDownPaneAgainstValueSet(select, 'control-wifi-anoidentity', ['peap', 'ttls']); - slideDownPaneAgainstValueSet(select, 'control-wifi-cacert', ['peap', 'tls', 'ttls']); - if (superSelect.value != '802eap') { - changeAndroidWifiPolicy(superSelect); - } -}; - -// End of functions related to grid-input-view - /** * This method will return query parameter value given its name. * @param name Query parameter name @@ -2043,18 +124,15 @@ var getParameterByName = function (name) { }; $(document).ready(function () { - $('#appbar-btn-apply-changes').addClass('hidden'); - // Adding initial state of wizard-steps. - $("#policy-profile-wizard-steps").html($(".wr-steps").html()); - var policyPayloadObj; + // Adding initial state of wizard-steps. invokerUtil.get( - base_api_url + "/policies/effective-policy/" + getParameterByName("type") + "/" + getParameterByName("id"), + "/api/device-mgt/v1.0" + "/policies/effective-policy/" + getParameterByName("type") + "/" + getParameterByName("id"), // on success function (data, textStatus, jqXHR) { if (jqXHR.status == 200 && data) { policyPayloadObj = JSON.parse(data); - skipStep["policy-platform"](policyPayloadObj); + displayPolicy(policyPayloadObj); } }, // on error @@ -2063,243 +141,4 @@ $(document).ready(function () { // should be redirected to an error page } ); - - $("select.select2[multiple=multiple]").select2({ - "tags": true - }); - - $("#users-select-field").hide(); - $("#user-roles-select-field").show(); - - $("input[type='radio'].select-users-radio").change(function () { - if ($("#users-radio-btn").is(":checked")) { - $("#user-roles-select-field").hide(); - $("#users-select-field").show(); - } - if ($("#user-roles-radio-btn").is(":checked")) { - $("#users-select-field").hide(); - $("#user-roles-select-field").show(); - } - }); - - // Support for special input type "ANY" on user(s) & user-role(s) selection - $("#users-input, #user-roles-input").select2({ - "tags": true - }).on("select2:select", function (e) { - if (e.params.data.id == "ANY") { - $(this).val("ANY").trigger("change"); - } else { - $("option[value=ANY]", this).prop("selected", false).parent().trigger("change"); - } - }); - - // Maintains an array of configured features of the profile - var advanceOperations = ".wr-advance-operations"; - $(advanceOperations).on("click", ".wr-input-control.switch", function (event) { - var operationCode = $(this).parents(".operation-data").data("operation-code"); - var operation = $(this).parents(".operation-data").data("operation"); - var operationDataWrapper = $(this).data("target"); - // prevents event bubbling by figuring out what element it's being called from. - if (event.target.tagName == "INPUT") { - var featureConfiguredIcon; - if ($("input[type='checkbox']", this).is(":checked")) { - configuredOperations.push(operationCode); - // when a feature is enabled, if "zero-configured-features" msg is available, hide that. - var zeroConfiguredOperationsErrorMsg = "#policy-profile-main-error-msg"; - if (!$(zeroConfiguredOperationsErrorMsg).hasClass("hidden")) { - $(zeroConfiguredOperationsErrorMsg).addClass("hidden"); - } - // add configured-state-icon to the feature - featureConfiguredIcon = "#" + operation + "-configured"; - if ($(featureConfiguredIcon).hasClass("hidden")) { - $(featureConfiguredIcon).removeClass("hidden"); - } - } else { - //splicing the array if operation is present. - var index = $.inArray(operationCode, configuredOperations); - if (index != -1) { - configuredOperations.splice(index, 1); - } - // when a feature is disabled, clearing all its current configured, error or success states - var subErrorMsgWrapper = "#" + operation + "-feature-error-msg"; - var subErrorIcon = "#" + operation + "-error"; - var subOkIcon = "#" + operation + "-ok"; - featureConfiguredIcon = "#" + operation + "-configured"; - - if (!$(subErrorMsgWrapper).hasClass("hidden")) { - $(subErrorMsgWrapper).addClass("hidden"); - } - if (!$(subErrorIcon).hasClass("hidden")) { - $(subErrorIcon).addClass("hidden"); - } - if (!$(subOkIcon).hasClass("hidden")) { - $(subOkIcon).addClass("hidden"); - } - if (!$(featureConfiguredIcon).hasClass("hidden")) { - $(featureConfiguredIcon).addClass("hidden"); - } - // reinitializing input fields into the defaults - $(operationDataWrapper + " input").each( - function () { - if ($(this).is("input:text")) { - $(this).val($(this).data("default")); - } else if ($(this).is("input:password")) { - $(this).val(""); - } else if ($(this).is("input:checkbox")) { - $(this).prop("checked", $(this).data("default")); - // if this checkbox is the parent input of a grouped-input - if ($(this).hasClass("parent-input")) { - var groupedInput = $(this).parent().parent().parent(); - updateGroupedInputVisibility(groupedInput); - } - } - } - ); - // reinitializing select fields into the defaults - $(operationDataWrapper + " select").each( - function () { - var defaultOption = $(this).data("default"); - $("option:eq(" + defaultOption + ")", this).prop("selected", "selected"); - } - ); - // collapsing expanded-panes (upon the selection of html-select-options) if any - $(operationDataWrapper + " .expanded").each( - function () { - if ($(this).hasClass("expanded")) { - $(this).removeClass("expanded"); - } - $(this).slideUp(); - } - ); - // removing all entries of grid-input elements if exist - $(operationDataWrapper + " .grouped-array-input").each( - function () { - var gridInputs = $(this).find("[data-add-form-clone]"); - if (gridInputs.length > 0) { - gridInputs.remove(); - } - var helpTexts = $(this).find("[data-help-text=add-form]"); - if (helpTexts.length > 0) { - helpTexts.show(); - } - } - ); - } - } - }); - - // adding support for cloning multiple profiles per feature with cloneable class definitions - $(advanceOperations).on("click", ".multi-view.add.enabled", function () { - // get a copy of .cloneable and create new .cloned div element - var cloned = "

    " + $(".cloneable", $(this).parent().parent()).html() + "
    "; - // append newly created .cloned div element to panel-body - $(this).parent().parent().append(cloned); - // enable remove action of newly cloned div element - $(".cloned", $(this).parent().parent()).each( - function () { - if ($(".multi-view.remove", this).hasClass("disabled")) { - $(".multi-view.remove", this).removeClass("disabled"); - } - if (!$(".multi-view.remove", this).hasClass("enabled")) { - $(".multi-view.remove", this).addClass("enabled"); - } - } - ); - }); - - $(advanceOperations).on("click", ".multi-view.remove.enabled", function () { - $(this).parent().remove(); - }); - - // enabling or disabling grouped-input based on the status of a parent check-box - $(advanceOperations).on("click", ".grouped-input", function () { - updateGroupedInputVisibility(this); - }); - - // add form entry click function for grid inputs - $(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")); - - // adding class .child-input to capture text-input-array-values - $("input, select", clonedForm).addClass("child-input"); - - $(addFormContainer).append(clonedForm); - setId(addFormContainer); - showHideHelpText(addFormContainer); - }); - - // remove form entry click function for grid inputs - $(advanceOperations).on("click", "[data-click-event=remove-form]", function () { - var addFormContainer = $("[data-add-form-container=" + $(this).attr("href") + "]"); - - $(this).closest("[data-add-form-element=clone]").remove(); - setId(addFormContainer); - showHideHelpText(addFormContainer); - }); - - $(".wizard-stepper").click(function () { - // button clicked here can be either a continue button or a back button. - var currentStep = $(this).data("current"); - var validationIsRequired = $(this).data("validate"); - var wizardIsToBeContinued; - - if (validationIsRequired) { - wizardIsToBeContinued = validateStep[currentStep](); - } else { - wizardIsToBeContinued = true; - } - - if (wizardIsToBeContinued) { - // When moving back and forth, following code segment will - // remove if there are any visible error-messages. - var errorMsgWrappers = ".alert.alert-danger"; - $(errorMsgWrappers).each( - function () { - if (!$(this).hasClass("hidden")) { - $(this).addClass("hidden"); - } - } - ); - - var nextStep = $(this).data("next"); - var isBackBtn = $(this).data("is-back-btn"); - - // if current button is a continuation... - if (!isBackBtn) { - // initiate stepForwardFrom[*] functions to gather form data. - if (stepForwardFrom[currentStep]) { - stepForwardFrom[currentStep](this); - } - } else { - // initiate stepBackFrom[*] functions to rollback. - if (stepBackFrom[currentStep]) { - stepBackFrom[currentStep](); - } - } - - // following step occurs only at the last stage of the wizard. - if (!nextStep) { - window.location.href = $(this).data("direct"); - } - - // updating next wizard step as current. - $(".itm-wiz").each(function () { - var step = $(this).data("step"); - if (step == nextStep) { - $(this).addClass("itm-wiz-current"); - } else { - $(this).removeClass("itm-wiz-current"); - } - }); - - // adding next update of wizard-steps. - $("#" + nextStep + "-wizard-steps").html($(".wr-steps").html()); - - // hiding current section of the wizard and showing next section. - $("." + currentStep).addClass("hidden"); - $("." + nextStep).removeClass("hidden"); - } - }); }); 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/templates/hidden-operations-android.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-android.hbs deleted file mode 100644 index 2017870949..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-android.hbs +++ /dev/null @@ -1,1493 +0,0 @@ -
    - - -
    - -
    -
    - -
    -
    - - -
    - -
    - -
    - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    -
    -
    -
    - - - -
    -
    - -
    -
    - -
    -
    - -
    - -
    -
    - Bellow restrictions will be applied on devices with Android version 5.0 Lollipop onwards only - -

    -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    - -
    - -
    -
    -
    - Bellow restrictions will be applied on devices with Android version 6.0 Marshmallow onwards only. - -

    -
    - -
    -
    -
    -
    -
    - - - -
    -
    - -
    -
    - - Un-check following checkbox in case you do not need the device to be encrypted. -
    -
    -
    - -
    -
    -
    -
    -
    - - - -
    -
    - -
    -
    - - - - - - - - - - - - - - - - - Please note that * sign represents required fields of data. -
    -
    - -
    - - -
    -
    - - -
    - - - - - - - - -
    -
    -
    - - -
    -
    - -
    -
    - - - -
    -
    - -
    - -
    - - - - - - - - - - - - - - -
    No:Application Name/DescriptionPackage Name
    - No entries added yet . -
    - - - - - - - - - - -
    -
    -
    -
    -
    - - - -
    -
    - -
    -
    - Please note that * sign represents required fields of data. -
    -
    - -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    - -
    -
    - - - -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    - - -
    -
    -
    -
    - - -
    -
    - - -
    - - - -
    - -

    - - - -
    - - - -
    -
    -
    - - -
    -
    - - -
    - - - -
    - -
    - - - - - - - - - - - - - - -
    No:Application Name / DescriptionPackage Name
    - No entries added yet . -
    - - - - - - - - - - -
    -
    -
    -
    -
    -
    -
    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/templates/hidden-operations-ios.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-ios.hbs deleted file mode 100644 index 37a776b6f8..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-ios.hbs +++ /dev/null @@ -1,4728 +0,0 @@ -
    - - -
    - -
    -
    - -
    - - - -
    - -
    - -
    - -
    - -
    - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    -
    -
    -
    - - - -
    -
    - -
    -
    -Please note that * sign represents required fields of data. -
    -
    - - -
    - - -
    -
    - -
    -
    - -
    - -
    - -
    - - - - - - - - - - - - - - -
    No:KeyValue
    - No entries added yet . -
    - - - - - - - - - - -
    -
    -
    - - -
    - - - - -
    -
    -
    - - - -
    -
    - -
    -
    - Please note that * sign represents required fields of data. -
    -
    - - -
    - - -
    -
    - -
    -
    - - -
    - - - - - - - - - - - - - -
    No:Safari Domain
    - No entries added yet . -
    - - - - - - - - - - -
    -
    -
    -
    -
    - -
    - Please note that * sign represents required fields of data. -
    -
    - - -
    - - -
    - - - - - - - - - - - - - - -
    No:App IdentifierVPN UUID
    - No entries added yet . -
    - - - - - - - - - - -
    -
    -
    -
    -
    - - - -
    -
    - -
    -
    - - - -
    - -
    - - -
    - - - - - - - - - - - - - - -
    No:Application Name/DescriptionPackage Name
    - No entries added yet . -
    - - - - - - - - - - -
    -
    -
    -
    -
    - - - -
    -
    - -
    -
    - - -
    - - -
    - -
    - - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - - -
    - -
    - - -
    - - - -
    - - -
    - - - -
    - - -
    - - - - - - - - - - - - - -
    No:Roaming Consortium OI
    - No entries added yet . -
    - - - - - - - - - -
    -
    - -
    - -
    - - -
    - - - - - - - - - - - - - -
    No:NAI Realm Name
    - No entries added yet . -
    - - - - - - - - - -
    -
    - -
    - -
    - - -
    - - - - - - - - - - - - - - -
    No:Mobile Country Code ( MCC )Mobile Network Code ( MNC )
    - No entries added yet . -
    - - - - - - - - - - -
    -
    -
    -
    -
    - - - -
    -
    - -
    -
    - - -
    - - -
    - -
    - - -
    - -
    - -
    - - -
    - -
    - -
    - - -
    - -
    - - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - - -
    - -
    - - -
    - -
    - -
    - -
    - -
    - -
    -Incoming Mail Settings : -
    - -
    - - -
    - -
    - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    -Outgoing Mail Settings : -
    - -
    - - -
    - -
    - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - -
    - -
    - - -
    - -
    -
    -
    - - - -
    -
    - -
    -
    - - -
    - - -
    - - - - - - - - - - - - - - -
    No:Device NamePassword
    - No entries added yet . -
    - - - - - - - - - - -
    -
    - -
    - -
    - - -
    - - - - - - - - - - - - - -
    No:Destination
    - No entries added yet . -
    - - - - - - - - - -
    -
    - -
    -
    -
    - - - -
    -
    - -
    -
    - - -
    - - -
    - -
    - - -
    - -
    - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - - - - - - - - - - - - - - - -
    No:DescriptionSearch BaseScope
    - No entries added yet . -
    - - - - - - - - - - - -
    -
    - -
    -
    -
    - - - -
    -
    - -
    -
    - - -
    - - -
    - -
    - - -
    - -
    - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    -
    -
    - - - -
    -
    - -
    -
    - - -
    - - -
    - -
    - - -
    - -
    - -
    - -
    - - -
    - -
    - - -
    - -
    -
    -
    - - - -
    -
    - -
    -
    - - -
    - - -
    - - - - - - - - - - - - - - - - - -
    No:APNUsernamePasswordProxyPort
    - No entries added yet . -
    - - - - - - - - - - - - - -
    -
    - -
    -
    -
    - - - -
    -
    - -
    -
    - - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - - - - - - - - - - - - - - - - - - -
    No:APNAuth.TypeUsernamePasswordProxyPort
    - No entries added yet . -
    - - - - - - - - - - - - - - -
    -
    - -
    -
    -
    - - - -
    -
    - -
    -
    - - -Restrictions on Device Functionality : -
    -
    -
      -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
        -
      • -
        - -
        -
      • -
      • -
        - -
        -
      • -
      • -
        - -
        -
      • -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    -
    -
    -Restrictions on Applications : -
    -
    -
      -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
        -
      • -
        - -
        -
      • -
      • -
        - -
        -
      • -
      • -
        - -
        -
      • -
      • -
        - -
        -
      • -
      • -
        - - -
        -
      • -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    • -
      - -
      -
    • -
    -
    - - - -
    -
    -
    - -
    -
    \ No newline at end of file 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/templates/hidden-operations-windows.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-windows.hbs deleted file mode 100644 index c05725b89d..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/public/templates/hidden-operations-windows.hbs +++ /dev/null @@ -1,566 +0,0 @@ -
    - - -
    - -
    -
    - -
    -
    - - -
    - -
    - -
    - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    - -
    - - -
    -
    -
    -
    - - - -
    -
    - -
    -
    - - Un-check following checkbox in case you need to disable camera. -
    -
    -
    - -
    -
    -
    -
    -
    - - - -
    -
    - -
    -
    - - Un-check following checkbox in case you need to disable storage-encryption. -
    -
    -
    - -
    -
    -
    -
    -
    - - - -
    -
    - -
    -
    - - - -
    -
    - -
    - - - - - - - - - - - - - - -
    No:Application Name/DescriptionPackage Name
    - No entries added yet . -
    - - - - - - - - - - -
    -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -
    \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.hbs index b7f2adf56d..025e51d81b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.hbs @@ -1,4 +1,5 @@ {{#zone "content"}} +{{!--#if isAuthorized--}} {{#defineZone "policy-profile-top"}}
    @@ -12,60 +13,64 @@
    -
    -
    - Policy Overview -
    - {{#defineZone "policy-detail-properties"}} - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Platform
    Ownership
    Action upon non-compliance
    Status
    Assigned Users
    Assigned Roles
    - {{/defineZone}} -
    Description
    -
    -
    -
    -
    -
    - Profile Information +
    + Policy Overview +
    + {{#defineZone "policy-detail-properties"}} + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Platform
    Groups
    Action upon non-compliance
    Status
    Assigned Users
    Assigned Roles
    + {{/defineZone}} +
    Description +
    +
    +
    +
    +
    +
    + Profile Information +
    +
    + -
    - {{/zone}} {{#zone "bottomJs"}} - - - - - - {{js "js/view.js"}} -{{/zone}} - +{{/zone}} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.js index 2d2a438263..06aa7bf336 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.effective-policy.view/view.js @@ -17,9 +17,11 @@ */ function onRequest(context) { -// var log = new Log("policy-view-edit-unit backend js"); -// var userModule = require("/app/modules/business-controllers/user.js")["userModule"]; -// context.roles = userModule.getRoles(); - return context; -} \ No newline at end of file + var utility = require("/app/modules/utility.js")["utility"]; + var deviceType = context.uriParams.deviceType; + var deviceId = context.uriParams.deviceId; + + return {"deviceTypePolicyView": utility.getTenantedDeviceUnitName(deviceType, deviceId,"policy-view")}; + +} 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. deleted file mode 100644 index 151a40c3e7..0000000000 --- a/e, commit your changes or stash them before you can merge. +++ /dev/null @@ -1,15 +0,0 @@ -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 From a831dc6a9a17e4d2b254dff4b057924135363a0e Mon Sep 17 00:00:00 2001 From: Supun94 Date: Mon, 19 Dec 2016 15:28:28 +0530 Subject: [PATCH 22/22] Changing cdm-config file --- .../public/js/device-view.js | 7 --- .../public/js/view.js | 56 +++++++++++-------- .../repository/conf/cdm-config.xml | 2 +- .../src/main/resources/conf/cdm-config.xml | 2 +- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js index 0241ceefcf..3672656fd4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.view/public/js/device-view.js @@ -16,7 +16,6 @@ * under the License. */ -(function () { var deviceId = $(".device-id"); var deviceIdentifier = deviceId.data("deviceid"); var deviceType = deviceId.data("type"); @@ -136,13 +135,9 @@ function loadPolicyCompliance() { var policyCompliance = $("#policy-view"); var policyComplianceTemplate = policyCompliance.attr("src"); - console.log("deviceId:"+deviceId); - console.log("deviceType:"+deviceType); var deviceId = policyCompliance.data("device-id"); var deviceType = policyCompliance.data("device-type"); var activePolicy = null; - console.log("deviceId:"+deviceId); - console.log("deviceType:"+deviceType); $.template( "policy-view", @@ -213,5 +208,3 @@ } ); } - -}()); 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 cebbaef87f..a41d89fa1b 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 @@ -38,32 +38,40 @@ var displayPolicy = function (policyPayloadObj) { } $("#policy-status").html(policyStatus); - console.log(policyPayloadObj); - // if (policyPayloadObj.users.length > 0) { - // $("#policy-users").text(policyPayloadObj.users.toString().split(",").join(", ")); - // } else { - // $("#users-row").addClass("hidden"); - // } - // if (policyPayloadObj.deviceGroups.length > 0) { - // debugger; - // var deviceGroups = policyPayloadObj.deviceGroups; - // var assignedGroups = []; - // for (var index in deviceGroups) { - // if (deviceGroups.hasOwnProperty(index)) { - // assignedGroups.push(deviceGroups[index].name); - // } - // } - // $("#policy-groups").text(assignedGroups.toString().split(",").join(", ")); - // } else { - // $("#policy-groups").text("NONE"); - // } + if (policyPayloadObj.users == null) { + $("#policy-users").text("NONE"); + } + else if (policyPayloadObj.users.length > 0) { + $("#policy-users").text(policyPayloadObj.users.toString().split(",").join(", ")); + } else { + $("#users-row").addClass("hidden"); + } + + if (policyPayloadObj.deviceGroups == null) { + $("#policy-groups").text("NONE"); + } else if (policyPayloadObj.deviceGroups.length > 0) { + debugger; + var deviceGroups = policyPayloadObj.deviceGroups; + var assignedGroups = []; + for (var index in deviceGroups) { + if (deviceGroups.hasOwnProperty(index)) { + assignedGroups.push(deviceGroups[index].name); + } + } + $("#policy-groups").text(assignedGroups.toString().split(",").join(", ")); + } else { + $("#policy-groups").text("NONE"); + } - // if (policyPayloadObj.roles.length > 0) { - // $("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", ")); - // } else { - // $("#roles-row").addClass("hidden"); - // } + if (policyPayloadObj.roles == null) { + $("#policy-roles").text("NONE"); + } + else if (policyPayloadObj.roles.length > 0) { + $("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", ")); + } else { + $("#roles-row").addClass("hidden"); + } var deviceType = policy["platform"]; var policyOperationsTemplateSrc = context + '/public/cdmf.unit.device.type.' + deviceType + 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 3e2078ad11..98be922a1c 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 @@ -43,7 +43,7 @@ 8 20 - Merged + Simple 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 44d131dea2..e48531dd83 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 @@ -46,7 +46,7 @@ - Merged + Simple android ios