syncing admin api from product emm

revert-70aa11f8
inosh 8 years ago
parent 9ec80bfe18
commit 60b42715d6

@ -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,

@ -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;

@ -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);
}

@ -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> 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<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
@Path("{serialNumber}")
public Response removeCertificate(@HeaderParam("Accept") String acceptHeader,

@ -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);

@ -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<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 -->
<Permission>
<name>Save certificate in the database</name>
<path>/device-mgt/android/certificate/save</path>
<url>/certificates/saveCertificate</url>
<path>/device-mgt/emm-admin/certificate/save</path>
<url>/certificates</url>
<method>POST</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<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>
<method>GET</method>
<scope>emm_admin</scope>
</Permission>
<Permission>
<name>Remove certificate in the database</name>
<path>/device-mgt/android/certificate/remove</path>
<name>get certificate in the database</name>
<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>
<method>DELETE</method>
<scope>emm_admin</scope>
</Permission>
<!-- End of Certificate related APIs -->

@ -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() {

Loading…
Cancel
Save