diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java index 56ec881e924..b4efa5d9853 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Certificate.java @@ -52,7 +52,6 @@ public interface Certificate { * @return Status of the data persist operation. */ @POST - @Path("saveCertificate") @ApiOperation( consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java index 759046bff8a..cac074c852e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Operation.java @@ -186,10 +186,7 @@ public interface Operation { @ApiResponses(value = {@ApiResponse(code = 200, message = "Activity details provided successfully.."), @ApiResponse(code = 500, message = "Error occurred while fetching the activity for the supplied id.")}) @Permission(scope = "operation-view", permissions = {"/permission/admin/device-mgt/admin/devices/view"}) - Response getActivity( - @ApiParam(name = "type", value = "Provide device {type} upon which the activity was performed", - required = true) @PathParam("type") String type, - @ApiParam(name = "id", value = "Provide activity id {id} as ACTIVITY_(number)", + Response getActivity(@ApiParam(name = "id", value = "Provide activity id {id} as ACTIVITY_(number)", required = true) @PathParam("id") String id) throws MDMAPIException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java index 7067eb19f67..5ee6e3633a6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/Policy.java @@ -280,4 +280,9 @@ public interface Policy { required = true) @PathParam("type") String type, @ApiParam(name = "id", value = "Define the device ID as the value for {id}.", required = true) @PathParam("id") String id); + + //TODO: This API is still not in use, but will be needed when grouping is implemented. + @GET + @Path("/device-group/{user}") + public Response getDeviceGroupsRelatedToPolicies(@PathParam("user") String userName); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/CertificateImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/CertificateImpl.java index de062241f96..d0d231bf719 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/CertificateImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/CertificateImpl.java @@ -31,6 +31,7 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.beans.EnrollmentCertificate; +import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException; import org.wso2.carbon.device.mgt.jaxrs.exception.Message; import javax.ws.rs.Consumes; @@ -65,7 +66,6 @@ public class CertificateImpl implements Certificate { * @return Status of the data persist operation. */ @POST - @Path("saveCertificate") public Response saveCertificate(@HeaderParam("Accept") String acceptHeader, EnrollmentCertificate[] enrollmentCertificates) { MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader); @@ -97,7 +97,6 @@ public class CertificateImpl implements Certificate { * @param serialNumber serial of the certificate needed. * @return certificate response. */ - @GET @Path("{serialNumber}") public Response getCertificate(@HeaderParam("Accept") String acceptHeader, @PathParam("serialNumber") String serialNumber) { @@ -111,14 +110,11 @@ public class CertificateImpl implements Certificate { } CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService(); - CertificateResponse certificateResponse; + List certificateResponse; try { - certificateResponse = certificateService.getCertificateBySerial(serialNumber); - if(certificateResponse != null) { - certificateResponse.setCertificate(null); //avoid sending byte array in response. - } + certificateResponse = certificateService.searchCertificates(serialNumber); return Response.status(Response.Status.OK).entity(certificateResponse).type(responseMediaType).build(); - } catch (KeystoreException e) { + } catch (CertificateManagementDAOException e) { String msg = "Error occurred while converting PEM file to X509Certificate"; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); @@ -164,6 +160,28 @@ public class CertificateImpl implements Certificate { } } + /** + * Get all certificates + * + * @return certificate details in an array. + * @throws MDMAPIException + */ + @GET + public Response getAllCertificates(@HeaderParam("Accept") String acceptHeader) + throws MDMAPIException { + MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader); + + CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService(); + try { + List certificates = certificateService.getCertificates(); + return Response.status(Response.Status.OK).entity(certificates).type(responseMediaType).build(); + } catch (CertificateManagementDAOException e) { + String msg = "Error occurred while fetching all certificates."; + log.error(msg, e); + throw new MDMAPIException(msg, e); + } + } + @DELETE @Path("{serialNumber}") public Response removeCertificate(@HeaderParam("Accept") String acceptHeader, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java index 2fb043bfd36..686b6844566 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/OperationImpl.java @@ -235,13 +235,13 @@ public class OperationImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Opera @Override @GET @Path("activity/{id}") - public Response getActivity(@PathParam("type") String type, @PathParam("id") String id) + public Response getActivity(@PathParam("id") String id) throws MDMAPIException { org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation; DeviceManagementProviderService dmService; try { dmService = DeviceMgtAPIUtils.getDeviceManagementService(); - operation = dmService.getOperationByActivityId(type, id); + operation = dmService.getOperationByActivityId(id); } catch (OperationManagementException e) { String msg = "Error occurred while fetching the activity for the supplied id."; log.error(msg, e); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/PolicyImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/PolicyImpl.java index 5947b5ec4a8..a06e986d120 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/PolicyImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/api/impl/PolicyImpl.java @@ -25,7 +25,10 @@ import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; 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.group.mgt.DeviceGroup; +import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; +import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.jaxrs.api.common.MDMAPIException; import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper; @@ -33,6 +36,7 @@ import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtUtil; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.jaxrs.api.util.ResponsePayload; import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper; +import org.wso2.carbon.policy.mgt.common.DeviceGroupWrapper; import org.wso2.carbon.policy.mgt.common.PolicyAdministratorPoint; import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; @@ -447,9 +451,9 @@ public class PolicyImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Policy { } } - @Override + @Override @GET - @Path("{type}/{id}/active-policy") + @Path("{type}/{id}/active-policy") public Response getDeviceActivePolicy(@PathParam("type") String type, @PathParam("id") String id) { try { DeviceIdentifier deviceIdentifier = DeviceMgtAPIUtils.instantiateDeviceIdentifier(type, id); @@ -463,4 +467,35 @@ public class PolicyImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Policy { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } + + @GET + @Path("/device-group/{user}") + public Response getDeviceGroupsRelatedToPolicies(@PathParam("user") String userName) { + try { + List groupWrappers = new ArrayList<>(); + GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService(); + List deviceGroups = service.getGroups(userName); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + for (DeviceGroup dg : deviceGroups) { + DeviceGroupWrapper gw = new DeviceGroupWrapper(); + gw.setId(dg.getId()); + gw.setOwner(dg.getOwner()); + gw.setName(dg.getName()); + gw.setTenantId(tenantId); + groupWrappers.add(gw); + } + + ResponsePayload responsePayload = new ResponsePayload(); + responsePayload.setStatusCode(HttpStatus.SC_OK); + responsePayload.setMessageFromServer("Sending all retrieved device groups."); + responsePayload.setResponseContent(groupWrappers); + return Response.status(HttpStatus.SC_OK).entity(groupWrappers).build(); + + } catch (GroupManagementException e) { + String error = "Error occurred while getting the groups related to users for policy."; + log.error(error, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); + } + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml index b06dc5fb4f4..1e41474c9af 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/META-INF/permissions.xml @@ -937,21 +937,31 @@ Save certificate in the database - /device-mgt/android/certificate/save - /certificates/saveCertificate + /device-mgt/emm-admin/certificate/save + /certificates POST + emm_admin get certificate in the database - /device-mgt/android/certificate/view + /device-mgt/emm-admin/certificate/Get /certificates/* GET + emm_admin - Remove certificate in the database - /device-mgt/android/certificate/remove + get certificate in the database + /device-mgt/emm-admin/certificate/GetAll + /certificates + GET + emm_admin + + + get certificate in the database + /device-mgt/emm-admin/certificate/Get /certificates/* DELETE + emm_admin diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/DeviceGroupWrapper.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/DeviceGroupWrapper.java index cd6c63b40a1..aee0576a4cb 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/DeviceGroupWrapper.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/DeviceGroupWrapper.java @@ -19,11 +19,19 @@ package org.wso2.carbon.policy.mgt.common; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +@ApiModel(value = "DeviceGroupWrapper", description = "This class carries all information related to device groups") public class DeviceGroupWrapper { + @ApiModelProperty(name = "id", value = "Id of the group", required = true) private int id; + @ApiModelProperty(name = "name", value = "Name of the group.", required = true) private String name; + @ApiModelProperty(name = "owner", value = "Creator of the group", required = true) private String owner; + @ApiModelProperty(name = "tenant ID", value = "To which tenant id the group belongs to.", required = true) private int tenantId; public int getId() {