|
|
@ -16,17 +16,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
package cdm.api.android;
|
|
|
|
package cdm.api.android;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cdm.api.android.common.AndroidAgentException;
|
|
|
|
import cdm.api.android.util.AndroidAPIUtils;
|
|
|
|
import cdm.api.android.util.AndroidAPIUtils;
|
|
|
|
import cdm.api.android.util.AndroidConstants;
|
|
|
|
|
|
|
|
import cdm.api.android.util.Message;
|
|
|
|
import cdm.api.android.util.Message;
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
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.PrivilegedCarbonContext;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementServiceException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementService;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
import javax.ws.rs.*;
|
|
|
@ -39,186 +38,171 @@ import javax.ws.rs.core.Response;
|
|
|
|
@Consumes({ "application/json", "application/xml" })
|
|
|
|
@Consumes({ "application/json", "application/xml" })
|
|
|
|
public class Enrollment {
|
|
|
|
public class Enrollment {
|
|
|
|
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(Enrollment.class);
|
|
|
|
private static Log log = LogFactory.getLog(Enrollment.class);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
|
|
|
|
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
|
|
|
|
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
|
|
|
|
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
|
|
|
|
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
|
|
|
|
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
|
|
|
|
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
|
|
|
|
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
|
|
|
|
* {"name":"osVersion","value":"5.0.0"}]}
|
|
|
|
* {"name":"osVersion","value":"5.0.0"}]}
|
|
|
|
*
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
public Message enrollDevice(Device device) {
|
|
|
|
public Message enrollDevice(org.wso2.carbon.device.mgt.common.Device device) throws AndroidAgentException {
|
|
|
|
|
|
|
|
|
|
|
|
boolean result = false;
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
int status = 0;
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
String msg = "";
|
|
|
|
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
try {
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
} finally {
|
|
|
|
log.error(errorMsg, deviceServiceMgtEx);
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (dmService != null) {
|
|
|
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
device.setType(
|
|
|
|
dmService.enrollDevice(device);
|
|
|
|
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
Response.status(HttpStatus.SC_CREATED);
|
|
|
|
result = dmService.enrollDevice(device);
|
|
|
|
responseMsg.setResponseMessage("Device enrollment succeeded");
|
|
|
|
Response.status(HttpStatus.SC_CREATED);
|
|
|
|
return responseMsg;
|
|
|
|
responseMsg.setResponseMessage("Device enrollment has succeeded");
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
|
|
|
|
String errorMsg = "Error occurred while enrolling the device";
|
|
|
|
} else {
|
|
|
|
log.error(errorMsg, deviceMgtEx);
|
|
|
|
responseMsg.setResponseMessage(
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceMgtEx);
|
|
|
|
AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
|
|
|
|
}
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
@GET
|
|
|
|
log.error(msg, e);
|
|
|
|
@Path("{id}")
|
|
|
|
responseMsg.setResponseMessage("Error occurred while enrolling the device");
|
|
|
|
public Message isEnrolled(@PathParam("id") String id) throws AndroidAgentException {
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
boolean result;
|
|
|
|
}
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
@GET
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
@Path("{id}")
|
|
|
|
|
|
|
|
public Message isEnrolled(@PathParam("id") String id) {
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
boolean result = false;
|
|
|
|
log.error(errorMsg, deviceServiceMgtEx);
|
|
|
|
String msg = "";
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
}
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
try {
|
|
|
|
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
try {
|
|
|
|
} finally {
|
|
|
|
result = dmService.isEnrolled(deviceIdentifier);
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
if (result) {
|
|
|
|
}
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
responseMsg.setResponseMessage("Device has already enrolled");
|
|
|
|
try {
|
|
|
|
} else {
|
|
|
|
if (dmService != null) {
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
result = dmService.isEnrolled(deviceIdentifier);
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
if (result) {
|
|
|
|
}
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage("Device has already enrolled");
|
|
|
|
return responseMsg;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
responseMsg.setResponseMessage("Device has not enrolled");
|
|
|
|
String errormsg = "Error occurred while enrollment of the device.";
|
|
|
|
}
|
|
|
|
log.error(errormsg, deviceMgtEx);
|
|
|
|
return responseMsg;
|
|
|
|
throw new AndroidAgentException(errormsg, deviceMgtEx);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage(
|
|
|
|
}
|
|
|
|
AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
/*
|
|
|
|
}
|
|
|
|
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
|
|
|
|
msg = "Error occurred while checking the enrollment of the device.";
|
|
|
|
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
|
|
|
|
log.error(msg, e);
|
|
|
|
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
* {"name":"osVersion","value":"5.0.0"}]}
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
*
|
|
|
|
return responseMsg;
|
|
|
|
**/
|
|
|
|
}
|
|
|
|
@PUT
|
|
|
|
|
|
|
|
@Path("{id}")
|
|
|
|
}
|
|
|
|
public Message modifyEnrollment(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device)
|
|
|
|
|
|
|
|
throws AndroidAgentException {
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
|
|
|
|
boolean result;
|
|
|
|
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
|
|
|
|
|
|
|
|
* {"name":"osVersion","value":"5.0.0"}]}
|
|
|
|
try {
|
|
|
|
*
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
**/
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|
@Path("{id}")
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
public Message modifyEnrollment(@PathParam("id") String id, Device device) {
|
|
|
|
log.error(errorMsg, deviceServiceMgtEx);
|
|
|
|
boolean result = false;
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
|
|
|
|
String msg = "";
|
|
|
|
}
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
try {
|
|
|
|
|
|
|
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
try {
|
|
|
|
result = dmService.modifyEnrollment(device);
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
if (result) {
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
responseMsg.setResponseMessage("Device enrollment has updated successfully");
|
|
|
|
}
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
responseMsg.setResponseMessage("device not found for enrollment");
|
|
|
|
if (dmService != null) {
|
|
|
|
Response.status(HttpStatus.SC_NOT_MODIFIED);
|
|
|
|
device.setType(
|
|
|
|
}
|
|
|
|
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
|
|
|
|
result = dmService.modifyEnrollment(device);
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
responseMsg.setResponseMessage("Device enrollment has updated successfully");
|
|
|
|
String errorMsg = "Error occurred while modifying enrollment of the device";
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
} else {
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
responseMsg.setResponseMessage("Update enrollment has failed");
|
|
|
|
responseMsg.setResponseMessage(errorMsg);
|
|
|
|
Response.status(HttpStatus.SC_NOT_MODIFIED);
|
|
|
|
return responseMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
@DELETE
|
|
|
|
}
|
|
|
|
@Path("{id}")
|
|
|
|
return responseMsg;
|
|
|
|
public Message disenrollDevice(@PathParam("id") String id) throws AndroidAgentException {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
msg = "Error occurred while modifying enrollment of the device";
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
log.error(msg, e);
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
boolean result;
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|
@DELETE
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
@Path("{id}")
|
|
|
|
log.error(errorMsg, deviceServiceMgtEx);
|
|
|
|
public Message disenrollDevice(@PathParam("id") String id) {
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
|
|
|
|
|
|
|
|
}
|
|
|
|
boolean result = false;
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
String msg = "";
|
|
|
|
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
try {
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
result = dmService.disenrollDevice(deviceIdentifier);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
try {
|
|
|
|
responseMsg.setResponseMessage("Device has disenrolled successfully");
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
} finally {
|
|
|
|
} else {
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
}
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (dmService != null) {
|
|
|
|
return responseMsg;
|
|
|
|
result = dmService.disenrollDevice(deviceIdentifier);
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
if (result) {
|
|
|
|
String errorMsg = "Error occurred while dis enrolling the device";
|
|
|
|
responseMsg.setResponseMessage("Device has disenrolled successfully");
|
|
|
|
log.error(errorMsg, deviceMgtEx);
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
} else {
|
|
|
|
responseMsg.setResponseMessage(errorMsg);
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
return responseMsg;
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
msg = "Error occurred while disenrolling the device";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|