|
|
@ -36,21 +36,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
|
|
|
package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
import org.apache.commons.httpclient.HttpStatus;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
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.CarbonContext;
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponse;
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.SubscriptionType;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.SubscriptionManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.HelperUtil;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceFilters;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.OperationLogFilters;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.MDMAppConstants;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Feature;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Feature;
|
|
|
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
|
|
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.OperationLogFilters;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceFilters;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
|
|
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
|
|
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
|
|
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
|
|
@ -88,17 +96,19 @@ import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceCompliance;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceCompliance;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationRequest;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ComplianceDeviceList;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationList;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationList;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationStatusBean;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationStatusBean;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ComplianceDeviceList;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationRequest;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.OperationList;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationUninstallation;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.DeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils;
|
|
|
|
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
|
|
|
import org.wso2.carbon.identity.jwt.client.extension.JWTClient;
|
|
|
|
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
|
|
|
import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo;
|
|
|
@ -877,6 +887,82 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
|
|
|
@Path("/{type}/{id}/uninstallation")
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Response uninstallation(
|
|
|
|
|
|
|
|
@PathParam("type") @Size(max = 45) String type,
|
|
|
|
|
|
|
|
@PathParam("id") @Size(max = 45) String id,
|
|
|
|
|
|
|
|
@QueryParam("packageName") String packageName) {
|
|
|
|
|
|
|
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
|
|
|
|
|
|
|
Operation operation = new Operation();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
RequestValidationUtil.validateDeviceIdentifier(type, id);
|
|
|
|
|
|
|
|
Device device = DeviceMgtAPIUtils.getDeviceManagementService().getDevice(id, false);
|
|
|
|
|
|
|
|
ApplicationManagementProviderService amc = DeviceMgtAPIUtils.getAppManagementService();
|
|
|
|
|
|
|
|
List<Application> applications = amc.getApplicationListForDevice(device);
|
|
|
|
|
|
|
|
//checking requested package names are valid or not
|
|
|
|
|
|
|
|
RequestValidationUtil.validateApplicationIdentifier(packageName, applications);
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
|
|
|
|
|
|
|
|
deviceIdentifiers.add(deviceIdentifier);
|
|
|
|
|
|
|
|
SubscriptionManager subscriptionManager = DeviceMgtAPIUtils.getSubscriptionManager();
|
|
|
|
|
|
|
|
String UUID = subscriptionManager.checkAppSubscription(device.getId(), packageName);
|
|
|
|
|
|
|
|
// UUID is available means app is subscribed in the entgra store
|
|
|
|
|
|
|
|
if (UUID != null) {
|
|
|
|
|
|
|
|
ApplicationInstallResponse response = subscriptionManager
|
|
|
|
|
|
|
|
.performBulkAppOperation(UUID, deviceIdentifiers, SubscriptionType.DEVICE.toString(),
|
|
|
|
|
|
|
|
"uninstall");
|
|
|
|
|
|
|
|
return Response.status(Response.Status.OK).entity(response).build();
|
|
|
|
|
|
|
|
//if the applications not installed via entgra store
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (Constants.ANDROID.equals(type)) {
|
|
|
|
|
|
|
|
ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation(packageName, "PUBLIC");
|
|
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
|
|
operation.setCode(MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL);
|
|
|
|
|
|
|
|
operation.setType(Operation.Type.PROFILE);
|
|
|
|
|
|
|
|
operation.setPayLoad(gson.toJson(applicationUninstallation));
|
|
|
|
|
|
|
|
DeviceManagementProviderService deviceManagementProviderService = HelperUtil
|
|
|
|
|
|
|
|
.getDeviceManagementProviderService();
|
|
|
|
|
|
|
|
Activity activity = deviceManagementProviderService.addOperation(
|
|
|
|
|
|
|
|
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_ANDROID, operation, deviceIdentifiers);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.CREATED).entity(activity).build();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Not implemented for other device types";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while getting '" + type + "' device, which carries " +
|
|
|
|
|
|
|
|
"the id '" + id + "'";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
} catch (SubscriptionManagementException |
|
|
|
|
|
|
|
|
org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException
|
|
|
|
|
|
|
|
e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while getting the " + type + "application is of device " + id + "subscribed " +
|
|
|
|
|
|
|
|
"at entgra store";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
} catch (ApplicationManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while fetching the apps of the '" + type + "' device, which carries " +
|
|
|
|
|
|
|
|
"the id '" + id + "'";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.serverError().entity(
|
|
|
|
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
|
|
|
|
} catch (OperationManagementException e) {
|
|
|
|
|
|
|
|
String msg = "Issue in retrieving operation management service instance";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
|
|
|
} catch (InvalidDeviceException e) {
|
|
|
|
|
|
|
|
String msg = "The list of device identifiers are invalid";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Path("/{type}/{id}/operations")
|
|
|
|
@Path("/{type}/{id}/operations")
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|