Reporting permission API

reporting
Inosh Perara 5 years ago committed by Charitha Goonetilleke
parent ebbae0a6eb
commit bea3a1c8dd

@ -107,6 +107,12 @@ import java.util.List;
description = "Getting Details of Device tenants",
key = "perm:admin:tenant:view",
permissions = {"/device-mgt/devices/tenants/view"}
),
@Scope(
name = "Add a permission to the permission tree",
description = "Add a permission to the permission tree",
key = "perm:admin:permissions:add",
permissions = {"/device-mgt/devices/permissions/add"}
)
}
)
@ -410,4 +416,49 @@ public interface DeviceManagementAdminService {
response = ErrorResponse.class)
})
Response getTenants();
@POST
@Path("/permissions")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Add permission to the tree",
notes = "Add permission to the tree.",
tags = "Device Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value =
"perm:admin:permissions:add")
})
}
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK. \n Successfully update the owner of devices.",
response = DeviceList.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 was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 400,
message = "The incoming request has more than one selection criteria defined via the query parameters.",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching " +
"adding permission to the tree.",
response = ErrorResponse.class)
})
Response addPermission(List<String> permissions);
}

@ -46,6 +46,8 @@ import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.exceptions.UserNotFoundException;
import org.wso2.carbon.device.mgt.common.general.TenantDetail;
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException;
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
@ -62,6 +64,7 @@ import javax.validation.constraints.Size;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@ -243,4 +246,31 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
"for super tenant admin only.").build();
}
}
@POST
@Path("/permissions")
@Produces({MediaType.APPLICATION_JSON})
public Response addPermission(List<String> permissions) {
String PERMISSION_PREFIX = "/permission/admin";
PermissionManagerService permissionService = DeviceMgtAPIUtils.getPermissionManagerService();
org.wso2.carbon.device.mgt.common.permission.mgt.Permission permission = new org
.wso2.carbon.device.mgt.common.permission.mgt.Permission();
for (String path : permissions) {
path = PERMISSION_PREFIX + path;
permission.setPath(path);
permission.setUrl(path);
try {
permissionService.addPermission(permission);
} catch (PermissionManagementException e) {
String msg = "Error occurred adding permission";
log.error(msg, e);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
}
return Response.status(Response.Status.OK).build();
}
}

@ -46,6 +46,7 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementService;
import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagerService;
import org.wso2.carbon.device.mgt.common.report.mgt.ReportManagementService;
import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
@ -468,6 +469,16 @@ public class DeviceMgtAPIUtils {
return searchManagerService;
}
public static PermissionManagerService getPermissionManagerService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
PermissionManagerService PermissionManagerService =
(PermissionManagerService) ctx.getOSGiService(PermissionManagerService.class, null);
if (PermissionManagerService == null) {
throw new IllegalStateException("Permission manager service is not initialized.");
}
return PermissionManagerService;
}
public static GeoLocationProviderService getGeoService() {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
GeoLocationProviderService

Loading…
Cancel
Save