mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'release-2.0.x' of https://github.com/wso2/carbon-device-mgt into release-2.0.x
This commit is contained in:
commit
f1954c4f10
@ -201,8 +201,8 @@
|
|||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>org.json.wso2</groupId>
|
||||||
<artifactId>gson</artifactId>
|
<artifactId>json</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec.wso2</groupId>
|
<groupId>commons-codec.wso2</groupId>
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import io.swagger.annotations.ApiParam;
|
|||||||
import io.swagger.annotations.ApiResponse;
|
import io.swagger.annotations.ApiResponse;
|
||||||
import io.swagger.annotations.ApiResponses;
|
import io.swagger.annotations.ApiResponses;
|
||||||
import io.swagger.annotations.ResponseHeader;
|
import io.swagger.annotations.ResponseHeader;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
import org.wso2.carbon.apimgt.annotations.api.Scope;
|
||||||
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
import org.wso2.carbon.apimgt.annotations.api.Scopes;
|
||||||
import org.wso2.carbon.device.mgt.common.Device;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
@ -330,19 +331,20 @@ public interface DeviceManagementService {
|
|||||||
@HeaderParam("If-Modified-Since")
|
@HeaderParam("If-Modified-Since")
|
||||||
String ifModifiedSince);
|
String ifModifiedSince);
|
||||||
|
|
||||||
//device delete request would looks like follows
|
//device rename request would looks like follows
|
||||||
//DELETE devices/type/virtual_firealarm/id/us06ww93auzp
|
//POST devices/type/virtual_firealarm/id/us06ww93auzp/rename
|
||||||
@DELETE
|
@POST
|
||||||
@Path("/type/{device-type}/id/{device-id}")
|
@Path("/type/{device-type}/id/{device-id}/rename")
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
produces = MediaType.APPLICATION_JSON,
|
produces = MediaType.APPLICATION_JSON,
|
||||||
httpMethod = "DELETE",
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
value = "Delete the device specified by device id",
|
httpMethod = "POST",
|
||||||
notes = "Returns the status of the deleted device operation.",
|
value = "Update the device specified by device id",
|
||||||
|
notes = "Returns the status of the updated device operation.",
|
||||||
tags = "Device Management",
|
tags = "Device Management",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:delete")
|
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:update")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -383,8 +385,12 @@ public interface DeviceManagementService {
|
|||||||
"Server error occurred while retrieving information requested device.",
|
"Server error occurred while retrieving information requested device.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
//TODO need to introduce delete permission
|
Response renameDevice(
|
||||||
Response deleteDevice(
|
@ApiParam(
|
||||||
|
name = "device",
|
||||||
|
value = "The payload containing new name for device with updated name.",
|
||||||
|
required = true)
|
||||||
|
Device device,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "device-type",
|
name = "device-type",
|
||||||
value = "The device type, such as ios, android or windows.",
|
value = "The device type, such as ios, android or windows.",
|
||||||
@ -400,6 +406,75 @@ public interface DeviceManagementService {
|
|||||||
@Size(max = 45)
|
@Size(max = 45)
|
||||||
String deviceId);
|
String deviceId);
|
||||||
|
|
||||||
|
//device remove request would looks like follows
|
||||||
|
//DELETE devices/type/virtual_firealarm/id/us06ww93auzp
|
||||||
|
@DELETE
|
||||||
|
@Path("/type/{device-type}/id/{device-id}")
|
||||||
|
@ApiOperation(
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "DELETE",
|
||||||
|
value = "Remove the device specified by device id",
|
||||||
|
notes = "Returns the status of the deleted device operation.",
|
||||||
|
tags = "Device Management",
|
||||||
|
extensions = {
|
||||||
|
@Extension(properties = {
|
||||||
|
@ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:delete")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
|
@ApiResponses(
|
||||||
|
value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Successfully deleted the device.",
|
||||||
|
response = Device.class,
|
||||||
|
responseHeaders = {
|
||||||
|
@ResponseHeader(
|
||||||
|
name = "Content-Type",
|
||||||
|
description = "The 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 has been modified the last time.\n" +
|
||||||
|
"Used by caches, or in conditional requests."),
|
||||||
|
}),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 304,
|
||||||
|
message = "Not Modified. Empty body because the client already has the latest " +
|
||||||
|
"version of the requested resource."),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 400,
|
||||||
|
message = "Bad Request. \n Invalid request or validation error.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 404,
|
||||||
|
message = "Not Found. \n No device is found under the provided type and id.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n " +
|
||||||
|
"Server error occurred while retrieving information requested device.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
Response deleteDevice(
|
||||||
|
@ApiParam(
|
||||||
|
name = "device-type",
|
||||||
|
value = "The device type, such as ios, android or windows.",
|
||||||
|
required = true)
|
||||||
|
@PathParam("device-type")
|
||||||
|
@Size(max = 45)
|
||||||
|
String deviceType,
|
||||||
|
@ApiParam(
|
||||||
|
name = "device-id",
|
||||||
|
value = "The device identifier of the device.",
|
||||||
|
required = true)
|
||||||
|
@PathParam("device-id")
|
||||||
|
@Size(max = 45)
|
||||||
|
String deviceId);
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Path("/{type}/{id}/features")
|
@Path("/{type}/{id}/features")
|
||||||
|
|||||||
@ -21,13 +21,22 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.*;
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Feature;
|
||||||
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
||||||
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
||||||
|
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
||||||
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
import org.wso2.carbon.device.mgt.common.search.SearchContext;
|
||||||
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
|
||||||
@ -40,15 +49,20 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList;
|
|||||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.Policy;
|
|
||||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData;
|
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException;
|
|
||||||
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
||||||
|
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import javax.ws.rs.*;
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.DELETE;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.HeaderParam;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.PathParam;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
@ -225,14 +239,47 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|||||||
@Override
|
@Override
|
||||||
@Path("/type/{device-type}/id/{device-id}")
|
@Path("/type/{device-type}/id/{device-id}")
|
||||||
public Response deleteDevice(@PathParam("device-type") String deviceType, @PathParam("device-id") String deviceId) {
|
public Response deleteDevice(@PathParam("device-type") String deviceType, @PathParam("device-id") String deviceId) {
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService =
|
||||||
log.info("Deleting " + deviceType + " " + deviceId + "is not supported");
|
DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
try {
|
try {
|
||||||
return Response.status(Response.Status.BAD_REQUEST).entity("{Deleting device(s) is not supported}").build();
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(deviceId, deviceType);
|
||||||
} catch (Exception e) {
|
Device persistedDevice = deviceManagementProviderService.getDevice(deviceIdentifier);
|
||||||
String msg = "Error occurred while deleting device(s)";
|
if (persistedDevice == null) {
|
||||||
log.error(msg, e);
|
return Response.status(Response.Status.NOT_FOUND).build();
|
||||||
return Response.serverError().entity(new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
}
|
||||||
|
|
||||||
|
boolean response = deviceManagementProviderService.disenrollDevice(deviceIdentifier);
|
||||||
|
return Response.status(Response.Status.OK).entity(response).build();
|
||||||
|
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
String msg = "Error encountered while deleting device of type : " + deviceType + " and " +
|
||||||
|
"ID : " + deviceId;
|
||||||
|
log.error(msg);
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()
|
||||||
|
).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Override
|
||||||
|
@Path("/type/{device-type}/id/{device-id}/rename")
|
||||||
|
public Response renameDevice(Device device, @PathParam("device-type") String deviceType,
|
||||||
|
@PathParam("device-id") String deviceId) {
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
|
try {
|
||||||
|
Device persistedDevice = deviceManagementProviderService.getDevice(new DeviceIdentifier
|
||||||
|
(deviceId, deviceType));
|
||||||
|
persistedDevice.setName(device.getName());
|
||||||
|
boolean response = deviceManagementProviderService.modifyEnrollment(persistedDevice);
|
||||||
|
return Response.status(Response.Status.CREATED).entity(response).build();
|
||||||
|
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
log.error("Error encountered while updating device of type : " + deviceType + " and " +
|
||||||
|
"ID : " + deviceId);
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST).entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setMessage("Error while updating " +
|
||||||
|
"device of type " + deviceType + " and ID : " + deviceId).build()).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -404,10 +404,15 @@ public class RoleManagementServiceImpl implements RoleManagementService {
|
|||||||
// Get all role permissions
|
// Get all role permissions
|
||||||
final UIPermissionNode rolePermissions = this.getAllRolePermissions(roleName, userRealm);
|
final UIPermissionNode rolePermissions = this.getAllRolePermissions(roleName, userRealm);
|
||||||
List<String> permissions = new ArrayList<String>();
|
List<String> permissions = new ArrayList<String>();
|
||||||
|
final UIPermissionNode emmRolePermissions = (UIPermissionNode)this.getRolePermissions(roleName);
|
||||||
|
List<String> emmConsolePermissions = new ArrayList<String>();
|
||||||
|
this.getAuthorizedPermissions(emmRolePermissions, emmConsolePermissions);
|
||||||
|
emmConsolePermissions.removeAll(new ArrayList<String>(Arrays.asList(roleInfo.getPermissions())));
|
||||||
this.getAuthorizedPermissions(rolePermissions, permissions);
|
this.getAuthorizedPermissions(rolePermissions, permissions);
|
||||||
for (String permission : roleInfo.getPermissions()) {
|
for (String permission : roleInfo.getPermissions()) {
|
||||||
permissions.add(permission);
|
permissions.add(permission);
|
||||||
}
|
}
|
||||||
|
permissions.removeAll(emmConsolePermissions);
|
||||||
String [] allApplicablePerms = new String[permissions.size()];
|
String [] allApplicablePerms = new String[permissions.size()];
|
||||||
allApplicablePerms = permissions.toArray(allApplicablePerms);
|
allApplicablePerms = permissions.toArray(allApplicablePerms);
|
||||||
roleInfo.setPermissions(allApplicablePerms);
|
roleInfo.setPermissions(allApplicablePerms);
|
||||||
|
|||||||
@ -90,6 +90,7 @@
|
|||||||
"perm:devices:operations",
|
"perm:devices:operations",
|
||||||
"perm:devices:search",
|
"perm:devices:search",
|
||||||
"perm:devices:details",
|
"perm:devices:details",
|
||||||
|
"perm:devices:update",
|
||||||
"perm:devices:view",
|
"perm:devices:view",
|
||||||
"perm:view-configuration",
|
"perm:view-configuration",
|
||||||
"perm:manage-configuration",
|
"perm:manage-configuration",
|
||||||
|
|||||||
@ -730,7 +730,7 @@ function attachDeviceEvents() {
|
|||||||
var deviceId = $(this).data("deviceid");
|
var deviceId = $(this).data("deviceid");
|
||||||
var deviceType = $(this).data("devicetype");
|
var deviceType = $(this).data("devicetype");
|
||||||
var deviceName = $(this).data("devicename");
|
var deviceName = $(this).data("devicename");
|
||||||
var serviceURL = "/api/device-mgt/v1.0/devices/type/" + deviceType + "/id/" + deviceId;
|
var serviceURL = "/api/device-mgt/v1.0/devices/type/" + deviceType + "/id/" + deviceId + "/rename";
|
||||||
|
|
||||||
$(modalPopupContent).html($('#edit-device-modal-content').html());
|
$(modalPopupContent).html($('#edit-device-modal-content').html());
|
||||||
$('#edit-device-name').val(deviceName);
|
$('#edit-device-name').val(deviceName);
|
||||||
@ -738,7 +738,9 @@ function attachDeviceEvents() {
|
|||||||
|
|
||||||
$("a#edit-device-yes-link").click(function () {
|
$("a#edit-device-yes-link").click(function () {
|
||||||
var newDeviceName = $('#edit-device-name').val();
|
var newDeviceName = $('#edit-device-name').val();
|
||||||
invokerUtil.put(serviceURL, {"name": newDeviceName}, function (message) {
|
var request = {};
|
||||||
|
request['name'] = newDeviceName;
|
||||||
|
invokerUtil.post(serviceURL, request, function (message) {
|
||||||
$(modalPopupContent).html($('#edit-device-200-content').html());
|
$(modalPopupContent).html($('#edit-device-200-content').html());
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
hidePopup();
|
hidePopup();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user