Merge branch 'application-mgt-new' into 'application-mgt-new'

Add iOS enterprise app install

See merge request entgra/carbon-device-mgt!129
feature/appm-store/pbac
Dharmakeerthi Lasantha 6 years ago
commit 9f7b05a502

@ -92,4 +92,33 @@ public interface ArtifactDownloadAPI {
required = true)
@PathParam("fileName") String fileName);
@GET
@Path("/plist/{uuid}")
@Produces(MediaType.TEXT_XML)
@ApiOperation(
produces = MediaType.TEXT_XML,
httpMethod = "GET",
value = "Get plist artifact content of an application",
notes = "Get plist artifact content of an application"
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved plist artifact content.",
response = ApplicationList.class),
@ApiResponse(
code = 404,
message = "Not Found. Plist artifact content not found for the application."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while retrieving plist artifact content.",
response = ErrorResponse.class)
})
Response getPlistArtifact(
@ApiParam(
name = "uuid",
value = "UUID of the application release.",
required = true)
@PathParam("uuid") String uuid);
}

@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.api.services.ArtifactDownloadAPI;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
@ -72,4 +73,24 @@ public class ArtifactDownloadAPIImpl implements ArtifactDownloadAPI {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Override
@Produces(MediaType.TEXT_XML)
@Path("/plist/{uuid}")
public Response getPlistArtifact(@PathParam("uuid") String uuid) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
String plistContent = applicationManager.getPlistArtifact(uuid);
return Response.status(Response.Status.OK).entity(plistContent).build();
} catch (NotFoundException e) {
String msg = "Couldn't find an application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while getting the application plist artifact file.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -258,4 +258,13 @@ public interface ApplicationManager {
String getInstallableLifecycleState() throws ApplicationManagementException;
/**
* Get plist content to download and install the application.
*
* @param uuid Release UUID of the application.
* @return plist string
* @throws ApplicationManagementException Application management exception
*/
String getPlistArtifact(String uuid) throws ApplicationManagementException;
}

@ -19,6 +19,7 @@ package org.wso2.carbon.device.application.mgt.core.impl;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.validator.routines.UrlValidator;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
@ -2603,4 +2604,47 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new UnexpectedServerErrorException(msg);
}
}
public String getPlistArtifact(String releaseUuid) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
if (applicationDTO == null) {
String msg = "Couldn't find application for the release UUID: " + releaseUuid;
log.error(msg);
throw new NotFoundException(msg);
}
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
String artifactDownloadEndpoint = ConfigurationManager.getInstance().getConfiguration()
.getArtifactDownloadEndpoint();
String artifactDownloadURL = artifactDownloadEndpoint + Constants.FORWARD_SLASH + applicationReleaseDTO.getUuid()
+ Constants.FORWARD_SLASH + applicationReleaseDTO.getInstallerName();
String plistContent = "<!DOCTYPE plist PUBLIC "-//Apple//DTDPLIST1.0//EN" "" +
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="" +
"1.0"><dict><key>items</key><array><dict><" +
"key>assets</key><array><dict><key>kind</key><" +
"string>software-package</string><key>url</key><string>" +
"$downloadURL</string></dict></array><key>metadata<" +
"/key><dict><key>bundle-identifier</key><string>" +
"$packageName</string><key>bundle-version</key><string>" +
"$bundleVersion</string><key>kind</key><string>" +
"software</string><key>title</key><string>$appName<" +
"/string></dict></dict></array></dict></plist>";
plistContent = plistContent.replace("$downloadURL", artifactDownloadURL)
.replace("$packageName", applicationReleaseDTO.getPackageName())
.replace("$bundleVersion", applicationReleaseDTO.getVersion())
.replace("$appName", applicationDTO.getName());
return StringEscapeUtils.unescapeXml(plistContent);
} catch (DBConnectionException e) {
throw new ApplicationManagementException(
"Error occurred while obtaining the database connection for getting application for the release UUID: "
+ releaseUuid, e);
} catch (ApplicationManagementDAOException e) {
throw new ApplicationManagementException(
"Error occurred while getting application data for release UUID: " + releaseUuid, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
}

@ -35,6 +35,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManageme
import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException;
import org.wso2.carbon.device.application.mgt.common.response.Application;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
@ -46,9 +47,11 @@ import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import org.wso2.carbon.device.application.mgt.core.util.HelperUtil;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.MDMAppConstants;
import org.wso2.carbon.device.mgt.common.app.mgt.MobileApp;
import org.wso2.carbon.device.mgt.common.app.mgt.MobileAppTypes;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
@ -70,6 +73,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;
/**
@ -474,6 +478,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
} else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) {
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
String artifactDownloadEndpoint = ConfigurationManager.getInstance().getConfiguration()
.getArtifactDownloadEndpoint();
String plistDownloadEndpoint = artifactDownloadEndpoint + Constants.FORWARD_SLASH +
MDMAppConstants.IOSConstants.PLIST + Constants.FORWARD_SLASH +
application.getApplicationReleases().get(0).getUuid();
mobileApp.setType(mobileAppType);
mobileApp.setLocation(plistDownloadEndpoint);
Properties properties = new Properties();
properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true);
properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true);
mobileApp.setProperties(properties);
return MDMIOSOperationUtil.createInstallAppOperation(mobileApp);
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
return MDMIOSOperationUtil.createAppUninstallOperation(mobileApp);

@ -32,6 +32,7 @@ public class MDMAppConstants {
public static final String IS_PREVENT_BACKUP = "isPreventBackup";
public static final String I_TUNES_ID = "iTunesId";
public static final String LABEL = "label";
public static final String PLIST = "plist";
public static final String OPCODE_INSTALL_ENTERPRISE_APPLICATION = "INSTALL_ENTERPRISE_APPLICATION";
public static final String OPCODE_INSTALL_STORE_APPLICATION = "INSTALL_STORE_APPLICATION";
public static final String OPCODE_INSTALL_WEB_APPLICATION = "WEB_CLIP";

@ -48,10 +48,7 @@ public class MDMIOSOperationUtil {
case ENTERPRISE:
EnterpriseApplication enterpriseApplication =
new EnterpriseApplication();
enterpriseApplication.setBundleId(application.getId());
enterpriseApplication.setIdentifier(application.getIdentifier());
enterpriseApplication.setManifestURL(application.getLocation());
Properties properties = application.getProperties();
enterpriseApplication.setPreventBackupOfAppData((Boolean) properties.
get(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP));

Loading…
Cancel
Save