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 000000000..5414a1407 --- /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,125 @@ +/* + * 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 org.apache.commons.lang.StringUtils; + +import java.io.Serializable; + +/** + * 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 = "proxyConfigType", + value = "Type of the proxy", + required = true + ) + private ProxyType proxyConfigType; + + @ApiModelProperty( + name = "proxyHost", + value = "The hostname of the proxy server" + ) + private String proxyHost; + + @ApiModelProperty( + name = "proxyPort", + value = "The port which the proxy server is running" + ) + private int proxyPort; + + @ApiModelProperty( + name = "proxyExclList", + value = "Hosts to exclude using the proxy on connections for. These hosts can use wildcards such as " + + "*.example.com" + ) + private String proxyExclList; + + @ApiModelProperty( + name = "proxyPacUrl", + value = "PAC file URL to auto config proxy" + ) + private String proxyPacUrl; + + public boolean validateRequest() { + if (ProxyType.MANUAL.equals(this.proxyConfigType)) { + if (StringUtils.isEmpty(this.proxyHost)) { + return false; + } + if (this.proxyPort < 0 || this.proxyPort > 65535) { + return false; + } + } else if (ProxyType.AUTO.equals(this.proxyConfigType)) { + if (StringUtils.isEmpty(proxyPacUrl)) { + return false; + } + } + return false; + } + + public ProxyType getProxyConfigType() { + return proxyConfigType; + } + + public void setProxyConfigType(ProxyType proxyConfigType) { + this.proxyConfigType = proxyConfigType; + } + + public String getProxyHost() { + return proxyHost; + } + + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + public int getProxyPort() { + return proxyPort; + } + + public void setProxyPort(int proxyPort) { + this.proxyPort = proxyPort; + } + + public String getProxyExclList() { + return proxyExclList; + } + + public void setProxyExclList(String proxyExclList) { + this.proxyExclList = proxyExclList; + } + + public String getProxyPacUrl() { + return proxyPacUrl; + } + + public void setProxyPacUrl(String proxyPacUrl) { + this.proxyPacUrl = proxyPacUrl; + } +} 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/ProxyType.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/ProxyType.java new file mode 100644 index 000000000..3fdc4e1ba --- /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/ProxyType.java @@ -0,0 +1,5 @@ +package org.wso2.carbon.mdm.services.android.bean; + +public enum ProxyType { + MANUAL, AUTO +} 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 000000000..1063ee260 --- /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 c8bd68d9c..998503b13 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; @@ -193,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", @@ -1834,5 +1857,65 @@ public interface DeviceManagementAdminService { required = true) WebClipBeanWrapper webClipBeanWrapper); - + @POST + @Path("/configure-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:configure-global-proxy") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully scheduled the 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 b50e4b4ad..0941a66a9 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,53 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe } } + @POST + @Path("/configure-global-proxy") + @Override + public Response setRecommendedGlobalProxy(GlobalProxyBeanWrapper globalProxyBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Applying 'configure-global-proxy' operation: " + + globalProxyBeanWrapper.getOperation().toJSON() + " for Devices: [" + + String.join(",", globalProxyBeanWrapper.getDeviceIDs()) + "]"); + } + + try { + if (globalProxyBeanWrapper == null || globalProxyBeanWrapper.getOperation() == null) { + 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()); + } + + GlobalProxy globalProxy = globalProxyBeanWrapper.getOperation(); + if (globalProxy.validateRequest()) { + 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(); + } else { + 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()); + } + } 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 b33c6bb89..cc3af5e30 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 { 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 4b510a304..556dbb03d 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 = { + "proxyConfigType": operationPayload["proxyConfigType"], + "proxyHost": operationPayload["proxyHost"], + "proxyPort": operationPayload["proxyPort"], + "proxyExclList": operationPayload["proxyExclList"], + "proxyPacUrl": operationPayload["proxyPacUrl"] + }; + break; case androidOperationConstants["VPN_OPERATION_CODE"]: payload = { "serverAddress": operationPayload["serverAddress"], @@ -310,6 +321,18 @@ var androidOperationModule = function () { } }; break; + case androidOperationConstants["GLOBAL_PROXY_OPERATION_CODE"]: + operationType = operationTypeConstants["PROFILE"]; + payload = { + "operation": { + "proxyConfigType": operationData["proxyConfigType"], + "proxyHost": operationData["proxyHost"], + "proxyPort": operationData["proxyPort"], + "proxyExclList": operationData["proxyExclList"], + "proxyPacUrl": operationData["proxyPacUrl"] + } + }; + break; case androidOperationConstants["VPN_OPERATION_CODE"]: operationType = operationTypeConstants["PROFILE"]; payload = { @@ -433,6 +456,7 @@ var androidOperationModule = function () { publicMethods.getAndroidServiceEndpoint = function (operationCode) { var featureMap = { "WIFI": "configure-wifi", + "GLOBAL_PROXY": "configure-global-proxy", "CAMERA": "control-camera", "VPN": "configure-vpn", "DEVICE_LOCK": "lock-devices", @@ -455,7 +479,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 cc151761f..b19525b04 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,69 @@ 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; + + 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; + } + } 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 + // 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"]; @@ -777,6 +842,36 @@ 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; + var pane; + for (var i = 0; i < valueSet.length; ++i) { + if (selectedValueOnChange !== valueSet[i]) { + pane = paneSelector + valueSet[i].toLowerCase(); + if ($(pane).hasClass("expanded")) { + $(pane).removeClass("expanded"); + } + $(pane).slideUp(); + } else { + pane = paneSelector + selectedValueOnChange.toLowerCase(); + if (!$(pane).hasClass("expanded")) { + $(pane).addClass("expanded"); + } + $(pane).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 82f09727b..df8ca218c 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,132 @@ + +
+
+ +
+
+
+
+ +
+ 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. +
+
+ + +
+ + +
+
+
+ + +
+
+ + + +
+
+ + +
+
+ +
+
+
+ +
Wifi Setting up wifi configuration + + Global Proxy + Setting up a network-independent global HTTP proxy on a device. + Camera Enable or disable camera