|
|
@ -1,32 +1,33 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
|
|
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* Version 2.0 (the "License"); you may not use this file except
|
|
|
|
|
|
|
|
* in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* limitations under the License.
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
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.*;
|
|
|
@ -41,163 +42,131 @@ 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",
|
|
|
|
|
|
|
|
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
|
|
|
|
|
|
|
|
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
|
|
|
|
|
|
|
|
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
|
|
|
|
|
|
|
|
* {"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;
|
|
|
|
|
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
String msg = "";
|
|
|
|
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
|
|
|
|
log.error(errorMsg, deviceServiceMgtEx);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
result = dmService.enrollDevice(device);
|
|
|
|
|
|
|
|
Response.status(HttpStatus.SC_CREATED);
|
|
|
|
Response.status(HttpStatus.SC_CREATED);
|
|
|
|
responseMsg.setResponseMessage("Device enrollment has succeeded");
|
|
|
|
responseMsg.setResponseMessage("Device enrollment succeeded");
|
|
|
|
return responseMsg;
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
responseMsg.setResponseMessage(
|
|
|
|
String errorMsg = "Error occurred while enrolling the device";
|
|
|
|
AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
|
|
|
|
log.error(errorMsg, deviceMgtEx);
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceMgtEx);
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage("Error occurred while enrolling the device");
|
|
|
|
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Path("{id}")
|
|
|
|
@Path("{id}")
|
|
|
|
public Message isEnrolled(@PathParam("id") String id) {
|
|
|
|
public Message isEnrolled(@PathParam("id") String id) throws AndroidAgentException {
|
|
|
|
|
|
|
|
|
|
|
|
boolean result = false;
|
|
|
|
boolean result;
|
|
|
|
String msg = "";
|
|
|
|
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
|
|
|
|
log.error(errorMsg, deviceServiceMgtEx);
|
|
|
|
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (dmService != null) {
|
|
|
|
|
|
|
|
result = dmService.isEnrolled(deviceIdentifier);
|
|
|
|
result = dmService.isEnrolled(deviceIdentifier);
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
responseMsg.setResponseMessage("Device has already enrolled");
|
|
|
|
responseMsg.setResponseMessage("Device has already enrolled");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
responseMsg.setResponseMessage("Device has not enrolled");
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage(
|
|
|
|
|
|
|
|
AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE);
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
msg = "Error occurred while checking the enrollment of the device.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
|
|
|
|
String errormsg = "Error occurred while enrollment of the device.";
|
|
|
|
|
|
|
|
log.error(errormsg, deviceMgtEx);
|
|
|
|
|
|
|
|
throw new AndroidAgentException(errormsg, deviceMgtEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Request Format : {"deviceIdentifier":"macid","description":"description","ownership":"BYOD",
|
|
|
|
|
|
|
|
* "properties":[{"name":"username","value":"harshan"},{"name":"device","value":"Harshan S5"},
|
|
|
|
|
|
|
|
* {"name":"imei","value":"356938035643809"},{"name":"imsi","value":"404685505601234"},{"name":"model","value":"Galaxy S5"},
|
|
|
|
|
|
|
|
* {"name":"regId","value":"02fab24b2242"},{"name":"vendor","value":"Samsung"},
|
|
|
|
|
|
|
|
* {"name":"osVersion","value":"5.0.0"}]}
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
@PUT
|
|
|
|
@Path("{id}")
|
|
|
|
@Path("{id}")
|
|
|
|
public Message modifyEnrollment(@PathParam("id") String id, Device device) {
|
|
|
|
public Message modifyEnrollment(@PathParam("id") String id, org.wso2.carbon.device.mgt.common.Device device)
|
|
|
|
boolean result = false;
|
|
|
|
throws AndroidAgentException {
|
|
|
|
String msg = "";
|
|
|
|
|
|
|
|
|
|
|
|
boolean result;
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
|
|
|
|
log.error(errorMsg, deviceServiceMgtEx);
|
|
|
|
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (dmService != null) {
|
|
|
|
device.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
device.setType(
|
|
|
|
|
|
|
|
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID);
|
|
|
|
|
|
|
|
result = dmService.modifyEnrollment(device);
|
|
|
|
result = dmService.modifyEnrollment(device);
|
|
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
responseMsg.setResponseMessage("Device enrollment has updated successfully");
|
|
|
|
responseMsg.setResponseMessage("Device enrollment has updated successfully");
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
Response.status(HttpStatus.SC_OK);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
responseMsg.setResponseMessage("Update enrollment has failed");
|
|
|
|
responseMsg.setResponseMessage("device not found for enrollment");
|
|
|
|
Response.status(HttpStatus.SC_NOT_MODIFIED);
|
|
|
|
Response.status(HttpStatus.SC_NOT_MODIFIED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
msg = AndroidConstants.Messages.DEVICE_MANAGER_SERVICE_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
msg = "Error occurred while modifying enrollment of the device";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
|
|
responseMsg.setResponseMessage(msg);
|
|
|
|
|
|
|
|
return responseMsg;
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
|
|
|
|
String errorMsg = "Error occurred while modifying enrollment of the device";
|
|
|
|
|
|
|
|
log.error(errorMsg, deviceMgtEx);
|
|
|
|
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceMgtEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@DELETE
|
|
|
|
@DELETE
|
|
|
|
@Path("{id}")
|
|
|
|
@Path("{id}")
|
|
|
|
public Message disenrollDevice(@PathParam("id") String id) {
|
|
|
|
public Message disEnrollDevice(@PathParam("id") String id) throws AndroidAgentException {
|
|
|
|
|
|
|
|
|
|
|
|
boolean result = false;
|
|
|
|
|
|
|
|
String msg = "";
|
|
|
|
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
DeviceManagementService dmService;
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
Message responseMsg = new Message();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean result;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
dmService = AndroidAPIUtils.getDeviceManagementService();
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
} catch (DeviceManagementServiceException deviceServiceMgtEx) {
|
|
|
|
|
|
|
|
String errorMsg = "Device management service error";
|
|
|
|
|
|
|
|
log.error(errorMsg, deviceServiceMgtEx);
|
|
|
|
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceServiceMgtEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
DeviceIdentifier deviceIdentifier = AndroidAPIUtils.convertToDeviceIdentifierObject(id);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (dmService != null) {
|
|
|
|
|
|
|
|
result = dmService.disenrollDevice(deviceIdentifier);
|
|
|
|
result = dmService.disenrollDevice(deviceIdentifier);
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
responseMsg.setResponseMessage("Device has disenrolled successfully");
|
|
|
|
responseMsg.setResponseMessage("Device has disenrolled successfully");
|
|
|
@ -206,19 +175,12 @@ public class Enrollment {
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
responseMsg.setResponseMessage("Device not found");
|
|
|
|
Response.status(HttpStatus.SC_NOT_FOUND);
|
|
|
|
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;
|
|
|
|
return responseMsg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (DeviceManagementException deviceMgtEx) {
|
|
|
|
|
|
|
|
String errorMsg = "Error occurred while dis enrolling the device";
|
|
|
|
|
|
|
|
log.error(errorMsg, deviceMgtEx);
|
|
|
|
|
|
|
|
throw new AndroidAgentException(errorMsg, deviceMgtEx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|