syncing admin api from product emm

merge-requests/7/head
inosh 9 years ago
parent 9ec80bfe18
commit 60b42715d6

@ -52,7 +52,6 @@ public interface Certificate {
* @return Status of the data persist operation. * @return Status of the data persist operation.
*/ */
@POST @POST
@Path("saveCertificate")
@ApiOperation( @ApiOperation(
consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, consumes = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,
produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML, produces = MediaType.APPLICATION_JSON + ", " + MediaType.APPLICATION_XML,

@ -186,10 +186,7 @@ public interface Operation {
@ApiResponses(value = {@ApiResponse(code = 200, message = "Activity details provided successfully.."), @ApiResponses(value = {@ApiResponse(code = 200, message = "Activity details provided successfully.."),
@ApiResponse(code = 500, message = "Error occurred while fetching the activity for the supplied id.")}) @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"}) @Permission(scope = "operation-view", permissions = {"/permission/admin/device-mgt/admin/devices/view"})
Response getActivity( Response getActivity(@ApiParam(name = "id", value = "Provide activity id {id} as ACTIVITY_(number)",
@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)",
required = true) @PathParam("id") String id) required = true) @PathParam("id") String id)
throws MDMAPIException; throws MDMAPIException;

@ -280,4 +280,9 @@ public interface Policy {
required = true) @PathParam("type") String type, required = true) @PathParam("type") String type,
@ApiParam(name = "id", value = "Define the device ID as the value for {id}.", @ApiParam(name = "id", value = "Define the device ID as the value for {id}.",
required = true) @PathParam("id") String 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);
} }

@ -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.common.PaginationResult;
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; 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.beans.EnrollmentCertificate;
import org.wso2.carbon.device.mgt.jaxrs.exception.BadRequestException;
import org.wso2.carbon.device.mgt.jaxrs.exception.Message; import org.wso2.carbon.device.mgt.jaxrs.exception.Message;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -65,7 +66,6 @@ public class CertificateImpl implements Certificate {
* @return Status of the data persist operation. * @return Status of the data persist operation.
*/ */
@POST @POST
@Path("saveCertificate")
public Response saveCertificate(@HeaderParam("Accept") String acceptHeader, public Response saveCertificate(@HeaderParam("Accept") String acceptHeader,
EnrollmentCertificate[] enrollmentCertificates) { EnrollmentCertificate[] enrollmentCertificates) {
MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader); MediaType responseMediaType = DeviceMgtAPIUtils.getResponseMediaType(acceptHeader);
@ -97,7 +97,6 @@ public class CertificateImpl implements Certificate {
* @param serialNumber serial of the certificate needed. * @param serialNumber serial of the certificate needed.
* @return certificate response. * @return certificate response.
*/ */
@GET
@Path("{serialNumber}") @Path("{serialNumber}")
public Response getCertificate(@HeaderParam("Accept") String acceptHeader, public Response getCertificate(@HeaderParam("Accept") String acceptHeader,
@PathParam("serialNumber") String serialNumber) { @PathParam("serialNumber") String serialNumber) {
@ -111,14 +110,11 @@ public class CertificateImpl implements Certificate {
} }
CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService(); CertificateManagementService certificateService = DeviceMgtAPIUtils.getCertificateManagementService();
CertificateResponse certificateResponse; List<CertificateResponse> certificateResponse;
try { try {
certificateResponse = certificateService.getCertificateBySerial(serialNumber); certificateResponse = certificateService.searchCertificates(serialNumber);
if(certificateResponse != null) {
certificateResponse.setCertificate(null); //avoid sending byte array in response.
}
return Response.status(Response.Status.OK).entity(certificateResponse).type(responseMediaType).build(); 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"; String msg = "Error occurred while converting PEM file to X509Certificate";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type(responseMediaType).build(); 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<CertificateResponse> 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 @DELETE
@Path("{serialNumber}") @Path("{serialNumber}")
public Response removeCertificate(@HeaderParam("Accept") String acceptHeader, public Response removeCertificate(@HeaderParam("Accept") String acceptHeader,

@ -235,13 +235,13 @@ public class OperationImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Opera
@Override @Override
@GET @GET
@Path("activity/{id}") @Path("activity/{id}")
public Response getActivity(@PathParam("type") String type, @PathParam("id") String id) public Response getActivity(@PathParam("id") String id)
throws MDMAPIException { throws MDMAPIException {
org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation; org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation;
DeviceManagementProviderService dmService; DeviceManagementProviderService dmService;
try { try {
dmService = DeviceMgtAPIUtils.getDeviceManagementService(); dmService = DeviceMgtAPIUtils.getDeviceManagementService();
operation = dmService.getOperationByActivityId(type, id); operation = dmService.getOperationByActivityId(id);
} catch (OperationManagementException e) { } catch (OperationManagementException e) {
String msg = "Error occurred while fetching the activity for the supplied id."; String msg = "Error occurred while fetching the activity for the supplied id.";
log.error(msg, e); log.error(msg, e);

@ -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.Device;
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.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.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.common.MDMAPIException;
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper; 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.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.jaxrs.api.util.ResponsePayload; import org.wso2.carbon.device.mgt.jaxrs.api.util.ResponsePayload;
import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper; 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.PolicyAdministratorPoint;
import org.wso2.carbon.policy.mgt.common.PolicyManagementException; import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; 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 @GET
@Path("{type}/{id}/active-policy") @Path("{type}/{id}/active-policy")
public Response getDeviceActivePolicy(@PathParam("type") String type, @PathParam("id") String id) { public Response getDeviceActivePolicy(@PathParam("type") String type, @PathParam("id") String id) {
try { try {
DeviceIdentifier deviceIdentifier = DeviceMgtAPIUtils.instantiateDeviceIdentifier(type, id); 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(); 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<DeviceGroupWrapper> groupWrappers = new ArrayList<>();
GroupManagementProviderService service = DeviceMgtAPIUtils.getGroupManagementProviderService();
List<DeviceGroup> 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();
}
}
} }

@ -937,21 +937,31 @@
<!-- Certificate related APIs --> <!-- Certificate related APIs -->
<Permission> <Permission>
<name>Save certificate in the database</name> <name>Save certificate in the database</name>
<path>/device-mgt/android/certificate/save</path> <path>/device-mgt/emm-admin/certificate/save</path>
<url>/certificates/saveCertificate</url> <url>/certificates</url>
<method>POST</method> <method>POST</method>
<scope>emm_admin</scope>
</Permission> </Permission>
<Permission> <Permission>
<name>get certificate in the database</name> <name>get certificate in the database</name>
<path>/device-mgt/android/certificate/view</path> <path>/device-mgt/emm-admin/certificate/Get</path>
<url>/certificates/*</url> <url>/certificates/*</url>
<method>GET</method> <method>GET</method>
<scope>emm_admin</scope>
</Permission> </Permission>
<Permission> <Permission>
<name>Remove certificate in the database</name> <name>get certificate in the database</name>
<path>/device-mgt/android/certificate/remove</path> <path>/device-mgt/emm-admin/certificate/GetAll</path>
<url>/certificates</url>
<method>GET</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>get certificate in the database</name>
<path>/device-mgt/emm-admin/certificate/Get</path>
<url>/certificates/*</url> <url>/certificates/*</url>
<method>DELETE</method> <method>DELETE</method>
<scope>emm_admin</scope>
</Permission> </Permission>
<!-- End of Certificate related APIs --> <!-- End of Certificate related APIs -->

@ -19,11 +19,19 @@
package org.wso2.carbon.policy.mgt.common; 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 { public class DeviceGroupWrapper {
@ApiModelProperty(name = "id", value = "Id of the group", required = true)
private int id; private int id;
@ApiModelProperty(name = "name", value = "Name of the group.", required = true)
private String name; private String name;
@ApiModelProperty(name = "owner", value = "Creator of the group", required = true)
private String owner; private String owner;
@ApiModelProperty(name = "tenant ID", value = "To which tenant id the group belongs to.", required = true)
private int tenantId; private int tenantId;
public int getId() { public int getId() {

Loading…
Cancel
Save