|
|
@ -39,175 +39,186 @@ 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":"ww","ownership":"ww",
|
|
|
|
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
|
|
|
|
* "properties":[{"name":"username","value":"ww"},{"name":"device","value":"ww"},
|
|
|
|
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
|
|
|
|
* {"name":"imei","value":"imei"},{"name":"imsi","value":"imsi"},{"name":"model","value":"mi3"},
|
|
|
|
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
|
|
|
|
* {"name":"regId","value":"regid"},{"name":"vendor","value":"vendor"},
|
|
|
|
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
|
|
|
|
* {"name":"osVersion","value":"Lolipop"}]}
|
|
|
|
* {"name":"osVersion","value":"5.0.0"}]}
|
|
|
|
*
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
public Message enrollDevice(Device device) {
|
|
|
|
public Message enrollDevice(Device device) {
|
|
|
|
|
|
|
|
|
|
|
|
boolean result = false;
|
|
|
|
boolean result = false;
|
|
|
|
int status = 0;
|
|
|
|
int status = 0;
|
|
|
|
String msg = "";
|
|
|
|
String msg = "";
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (dmService != null) {
|
|
|
|
if (dmService != null) {
|
|
|
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
device.setType(
|
|
|
|
result = dmService.enrollDevice(device);
|
|
|
|
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
Response.status(HttpStatus.SC_CREATED);
|
|
|
|
result = dmService.enrollDevice(device);
|
|
|
|
responseMsg.setResponseMessage("Device enrollment has succeeded");
|
|
|
|
Response.status(HttpStatus.SC_CREATED);
|
|
|
|
return responseMsg;
|
|
|
|
responseMsg.setResponseMessage("Device enrollment has succeeded");
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage(AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
|
|
|
|
} else {
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
responseMsg.setResponseMessage(
|
|
|
|
return responseMsg;
|
|
|
|
AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
|
|
|
|
}
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
return responseMsg;
|
|
|
|
log.error(msg, e);
|
|
|
|
}
|
|
|
|
responseMsg.setResponseMessage("Error occurred while enrolling the device");
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
log.error(msg, e);
|
|
|
|
return responseMsg;
|
|
|
|
responseMsg.setResponseMessage("Error occurred while enrolling the device");
|
|
|
|
}
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
}
|
|
|
|
@Path("{id}")
|
|
|
|
|
|
|
|
public Message isEnrolled(@PathParam("id") String id) {
|
|
|
|
@GET
|
|
|
|
|
|
|
|
@Path("{id}")
|
|
|
|
boolean result = false;
|
|
|
|
public Message isEnrolled(@PathParam("id") String id) {
|
|
|
|
String msg = "";
|
|
|
|
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
boolean result = false;
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
String msg = "";
|
|
|
|
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
try {
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
if (dmService != null) {
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
result = dmService.isEnrolled(deviceIdentifier);
|
|
|
|
try {
|
|
|
|
if (result) {
|
|
|
|
if (dmService != null) {
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
result = dmService.isEnrolled(deviceIdentifier);
|
|
|
|
responseMsg.setResponseMessage("Device already enroll");
|
|
|
|
if (result) {
|
|
|
|
} else {
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage("Device has already enrolled");
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
} else {
|
|
|
|
responseMsg.setResponseMessage("Device not enroll");
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
}
|
|
|
|
responseMsg.setResponseMessage("Device has not enrolled");
|
|
|
|
return responseMsg;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return responseMsg;
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
} else {
|
|
|
|
responseMsg.setResponseMessage(AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
return responseMsg;
|
|
|
|
responseMsg.setResponseMessage(
|
|
|
|
}
|
|
|
|
AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
return responseMsg;
|
|
|
|
msg = "Error occurred while checking enrollment of the device";
|
|
|
|
}
|
|
|
|
log.error(msg, e);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
msg = "Error occurred while checking the enrollment of the device.";
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
log.error(msg, e);
|
|
|
|
return responseMsg;
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
}
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
}
|
|
|
|
@Path("{id}")
|
|
|
|
|
|
|
|
public Message modifyEnrollment(@PathParam("id") String id, Device device) {
|
|
|
|
/*
|
|
|
|
boolean result = false;
|
|
|
|
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
|
|
|
|
String msg = "";
|
|
|
|
* "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();
|
|
|
|
**/
|
|
|
|
} finally {
|
|
|
|
@PUT
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
@Path("{id}")
|
|
|
|
}
|
|
|
|
public Message modifyEnrollment(@PathParam("id") String id, Device device) {
|
|
|
|
|
|
|
|
boolean result = false;
|
|
|
|
try {
|
|
|
|
String msg = "";
|
|
|
|
if (dmService != null) {
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
result = dmService.modifyEnrollment(device);
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
try {
|
|
|
|
responseMsg.setResponseMessage("update device");
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
} finally {
|
|
|
|
}else{
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
responseMsg.setResponseMessage("Update enrollment has failed");
|
|
|
|
}
|
|
|
|
Response.status(HttpStatus.SC_NOT_MODIFIED);
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
} else {
|
|
|
|
if (dmService != null) {
|
|
|
|
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
|
|
|
device.setType(
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
result = dmService.modifyEnrollment(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
if (result) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
responseMsg.setResponseMessage("Device enrollment has updated successfully");
|
|
|
|
msg = "Error occurred while modifying enrollment of the device";
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
log.error(msg, e);
|
|
|
|
} else {
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
responseMsg.setResponseMessage("Update enrollment has failed");
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
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) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
msg = "Error occurred while modifying enrollment of the device";
|
|
|
|
boolean result = false;
|
|
|
|
log.error(msg, e);
|
|
|
|
String msg = "";
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
@DELETE
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
@Path("{id}")
|
|
|
|
}
|
|
|
|
public Message disenrollDevice(@PathParam("id") String id) {
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
|
|
|
|
try {
|
|
|
|
boolean result = false;
|
|
|
|
if (dmService != null) {
|
|
|
|
String msg = "";
|
|
|
|
result = dmService.disenrollDevice(deviceIdentifier);
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
if (result) {
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
responseMsg.setResponseMessage("Dis enrolled device");
|
|
|
|
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
try {
|
|
|
|
}else{
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
} finally {
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
try {
|
|
|
|
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
|
|
|
if (dmService != null) {
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
result = dmService.disenrollDevice(deviceIdentifier);
|
|
|
|
}
|
|
|
|
if (result) {
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage("Device has disenrolled successfully");
|
|
|
|
return responseMsg;
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} else {
|
|
|
|
msg = "Error occurred while disenrolling the device";
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
log.error(msg, e);
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
}
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
} else {
|
|
|
|
return responseMsg;
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|