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/FileTransfer.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/FileTransfer.java new file mode 100644 index 0000000000..7cca854a05 --- /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/FileTransfer.java @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2017, 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.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.AndroidOperation; + +import java.io.Serializable; + + +@ApiModel(value = "FileTransfer", + description = "This class carries all information related to device lock operation.") +public class FileTransfer extends AndroidOperation implements Serializable { +//todo + @ApiModelProperty(name = "message", value = "Pop up message of the lock operation.", required = false) + private String message; + @ApiModelProperty(name = "isHardLockEnabled", value = "Hard lock enable status of the Device", required = true) + + public String getFielLocation() { + return message; + } + + public void setFileLocation(String message) { + this.message = message; + } + + +} 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/FileTransferBeanWrapper.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/FileTransferBeanWrapper.java new file mode 100644 index 0000000000..4794b05d75 --- /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/FileTransferBeanWrapper.java @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2017, 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.mdm.services.android.bean.wrapper; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.mdm.services.android.bean.DeviceLock; + +import java.util.List; + + + +/** + * This class is used to wrap the Notification bean with devices. + */ +@ApiModel(value = "FileTransferBeanWrapper", + description = "FileTransfer related Information.") +public class FileTransferBeanWrapper{ + + @ApiModelProperty(name = "deviceIDs", value = "Device id list of the operation to be executed.", required = true) + private List deviceIDs; + @ApiModelProperty(name = "operation", value = "Information of the Device lock operation.", required = true) + private FileTransfer operation; + + public List getDeviceIDs() { + return deviceIDs; + } + + public void setDeviceIDs(List deviceIDs) { + this.deviceIDs = deviceIDs; + } + + public FileTransfer getOperation() { + return operation; + } + + public void setOperation(FileTransfer operation) { + this.operation = operation; + } + +} 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 f3c3c72b10..2a653b22ce 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 @@ -216,11 +216,85 @@ import java.util.List; description = "Setting a Web Clip on Android Devices", key = "perm:android:set-webclip", permissions = {"/device-mgt/devices/owning-device/operations/android/webclip"} + ), + @Scope( + name = "File Transfer", + description = "Transferring a file to android devices", + key = "perm:android:file-transfer", + permissions = {"/device-mgt/devices/owning-device/operations/android/file-transfer"} ) } ) public interface DeviceManagementAdminService { + /////////////////////// + @POST + @Path("/file-transfer") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + httpMethod = "POST", + //todo + value = "Adding a Screen Lock on Android devices", + notes = "Using this API you have the option of hard locking an Android device, where the Administrator " + + "permanently locks the device or screen locking an Android device.", + //// + response = Activity.class, + tags = "Android Device Management Administrative Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = AndroidConstants.SCOPE, value = "perm:android:file-transfer") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + //todo + message = "Created. \n Successfully scheduled the device lock 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.", + 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.\n"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while locking the device.") + }) + Response fileTransfer( + @ApiParam( + name = "fileTransfer", + //todo + value = "Provide the ID of the Android device, the message that needs to be sent out when locking the device, " + + "and define true as the value if you need to hard lock the device or define false as the value to " + + "screen lock the device." + + "Multiple device IDs can be added by using comma separated values. ", + required = true) FileTransferBeanWrapper fileTransferBeanWrapper); +//////////////////////////////////// @POST @Path("/lock-devices") @ApiOperation( 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 22182b5b1e..537b543726 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 @@ -43,21 +43,7 @@ import org.wso2.carbon.mdm.services.android.bean.Vpn; import org.wso2.carbon.mdm.services.android.bean.WebClip; import org.wso2.carbon.mdm.services.android.bean.Wifi; import org.wso2.carbon.mdm.services.android.bean.WipeData; -import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationInstallationBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUninstallationBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.ApplicationUpdateBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.BlacklistApplicationsBeanWrapper; -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.LockCodeBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.NotificationBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.PasswordPolicyBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.UpgradeFirmwareBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.VpnBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.WebClipBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.WifiBeanWrapper; -import org.wso2.carbon.mdm.services.android.bean.wrapper.WipeDataBeanWrapper; +import org.wso2.carbon.mdm.services.android.bean.wrapper.*; import org.wso2.carbon.mdm.services.android.exception.BadRequestException; import org.wso2.carbon.mdm.services.android.exception.UnexpectedServerErrorException; import org.wso2.carbon.mdm.services.android.services.DeviceManagementAdminService; @@ -87,7 +73,49 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe private static final Log log = LogFactory.getLog(DeviceManagementAdminServiceImpl.class); private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; +///////////////////////////////////////////////////////////////////////////////////// +@POST +@Path("/file-transfer") +@Override +public Response fileTransfer(FileTransferBeanWrapper fileTransferBeanWrapper) { + if (log.isDebugEnabled()) { + log.debug("Invoking Android device lock operation"); + } + + try { + if (fileTransferBeanWrapper == null || fileTransferBeanWrapper.getOperation() == null) { + String errorMessage = "Lock bean is empty."; + log.error(errorMessage); + throw new BadRequestException( + new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build()); + } + FileTransfer file = fileTransferBeanWrapper.getOperation(); + ProfileOperation operation = new ProfileOperation(); + operation.setCode(AndroidConstants.OperationCodes.DEVICE_LOCK); + operation.setType(Operation.Type.PROFILE); + operation.setEnabled(true); + operation.setPayLoad(file.toJSON()); + return AndroidAPIUtils.getOperationResponse(fileTransferBeanWrapper.getDeviceIDs(), operation); + } 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()); + } catch (DeviceManagementException e) { + String errorMessage = "Issue in retrieving device management service instance"; + log.error(errorMessage, e); + throw new UnexpectedServerErrorException( + new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(errorMessage).build()); + } +} + + /////////////////////////////////////////////////////////// @POST @Path("/lock-devices") @Override