From 61210bd73eb78f6b3441166621c5b4b47665c1e7 Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Wed, 9 Jan 2019 20:26:08 +1100 Subject: [PATCH 1/8] Implement new API for the global proxy policy --- .../services/android/bean/GlobalProxy.java | 105 ++++++++++++++++++ .../bean/wrapper/GlobalProxyBeanWrapper.java | 66 +++++++++++ .../DeviceManagementAdminService.java | 100 +++++++++++++++-- .../DeviceManagementAdminServiceImpl.java | 80 +++++++++++-- .../android/util/AndroidConstants.java | 20 +++- 5 files changed, 346 insertions(+), 25 deletions(-) create mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/GlobalProxy.java create mode 100644 components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/GlobalProxyBeanWrapper.java diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/GlobalProxy.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/GlobalProxy.java new file mode 100644 index 0000000000..c2d2797010 --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/GlobalProxy.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mdm.services.android.bean; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +import java.util.List; + +/** + * This class represents the information of setting up global proxy + */ + +@ApiModel( + value = "GlobalProxy", + description = "This class represents the information of setting up global proxy" +) +public class GlobalProxy extends AndroidOperation implements Serializable { + + @ApiModelProperty(name = "host", value = "The hostname of the proxy server", required = true) + private String host; + + @ApiModelProperty( + name = "port", + value = "The port which the proxy server is running", + required = true) + private int port; + + @ApiModelProperty( + name = "excludedList", + value = "Hosts to exclude using the proxy on connections for. These hosts can use wildcards such as " + + "*.example.com" + ) + private List excludedList; + + @ApiModelProperty( + name = "username", + value = "Username of the proxy server" + ) + private String username; + + @ApiModelProperty( + name = "password", + value = "Password of the proxy server" + ) + private String password; + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public List getExcludedList() { + return excludedList; + } + + public void setExcludedList(List excludedList) { + this.excludedList = excludedList; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/GlobalProxyBeanWrapper.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/GlobalProxyBeanWrapper.java new file mode 100644 index 0000000000..1063ee260f --- /dev/null +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/bean/wrapper/GlobalProxyBeanWrapper.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.GlobalProxy; + +import java.util.List; + +/** + * This class is used to wrap the GlobalProxyPolicy bean with devices. + */ + +@ApiModel( + value = "GlobalProxyBeanWrapper", + description = "Mapping between global proxy settings and devices" +) +public class GlobalProxyBeanWrapper { + @ApiModelProperty( + name = "operation", + value = "Information of setting up global proxy", + required = true + ) + private GlobalProxy operation; + + @ApiModelProperty( + name = "deviceIDs", + value = "List of device Ids", + required = true) + private List deviceIDs; + + public GlobalProxy getOperation() { + return operation; + } + + public void setOperation(GlobalProxy operation) { + this.operation = operation; + } + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } +} + diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java index c8bd68d9ca..a981c408fe 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java @@ -1,19 +1,36 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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. + * 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. + * + * + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) 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.mdm.services.android.services; @@ -1834,5 +1851,64 @@ public interface DeviceManagementAdminService { required = true) WebClipBeanWrapper webClipBeanWrapper); - + @POST + @Path("/set-global-proxy") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Setting a network independent proxy recommendation on Android Devices", + notes = "Set global proxy on Android devices. All the network traffic will be routed through the proxy " + + "server regardless of the network the device is connected to.", + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:set-global-proxy") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the set global proxy operation.", + response = Activity.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "URL of the activity instance that refers to the scheduled operation."), + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.\n", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding the set global proxy operation.") + }) + Response setRecommendedGlobalProxy( + @ApiParam( + name = "globalProxyInfo", + value = "The properties to set the global proxy settings.", + required = true) + GlobalProxyBeanWrapper globalProxyBeanWrapper); } diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java index b50e4b4ad3..5bc879d665 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java @@ -1,19 +1,36 @@ /* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 + * 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. + * 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. + * + * + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) 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.mdm.services.android.services.impl; @@ -21,7 +38,6 @@ package org.wso2.carbon.mdm.services.android.services.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; @@ -37,6 +53,7 @@ import org.wso2.carbon.mdm.services.android.bean.DeviceEncryption; import org.wso2.carbon.mdm.services.android.bean.DeviceLock; import org.wso2.carbon.mdm.services.android.bean.ErrorResponse; import org.wso2.carbon.mdm.services.android.bean.FileTransfer; +import org.wso2.carbon.mdm.services.android.bean.GlobalProxy; import org.wso2.carbon.mdm.services.android.bean.LockCode; import org.wso2.carbon.mdm.services.android.bean.Notification; import org.wso2.carbon.mdm.services.android.bean.PasscodePolicy; @@ -53,6 +70,7 @@ import org.wso2.carbon.mdm.services.android.bean.wrapper.CameraBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.DeviceLockBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.EncryptionBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.FileTransferBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.GlobalProxyBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.LockCodeBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.NotificationBeanWrapper; import org.wso2.carbon.mdm.services.android.bean.wrapper.PasswordPolicyBeanWrapper; @@ -958,6 +976,44 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } } + @POST + @Path("/set-global-proxy") + @Override + public Response setRecommendedGlobalProxy(GlobalProxyBeanWrapper globalProxyBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking 'set-global-proxy' operation"); + } + + try { + if (globalProxyBeanWrapper == null || globalProxyBeanWrapper.getOperation() == null) { + String errorMessage = "The payload of the set global proxy operation is incorrect"; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400L).setMessage(errorMessage).build()); + } + + GlobalProxy globalProxy = globalProxyBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.GLOBAL_PROXY); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(globalProxy.toJSON()); + + Activity activity = AndroidDeviceUtils + .getOperationResponse(globalProxyBeanWrapper.getDeviceIDs(), operation); + return Response.status(Response.Status.CREATED).entity(activity).build(); + } catch (InvalidDeviceException e) { + String errorMessage = "Invalid Device Identifiers found."; + log.error(errorMessage, e); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400L).setMessage(errorMessage).build()); + } catch (OperationManagementException e) { + String errorMessage = "Issue in retrieving operation management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500L).setMessage(errorMessage).build()); + } + } + private static void validateApplicationUrl(String apkUrl) { try { URL url = new URL(apkUrl); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java index b33c6bb89d..cc3af5e303 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/util/AndroidConstants.java @@ -6,7 +6,24 @@ * in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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. + * + * + * Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) 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 @@ -122,6 +139,7 @@ public final class AndroidConstants { public static final String APP_RESTRICTION = "APP-RESTRICTION"; public static final String WORK_PROFILE = "WORK_PROFILE"; public static final String NOTIFIER_FREQUENCY = "NOTIFIER_FREQUENCY"; + public static final String GLOBAL_PROXY = "SET_GLOBAL_PROXY"; } public final class StatusCodes { From 2a959c39a76aa6a9b2a3a436ecdd8056852421f9 Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Sat, 12 Jan 2019 18:58:37 +1100 Subject: [PATCH 2/8] Add Android global proxy policy UI components Added UI components to create/edit and view global proxy settings. --- .../public/js/operation-mod.js | 35 +++++- .../public/js/android-policy-edit.js | 53 +++++++++ .../public/templates/android-policy-edit.hbs | 107 ++++++++++++++++++ .../public/templates/android-policy-view.hbs | 107 ++++++++++++++++++ .../public/js/android-policy-operations.js | 56 +++++++++ .../templates/android-policy-operations.hbs | 107 ++++++++++++++++++ 6 files changed, 461 insertions(+), 4 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js index 4b510a3040..2612025654 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js @@ -23,14 +23,15 @@ * in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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 + * "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 androidOperationModule = function () { @@ -51,6 +52,7 @@ var androidOperationModule = function () { "CAMERA_OPERATION_CODE": "CAMERA", "ENCRYPT_STORAGE_OPERATION_CODE": "ENCRYPT_STORAGE", "WIFI_OPERATION_CODE": "WIFI", + "GLOBAL_PROXY_OPERATION_CODE": "GLOBAL_PROXY", "WIPE_OPERATION_CODE": "WIPE_DATA", "NOTIFICATION_OPERATION_CODE": "NOTIFICATION", "WORK_PROFILE_CODE": "WORK_PROFILE", @@ -153,6 +155,15 @@ var androidOperationModule = function () { "wifiCaCertName": operationPayload["cacertName"] }; break; + case androidOperationConstants["GLOBAL_PROXY_OPERATION_CODE"]: + payload = { + "proxyHost": operationPayload["proxyHost"], + "proxyPort": operationPayload["proxyPort"], + "proxyExclList": operationPayload["proxyExclList"], + "proxyUsername": operationPayload["proxyUsername"], + "proxyPassword": operationPayload["proxyPassword"] + }; + break; case androidOperationConstants["VPN_OPERATION_CODE"]: payload = { "serverAddress": operationPayload["serverAddress"], @@ -310,6 +321,22 @@ var androidOperationModule = function () { } }; break; + case androidOperationConstants["GLOBAL_PROXY_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + var proxyExclList = []; + if (operationData["proxyExclList"]) { + proxyExclList = operationData["proxyExclList"].trim().split(/\s*,\s*/); + } + payload = { + "operation": { + "proxyHost": operationData["proxyHost"], + "proxyPort": operationData["proxyPort"], + "proxyExclList": proxyExclList, + "proxyUsername": operationData["proxyUsername"], + "proxyPassword": operationData["proxyPassword"] + } + }; + break; case androidOperationConstants["VPN_OPERATION_CODE"]: operationType = operationTypeConstants["PROFILE"]; payload = { @@ -433,6 +460,7 @@ var androidOperationModule = function () { publicMethods.getAndroidServiceEndpoint = function (operationCode) { var featureMap = { "WIFI": "configure-wifi", + "GLOBAL_PROXY": "set-global-proxy", "CAMERA": "control-camera", "VPN": "configure-vpn", "DEVICE_LOCK": "lock-devices", @@ -455,7 +483,6 @@ var androidOperationModule = function () { "ENTERPRISE_WIPE": "enterprise-wipe", "WIPE_DATA": "wipe" }; - //return "/mdm-android-agent/operation/" + featureMap[operationCode]; return "/api/device-mgt/android/v1.0/admin/devices/" + featureMap[operationCode]; }; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js index cc151761f9..63f26628be 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js @@ -45,6 +45,8 @@ var androidOperationConstants = { "ENCRYPT_STORAGE_OPERATION_CODE": "ENCRYPT_STORAGE", "WIFI_OPERATION": "wifi", "WIFI_OPERATION_CODE": "WIFI", + "GLOBAL_PROXY_OPERATION": "global-proxy", + "GLOBAL_PROXY_OPERATION_CODE": "GLOBAL_PROXY", "VPN_OPERATION": "vpn", "VPN_OPERATION_CODE": "VPN", "APPLICATION_OPERATION": "app-restriction", @@ -323,6 +325,57 @@ var validatePolicyProfile = function () { validationStatusArray.push(validationStatus); } + // Validating PROXY + if ($.inArray(androidOperationConstants["GLOBAL_PROXY_OPERATION_CODE"], configuredOperations) !== -1) { + // if PROXY is configured + operation = androidOperationConstants["GLOBAL_PROXY_OPERATION"]; + // initializing continueToCheckNextInputs to true + continueToCheckNextInputs = true; + + var proxyHost = $("input#proxy-host").val(); + var proxyPort = $("input#proxy-port").val(); + if (!proxyHost) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy server host name is required.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + + if (!proxyPort) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy server port is required.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!$.isNumeric(proxyPort)) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy server port requires a number input.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(proxyPort, 0, 65535)) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy 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 + }; + } + } + if ($.inArray(androidOperationConstants["VPN_OPERATION_CODE"], configuredOperations) != -1) { // if WIFI is configured operation = androidOperationConstants["VPN_OPERATION"]; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs index 82f09727be..e6771b2077 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs @@ -56,6 +56,17 @@ + + + + + Global Proxy Settings + + + + @@ -950,6 +961,102 @@ + +
+
+ +
+
+ Please note that * sign represents required fields of data. +
+
+ +
+ + +
+
+ + + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+ +
+ +
+
+ +
+
+ Please note that * sign represents required fields of data. +
+
+ +
+ + +
+
+ + + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+ +
+ +
+
+ +
+
+ Please note that * sign represents required fields of data. +
+
+ +
+ + +
+
+ + + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+ +
Date: Wed, 23 Jan 2019 14:43:27 +1100 Subject: [PATCH 3/8] Improve global proxy policy config UI Improve the policy config ui to support auto config proxy using a pac file url --- .../public/js/operation-mod.js | 14 +- .../public/js/android-policy-edit.js | 101 +++++++---- .../public/templates/android-policy-edit.hbs | 164 ++++++++++++------ .../public/js/android-policy-view.js | 27 +++ .../public/templates/android-policy-view.hbs | 162 +++++++++++------ .../public/js/android-policy-operations.js | 101 +++++++---- .../templates/android-policy-operations.hbs | 164 ++++++++++++------ 7 files changed, 498 insertions(+), 235 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js index 2612025654..de615926de 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js @@ -157,11 +157,13 @@ var androidOperationModule = function () { break; case androidOperationConstants["GLOBAL_PROXY_OPERATION_CODE"]: payload = { + "proxyConfigType": operationPayload["proxyConfigType"], "proxyHost": operationPayload["proxyHost"], "proxyPort": operationPayload["proxyPort"], "proxyExclList": operationPayload["proxyExclList"], "proxyUsername": operationPayload["proxyUsername"], - "proxyPassword": operationPayload["proxyPassword"] + "proxyPassword": operationPayload["proxyPassword"], + "proxyPacUrl": operationPayload["proxyPacUrl"] }; break; case androidOperationConstants["VPN_OPERATION_CODE"]: @@ -323,17 +325,15 @@ var androidOperationModule = function () { break; case androidOperationConstants["GLOBAL_PROXY_OPERATION_CODE"]: operationType = operationTypeConstants["PROFILE"]; - var proxyExclList = []; - if (operationData["proxyExclList"]) { - proxyExclList = operationData["proxyExclList"].trim().split(/\s*,\s*/); - } payload = { "operation": { + "proxyConfigType": operationData["proxyConfigType"], "proxyHost": operationData["proxyHost"], "proxyPort": operationData["proxyPort"], - "proxyExclList": proxyExclList, + "proxyExclList": operationData["proxyExclList"], "proxyUsername": operationData["proxyUsername"], - "proxyPassword": operationData["proxyPassword"] + "proxyPassword": operationData["proxyPassword"], + "proxyPacUrl": operationData["proxyPacUrl"] } }; break; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js index 63f26628be..d68fbb54c2 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/js/android-policy-edit.js @@ -332,38 +332,50 @@ var validatePolicyProfile = function () { // initializing continueToCheckNextInputs to true continueToCheckNextInputs = true; - var proxyHost = $("input#proxy-host").val(); - var proxyPort = $("input#proxy-port").val(); - if (!proxyHost) { - validationStatus = { - "error": true, - "subErrorMsg": "Proxy server host name is required.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } + if ($("input#manual-proxy-configuration-radio-button").is(":checked")) { + var proxyHost = $("input#proxy-host").val(); + var proxyPort = $("input#proxy-port").val(); + if (!proxyHost) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy server host name is required.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } - if (!proxyPort) { - validationStatus = { - "error": true, - "subErrorMsg": "Proxy server port is required.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!$.isNumeric(proxyPort)) { - validationStatus = { - "error": true, - "subErrorMsg": "Proxy server port requires a number input.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(proxyPort, 0, 65535)) { - validationStatus = { - "error": true, - "subErrorMsg": "Proxy server port is not within the range of valid port numbers.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; + if (!proxyPort) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy server port is required.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!$.isNumeric(proxyPort)) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy server port requires a number input.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(proxyPort, 0, 65535)) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy server port is not within the range of valid port numbers.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } else if ($("input#auto-proxy-configuration-radio-button").is(":checked")) { + var pacFileUrl = $("input#proxy-pac-url").val(); + if (!pacFileUrl) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy pac file URL is required for proxy auto config.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } } // at-last, if the value of continueToCheckNextInputs is still true @@ -830,6 +842,33 @@ var slideDownPaneAgainstValueSetForRadioButtons = function (selectElement, paneI $(paneSelector).addClass("hidden"); } }; + +/** + * Method to switch panes based on the selected radio button. + * + * The method will un hide the element with the id (paneIdPrefix + selectElement.value) + * + * @param selectElement selected HTML element + * @param paneIdPrefix prefix of the id of the pane to un hide. + * @param valueSet applicable value set + */ +var switchPaneAgainstValueSetForRadioButtons = function (selectElement, paneIdPrefix, valueSet) { + var selectedValueOnChange = selectElement.value; + var paneSelector = "#" + paneIdPrefix; + for (var i = 0; i < valueSet.length; ++i) { + if (selectedValueOnChange !== valueSet[i]) { + if ($(paneSelector).hasClass("expanded")) { + $(paneSelector).removeClass("expanded"); + } + $(paneSelector + valueSet[i]).slideUp(); + } else { + if (!$(paneSelector).hasClass("expanded")) { + $(paneSelector).addClass("expanded"); + } + $(paneSelector + selectedValueOnChange).slideDown(); + } + } +}; // End of HTML embedded invoke methods diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs index e6771b2077..4a692358c6 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs @@ -979,79 +979,133 @@ device. Once this configuration profile is installed on a device, all the network traffic will be routed through the proxy server.

-

- This method requires the caller to be the device owner. -

-

- This proxy is only a recommendation and it is possible that some apps will ignore it. -


+
+
+ +
Please note that * sign represents required fields of data.

-
- - -
-
- -
diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/js/android-policy-view.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/js/android-policy-view.js index 0dba7a2ed6..7afcd4b661 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/js/android-policy-view.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/js/android-policy-view.js @@ -166,6 +166,33 @@ var slideDownPaneAgainstValueSetForRadioButtons = function (selectElement, paneI $(paneSelector).addClass("hidden"); } }; + +/** + * Method to switch panes based on the selected radio button. + * + * The method will un hide the element with the id (paneIdPrefix + selectElement.value) + * + * @param selectElement selected HTML element + * @param paneIdPrefix prefix of the id of the pane to un hide. + * @param valueSet applicable value set + */ +var switchPaneAgainstValueSetForRadioButtons = function (selectElement, paneIdPrefix, valueSet) { + var selectedValueOnChange = selectElement.value; + var paneSelector = "#" + paneIdPrefix; + for (var i = 0; i < valueSet.length; ++i) { + if (selectedValueOnChange !== valueSet[i]) { + if ($(paneSelector).hasClass("expanded")) { + $(paneSelector).removeClass("expanded"); + } + $(paneSelector + valueSet[i]).slideUp(); + } else { + if (!$(paneSelector).hasClass("expanded")) { + $(paneSelector).addClass("expanded"); + } + $(paneSelector + selectedValueOnChange).slideDown(); + } + } +}; // End of HTML embedded invoke methods /** diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/templates/android-policy-view.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/templates/android-policy-view.hbs index eb70333884..1cce8875bd 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/templates/android-policy-view.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/templates/android-policy-view.hbs @@ -968,7 +968,8 @@
-
+

+ +
+ +
Please note that * sign represents required fields of data.

-
- - -
-
- -
diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js index 09f1838c29..19d522c3dc 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js @@ -251,38 +251,50 @@ var validatePolicyProfile = function () { // initializing continueToCheckNextInputs to true continueToCheckNextInputs = true; - var proxyHost = $("input#proxy-host").val(); - var proxyPort = $("input#proxy-port").val(); - if (!proxyHost) { - validationStatus = { - "error": true, - "subErrorMsg": "Proxy server host name is required.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } + if ($("input#manual-proxy-configuration-radio-button").is(":checked")) { + var proxyHost = $("input#proxy-host").val(); + var proxyPort = $("input#proxy-port").val(); + if (!proxyHost) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy server host name is required.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } - if (!proxyPort) { - validationStatus = { - "error": true, - "subErrorMsg": "Proxy server port is required.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - }else if (!$.isNumeric(proxyPort)) { - validationStatus = { - "error": true, - "subErrorMsg": "Proxy server port requires a number input.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; - } else if (!inputIsValidAgainstRange(proxyPort, 0, 65535)) { - validationStatus = { - "error": true, - "subErrorMsg": "Proxy server port is not within the range of valid port numbers.", - "erroneousFeature": operation - }; - continueToCheckNextInputs = false; + if (!proxyPort) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy server port is required.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!$.isNumeric(proxyPort)) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy server port requires a number input.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } else if (!inputIsValidAgainstRange(proxyPort, 0, 65535)) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy server port is not within the range of valid port numbers.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } + } else if ($("input#auto-proxy-configuration-radio-button").is(":checked")) { + var pacFileUrl = $("input#proxy-pac-url").val(); + if (!pacFileUrl) { + validationStatus = { + "error": true, + "subErrorMsg": "Proxy pac file URL is required for proxy auto config.", + "erroneousFeature": operation + }; + continueToCheckNextInputs = false; + } } // at-last, if the value of continueToCheckNextInputs is still true @@ -795,6 +807,33 @@ var slideDownPaneAgainstValueSetForRadioButtons = function (selectElement, paneI } }; +/** + * Method to switch panes based on the selected radio button. + * + * The method will un hide the element with the id (paneIdPrefix + selectElement.value) + * + * @param selectElement selected HTML element + * @param paneIdPrefix prefix of the id of the pane to un hide. + * @param valueSet applicable value set + */ +var switchPaneAgainstValueSetForRadioButtons = function (selectElement, paneIdPrefix, valueSet) { + var selectedValueOnChange = selectElement.value; + var paneSelector = "#" + paneIdPrefix; + for (var i = 0; i < valueSet.length; ++i) { + if (selectedValueOnChange !== valueSet[i]) { + if ($(paneSelector).hasClass("expanded")) { + $(paneSelector).removeClass("expanded"); + } + $(paneSelector + valueSet[i]).slideUp(); + } else { + if (!$(paneSelector).hasClass("expanded")) { + $(paneSelector).addClass("expanded"); + } + $(paneSelector + selectedValueOnChange).slideDown(); + } + } +}; + // End of HTML embedded invoke methods diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs index 5c51b323bb..3764052246 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs @@ -1003,79 +1003,133 @@ device. Once this configuration profile is installed on a device, all the network traffic will be routed through the proxy server.

-

- This method requires the caller to be the device owner. -

-

- This proxy is only a recommendation and it is possible that some apps will ignore it. -


+ +
+ +
Please note that * sign represents required fields of data.

-
- - -
-
- -
From 9c220a5b44145eda85190ea8e327d1380ae45722 Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Thu, 24 Jan 2019 22:02:12 +1100 Subject: [PATCH 4/8] Add permission for global proxy operation & refactor Refactored API path for global-proxy operation and add permissions and scopes to the API --- .../services/DeviceManagementAdminService.java | 13 ++++++++++--- .../impl/DeviceManagementAdminServiceImpl.java | 6 +++--- .../public/js/operation-mod.js | 2 +- .../private/config.json | 1 + 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java index a981c408fe..998503b13b 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/DeviceManagementAdminService.java @@ -210,6 +210,12 @@ import java.util.List; key = "perm:android:configure-wifi", permissions = {"/device-mgt/devices/owning-device/operations/android/wifi"} ), + @Scope( + name = "Configure Global Proxy", + description = "Configure Global Proxy on Android Device", + key = "perm:android:configure-global-proxy", + permissions = {"/device-mgt/devices/owning-device/operations/android/global-proxy"} + ), @Scope( name = "Encrypt Storage", description = "Encrypting storage on Android Device", @@ -1852,7 +1858,7 @@ public interface DeviceManagementAdminService { WebClipBeanWrapper webClipBeanWrapper); @POST - @Path("/set-global-proxy") + @Path("/configure-global-proxy") @ApiOperation( consumes = MediaType.APPLICATION_JSON, httpMethod = "POST", @@ -1863,14 +1869,15 @@ public interface DeviceManagementAdminService { tags = "Android Device Management Administrative Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:set-global-proxy") + @ExtensionProperty(name = AndroidConstants.SCOPE, + value = "perm:android:configure-global-proxy") }) } ) @ApiResponses(value = { @ApiResponse( code = 201, - message = "Created. \n Successfully scheduled the set global proxy operation.", + message = "Created. \n Successfully scheduled the global proxy operation.", response = Activity.class, responseHeaders = { @ResponseHeader( diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java index 5bc879d665..042d81c116 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.api/src/main/java/org/wso2/carbon/mdm/services/android/services/impl/DeviceManagementAdminServiceImpl.java @@ -977,16 +977,16 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } @POST - @Path("/set-global-proxy") + @Path("/configure-global-proxy") @Override public Response setRecommendedGlobalProxy(GlobalProxyBeanWrapper globalProxyBeanWrapper) { if (log.isDebugEnabled()) { - log.debug("Invoking 'set-global-proxy' operation"); + log.debug("Invoking 'configure-global-proxy' operation"); } try { if (globalProxyBeanWrapper == null || globalProxyBeanWrapper.getOperation() == null) { - String errorMessage = "The payload of the set global proxy operation is incorrect"; + String errorMessage = "The payload of the global proxy operation is incorrect"; log.error(errorMessage); throw new BadRequestException( new ErrorResponse.ErrorResponseBuilder().setCode(400L).setMessage(errorMessage).build()); diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js index de615926de..6821ab1ecd 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.operation-mod/public/js/operation-mod.js @@ -460,7 +460,7 @@ var androidOperationModule = function () { publicMethods.getAndroidServiceEndpoint = function (operationCode) { var featureMap = { "WIFI": "configure-wifi", - "GLOBAL_PROXY": "set-global-proxy", + "GLOBAL_PROXY": "configure-global-proxy", "CAMERA": "control-camera", "VPN": "configure-vpn", "DEVICE_LOCK": "lock-devices", diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/private/config.json b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/private/config.json index e6ab55c5d7..1f8a820102 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/private/config.json +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.type-view/private/config.json @@ -13,6 +13,7 @@ "perm:android:lock-devices", "perm:android:configure-vpn", "perm:android:configure-wifi", + "perm:android:configure-global-proxy", "perm:android:enroll", "perm:android:uninstall-application", "perm:android:manage-configuration", From 09bc51c5e0d94ad09925cd9888b20530dcdada0c Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Tue, 29 Jan 2019 10:57:34 +1100 Subject: [PATCH 5/8] Fix issue with displaying configured policy info This commit fixes the issue by engaging an onclick event to radio buttons to display the correct div of data --- .../public/templates/android-policy-edit.hbs | 12 ++++-------- .../public/templates/android-policy-view.hbs | 4 ++++ .../public/templates/android-policy-operations.hbs | 12 ++++-------- .../src/main/resources/devicetypes/android.xml | 4 ++++ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs index 4a692358c6..510f0a3cb7 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-edit/public/templates/android-policy-edit.hbs @@ -1015,11 +1015,9 @@ - + onclick="switchPaneAgainstValueSetForRadioButtons(this, + 'global-proxy-configuration-type-', ['manual','auto'])"/> + Manual @@ -1027,9 +1025,7 @@ diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/templates/android-policy-view.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/templates/android-policy-view.hbs index 1cce8875bd..cc72989801 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/templates/android-policy-view.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-view/public/templates/android-policy-view.hbs @@ -1020,6 +1020,8 @@
-
- - -
-
- - -
diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js index 19d522c3dc..27dedfa2e3 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/js/android-policy-operations.js @@ -819,17 +819,20 @@ var slideDownPaneAgainstValueSetForRadioButtons = function (selectElement, paneI var switchPaneAgainstValueSetForRadioButtons = function (selectElement, paneIdPrefix, valueSet) { var selectedValueOnChange = selectElement.value; var paneSelector = "#" + paneIdPrefix; + var pane; for (var i = 0; i < valueSet.length; ++i) { if (selectedValueOnChange !== valueSet[i]) { - if ($(paneSelector).hasClass("expanded")) { - $(paneSelector).removeClass("expanded"); + pane = paneSelector + valueSet[i].toLowerCase(); + if ($(pane).hasClass("expanded")) { + $(pane).removeClass("expanded"); } - $(paneSelector + valueSet[i]).slideUp(); + $(pane).slideUp(); } else { - if (!$(paneSelector).hasClass("expanded")) { - $(paneSelector).addClass("expanded"); + pane = paneSelector + selectedValueOnChange.toLowerCase(); + if (!$(pane).hasClass("expanded")) { + $(pane).addClass("expanded"); } - $(paneSelector + selectedValueOnChange).slideDown(); + $(pane).slideDown(); } } }; diff --git a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs index 89137a2324..466e486fc4 100644 --- a/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs +++ b/components/mobile-plugins/android-plugin/org.wso2.carbon.device.mgt.mobile.android.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.android.policy-wizard/public/templates/android-policy-operations.hbs @@ -1038,9 +1038,9 @@
-
- - -
-
- - -