diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/pom.xml b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/pom.xml new file mode 100644 index 0000000000..ae948f1b44 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/pom.xml @@ -0,0 +1,149 @@ + + + + + org.wso2.carbon.devicemgt-plugins + extensions + 2.2.2-SNAPSHOT + ../pom.xml + + 4.0.0 + 2.2.2-SNAPSHOT + org.wso2.carbon.appmgt.mdm.osgiconnector + bundle + WSO2 Carbon - App Manager WSO2 MDM OSGI Connector Component + http://maven.apache.org + + + + + org.apache.felix + maven-scr-plugin + + + generate-scr-scrdescriptor + + scr + + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + org.wso2.carbon.appmgt.mdm.osgiconnector.internal + + org.wso2.carbon.device.mgt.core.*, + org.wso2.carbon.appmgt.mobile.utils.*, + org.wso2.carbon.appmgt.mobile.mdm.*, + org.wso2.carbon.appmgt.mobile.interfaces.*, + *;resolution:=optional + + + !org.wso2.carbon.appmgt.mdm.osgiconnector.internal, + org.wso2.carbon.appmgt.mdm.osgiconnector.* + + + + + + + + + org.wso2.carbon.appmgt + org.wso2.carbon.appmgt.mobile + + + org.apache.ws.commons.axiom + axiom-api + + + org.apache.ws.commons.axiom + axiom-impl + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + + + org.apache.ws.commons.axiom + axiom-api + + + org.apache.ws.commons.axiom + axiom-impl + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.policy.mgt.core + + + org.apache.ws.commons.axiom + axiom-api + + + org.apache.ws.commons.axiom + axiom-impl + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + + + org.apache.ws.commons.axiom + axiom-api + + + org.apache.ws.commons.axiom + axiom-impl + + + + + commons-io.wso2 + commons-io + + + com.googlecode.json-simple.wso2 + json-simple + + + com.googlecode.plist + dd-plist + + + org.apache.felix + org.apache.felix.scr + + + com.google.code.gson + gson + + + + diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java new file mode 100644 index 0000000000..766698c9c7 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/ApplicationOperationsImpl.java @@ -0,0 +1,296 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.MobileApp; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.MobileAppTypes; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util.AndroidApplicationOperationUtil; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util.IOSApplicationOperationUtil; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util.MDMAppConstants; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util.MDMServiceAPIUtils; +import org.wso2.carbon.appmgt.mobile.beans.ApplicationOperationAction; +import org.wso2.carbon.appmgt.mobile.beans.ApplicationOperationDevice; +import org.wso2.carbon.appmgt.mobile.interfaces.ApplicationOperations; +import org.wso2.carbon.appmgt.mobile.mdm.App; +import org.wso2.carbon.appmgt.mobile.mdm.Device; +import org.wso2.carbon.appmgt.mobile.utils.MobileApplicationException; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.Platform; +import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +public class ApplicationOperationsImpl implements ApplicationOperations { + + private static final Log log = LogFactory.getLog(ApplicationOperationsImpl.class); + + /** + * @param applicationOperationAction holds the information needs to perform an action on mdm. + * @throws MobileApplicationException + */ + public String performAction(ApplicationOperationAction applicationOperationAction) + throws MobileApplicationException { + if (log.isDebugEnabled()) { + log.debug(applicationOperationAction.getAction() + " action is triggered for " + + applicationOperationAction.getType() +"."); + } + + Operation operation = null; + List deviceIdentifiers = new ArrayList<>(); + List deviceList; + if (MDMAppConstants.USER.equals(applicationOperationAction.getType())) { + String userName = null; + try { + for (String param : applicationOperationAction.getParams()) { + userName = param; + + deviceList = MDMServiceAPIUtils + .getDeviceManagementService(applicationOperationAction.getTenantId()). + getDevicesOfUser(userName); + + for (org.wso2.carbon.device.mgt.common.Device device : deviceList) { + if(applicationOperationAction.getApp().getPlatform().equalsIgnoreCase(device.getType())){ + deviceIdentifiers.add(getDeviceIdentifierByDevice(device)); + } + } + } + } catch (DeviceManagementException devEx) { + String errorMsg = "Error occurred fetch device for user " + userName + + " at app installation"; + logError(errorMsg, devEx); + throw new MobileApplicationException(errorMsg, devEx); + } + } else if (MDMAppConstants.ROLE.equals(applicationOperationAction.getType())) { + String userRole = null; + try { + for (String param : applicationOperationAction.getParams()) { + userRole = param; + + deviceList = MDMServiceAPIUtils + .getDeviceManagementService(applicationOperationAction.getTenantId()). + getAllDevicesOfRole(userRole); + + for (org.wso2.carbon.device.mgt.common.Device device : deviceList) { + deviceIdentifiers.add(getDeviceIdentifierByDevice(device)); + } + } + } catch (DeviceManagementException devMgtEx) { + String errorMsg = "Error occurred fetch device for user role " + userRole + + " at app installation"; + logError(errorMsg, devMgtEx); + throw new MobileApplicationException(errorMsg, devMgtEx); + } + + } else if (MDMAppConstants.DEVICE.equals(applicationOperationAction.getType())) { + DeviceIdentifier deviceIdentifier; + for (String param : applicationOperationAction.getParams()) { + deviceIdentifier = new DeviceIdentifier(); + if (isValidJSON(param)) { + JSONParser parser = new JSONParser(); + try { + JSONObject parsedObj = (JSONObject) parser.parse(param); + deviceIdentifier.setId((String) parsedObj.get(MDMAppConstants.ID)); + deviceIdentifier.setType((String) parsedObj.get(MDMAppConstants.TYPE)); + deviceIdentifiers.add(deviceIdentifier); + } catch (ParseException e) { + logError("Device Identifier is not valid json object.", e); + throw new MobileApplicationException(e); + } + + } + } + } else { + throw new IllegalStateException("invalid type is received from app store."); + } + App app = applicationOperationAction.getApp(); + MobileApp mobileApp = new MobileApp(); + mobileApp.setId(app.getId()); + mobileApp.setType(MobileAppTypes.valueOf(app.getType().toUpperCase())); + mobileApp.setAppIdentifier(app.getAppIdentifier()); + mobileApp.setIconImage(app.getIconImage()); + mobileApp.setIdentifier(app.getIdentifier()); + mobileApp.setLocation(app.getLocation()); + mobileApp.setName(app.getName()); + mobileApp.setPackageName(app.getPackageName()); + mobileApp.setPlatform(app.getPlatform()); + mobileApp.setVersion(app.getVersion()); + Properties properties = new Properties(); + + if (MDMAppConstants.IOS.equals(app.getPlatform())) { + if (MDMAppConstants.ENTERPRISE.equals(app.getType())) { + properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); + properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true); + } else if (MDMAppConstants.IOSConstants.PUBLIC.equals(app.getType())) { + properties.put(MDMAppConstants.IOSConstants.I_TUNES_ID, app.getIdentifier()); + properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); + properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true); + } else if (MDMAppConstants.WEBAPP.equals(app.getType())) { + properties.put(MDMAppConstants.IOSConstants.LABEL, app.getName()); + properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); + } + } else if (MDMAppConstants.WEBAPP.equals(app.getPlatform())) { + properties.put(MDMAppConstants.IOSConstants.LABEL, app.getName()); + properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); + } + mobileApp.setProperties(properties); + Activity activity = null; + try { + if (deviceIdentifiers.size() > 0) { + if (deviceIdentifiers.get(0).getType().equalsIgnoreCase(Platform.ANDROID.toString())) { + if (MDMAppConstants.INSTALL.equals(applicationOperationAction.getAction())) { + operation = AndroidApplicationOperationUtil + .createInstallAppOperation(mobileApp, applicationOperationAction.getSchedule()); + } else if (MDMAppConstants.UPDATE.equals(applicationOperationAction.getAction())) { + operation = AndroidApplicationOperationUtil + .createUpdateAppOperation(mobileApp, applicationOperationAction.getSchedule()); + } else { + operation = AndroidApplicationOperationUtil + .createAppUninstallOperation(mobileApp, applicationOperationAction.getSchedule()); + } + } else if (deviceIdentifiers.get(0).getType().equalsIgnoreCase(Platform.IOS.toString())) { + if (MDMAppConstants.INSTALL.equals(applicationOperationAction.getAction())) { + operation = + IOSApplicationOperationUtil.createInstallAppOperation(mobileApp); + } else { + operation = + IOSApplicationOperationUtil.createAppUninstallOperation(mobileApp); + } + } + activity = MDMServiceAPIUtils.getAppManagementService(applicationOperationAction.getTenantId()) + .installApplicationForDevices(operation, deviceIdentifiers); + + + } + + if(activity != null){ + return activity.getActivityId(); + } + + return null; + + } catch (DeviceApplicationException mdmExce) { + logError("Error in creating operation object using app.", mdmExce); + throw new MobileApplicationException(mdmExce.getMessage()); + } catch (ApplicationManagementException appMgtExce) { + logError("Error in app installation.", appMgtExce); + throw new MobileApplicationException(appMgtExce.getErrorMessage()); + } + + } + + /** + * Create a new device identifier from Device object. + * @param device device which is to be retrieved type and id + * @return created device identifier + */ + private static DeviceIdentifier getDeviceIdentifierByDevice( + org.wso2.carbon.device.mgt.common.Device device) { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(device.getDeviceIdentifier()); + deviceIdentifier.setType(device.getType()); + + return deviceIdentifier; + } + + /** + * @param applicationOperationDevice holds the information needs to retrieve device list. + * @return List of devices + * @throws MobileApplicationException + */ + public List getDevices(ApplicationOperationDevice applicationOperationDevice) + throws MobileApplicationException { + + List devices; + try { + List deviceList = MDMServiceAPIUtils + .getDeviceManagementService(applicationOperationDevice.getTenantId()). + getDevicesOfUser( + applicationOperationDevice.getCurrentUser().getUsername()); + devices = new ArrayList<>(deviceList.size()); + if(log.isDebugEnabled()){ + log.debug("device list got from mdm "+ deviceList.toString()); + } + for (org.wso2.carbon.device.mgt.common.Device commonDevice : deviceList) { + if (MDMAppConstants.ACTIVE + .equals(commonDevice.getEnrolmentInfo().getStatus().toString(). + toLowerCase())) { + Device device = new Device(); + org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier deviceIdentifier = + new org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier(); + deviceIdentifier.setId(commonDevice.getDeviceIdentifier()); + deviceIdentifier.setType(commonDevice.getType()); + device.setDeviceIdentifier(deviceIdentifier); + device.setName(commonDevice.getName()); + device.setModel(commonDevice.getName()); + device.setType(MDMAppConstants.MOBILE_DEVICE); + String imgUrl; + if (MDMAppConstants.ANDROID.equalsIgnoreCase(commonDevice.getType())) { + imgUrl = String.format(applicationOperationDevice.getConfigParams() + .get(MDMAppConstants.IMAGE_URL), + MDMAppConstants.NEXUS); + } else if (MDMAppConstants.IOS.equalsIgnoreCase(commonDevice.getType())) { + imgUrl = String.format(applicationOperationDevice.getConfigParams() + .get(MDMAppConstants.IMAGE_URL), + MDMAppConstants.IPHONE); + } else { + imgUrl = String.format(applicationOperationDevice.getConfigParams() + .get(MDMAppConstants.IMAGE_URL), + MDMAppConstants.NONE); + } + device.setImage(imgUrl); + device.setPlatform(commonDevice.getType()); + devices.add(device); + } + } + } catch (DeviceManagementException e) { + logError("Error While retrieving Device List.", e); + throw new MobileApplicationException(e.getMessage()); + + } + return devices; + } + + private boolean isValidJSON(String json) { + JSONParser parser = new JSONParser(); + try { + parser.parse(json); + } catch (ParseException e) { + return false; + } + return true; + } + + private void logError(String errorMessage, Throwable e) { + if (log.isDebugEnabled()) { + log.error(errorMessage, e); + } else { + log.error(errorMessage); + } + } + +} + diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/internal/DeviceApplicationServiceComponent.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/internal/DeviceApplicationServiceComponent.java new file mode 100644 index 0000000000..085f3a6501 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/internal/DeviceApplicationServiceComponent.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wso2.carbon.appmgt.mdm.osgiconnector.internal; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.appmgt.mdm.osgiconnector.ApplicationOperationsImpl; +import org.wso2.carbon.appmgt.mobile.interfaces.ApplicationOperations; + +/** + * @scr.component name="org.wso2.carbon.appmgt.mdm.osgiconnector" immediate="true" + */ + +public class DeviceApplicationServiceComponent { + + private static final Log log = LogFactory.getLog(DeviceApplicationServiceComponent.class); + + private ServiceRegistration mdmServiceRegistration; + + protected void activate(ComponentContext context) { + BundleContext bundleContext = context.getBundleContext(); + mdmServiceRegistration = bundleContext + .registerService(ApplicationOperations.class.getName(), new ApplicationOperationsImpl(), null); + if (log.isDebugEnabled()) { + log.debug("Device Application Service Component activated."); + } + + } + + protected void deactivate(ComponentContext context) { + if (mdmServiceRegistration != null) { + mdmServiceRegistration.unregister(); + mdmServiceRegistration = null; + } + if (log.isDebugEnabled()) { + log.debug("Device Application Service Component deactivated."); + } + + } + +} + + diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileApp.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileApp.java new file mode 100644 index 0000000000..2933669a45 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileApp.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans; + +import java.util.Properties; + +/** + * This class represents the generic mobile Application information + * which is used by AppM. + */ +public class MobileApp { + + private String id; + private String name; + private MobileAppTypes type; + private String platform; + private String version; + private String identifier; + private String iconImage; + private String packageName; + private String appIdentifier; + private String location; + private Properties properties; + + public MobileAppTypes getType() { + return type; + } + + public void setType(MobileAppTypes type) { + this.type = type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public String getIconImage() { + return iconImage; + } + + public void setIconImage(String iconImage) { + this.iconImage = iconImage; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public Properties getProperties() { + return properties; + } + + public void setProperties(Properties properties) { + this.properties = properties; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileAppTypes.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileAppTypes.java new file mode 100644 index 0000000000..9b1b306c03 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/MobileAppTypes.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans; + +public enum MobileAppTypes { + ENTERPRISE, WEBAPP, PUBLIC + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AndroidApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AndroidApplication.java new file mode 100644 index 0000000000..d638d7b111 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AndroidApplication.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.android; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +public class AndroidApplication { + private String type; + private String appIdentifier; + + public String getAppIdentifier() { + return appIdentifier; + } + + public void setAppIdentifier(String appIdentifier) { + this.appIdentifier = appIdentifier; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String toJSON() throws DeviceApplicationException { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AppStoreApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AppStoreApplication.java new file mode 100644 index 0000000000..6f78eb2443 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/AppStoreApplication.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.android; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +import java.io.Serializable; + +/** + * This class represents the Appstore Application information. + */ +public class AppStoreApplication extends AndroidApplication implements Serializable { + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/EnterpriseApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/EnterpriseApplication.java new file mode 100644 index 0000000000..f8990e5856 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/EnterpriseApplication.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.android; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +import java.io.Serializable; + +/** + * This class represents the Enterprise Application information. + */ +public class EnterpriseApplication extends AndroidApplication implements Serializable { + + private String url; + private String schedule; + private String packageName; + + public String getSchedule() { + return schedule; + } + + public void setSchedule(String schedule) { + this.schedule = schedule; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/WebApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/WebApplication.java new file mode 100644 index 0000000000..08a35e08e7 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/android/WebApplication.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.android; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +import java.io.Serializable; + +/** + * This class represents the Web Application information. + */ +public class WebApplication implements Serializable { + + private String name; + private String url; + private String type; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String toJSON() throws DeviceApplicationException { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/AppStoreApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/AppStoreApplication.java new file mode 100644 index 0000000000..b8e6a4e09f --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/AppStoreApplication.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios; + +import java.io.Serializable; + +public class AppStoreApplication extends IOSApplication implements Serializable { + + private int iTunesStoreID; + + public int getiTunesStoreID() { + return iTunesStoreID; + } + + public void setiTunesStoreID(int iTunesStoreID) { + this.iTunesStoreID = iTunesStoreID; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/EnterpriseApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/EnterpriseApplication.java new file mode 100644 index 0000000000..3a09b73252 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/EnterpriseApplication.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios; + +import java.io.Serializable; + +public class EnterpriseApplication extends IOSApplication implements Serializable { + + private String manifestURL; + + public String getManifestURL() { + return manifestURL; + } + + public void setManifestURL(String manifestURL) { + this.manifestURL = manifestURL; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/IOSApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/IOSApplication.java new file mode 100644 index 0000000000..12a8db23ab --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/IOSApplication.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +public class IOSApplication { + + private String identifier; + private boolean removeAppUponMDMProfileRemoval; + private boolean preventBackupOfAppData; + private String bundleId; + private String UUID; + + public String getUUID() { + return UUID; + } + + public void setUUID(String UUID) { + this.UUID = UUID; + } + + public String getIdentifier() { + return identifier; + } + + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + public boolean isRemoveAppUponMDMProfileRemoval() { + return removeAppUponMDMProfileRemoval; + } + + public void setRemoveAppUponMDMProfileRemoval(boolean removeAppUponMDMProfileRemoval) { + this.removeAppUponMDMProfileRemoval = removeAppUponMDMProfileRemoval; + } + + public boolean isPreventBackupOfAppData() { + return preventBackupOfAppData; + } + + public void setPreventBackupOfAppData(boolean preventBackupOfAppData) { + this.preventBackupOfAppData = preventBackupOfAppData; + } + + public String getBundleId() { + return bundleId; + } + + public void setBundleId(String bundleId) { + this.bundleId = bundleId; + } + + public String toJSON() throws DeviceApplicationException { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/RemoveApplication.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/RemoveApplication.java new file mode 100644 index 0000000000..22c7963def --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/RemoveApplication.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +import java.io.Serializable; + +public class RemoveApplication implements Serializable { + + private String bundleId; + + public String getBundleId() { + return bundleId; + } + + public void setBundleId(String bundleId) { + this.bundleId = bundleId; + } + + public String toJSON() throws DeviceApplicationException { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/WebClip.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/WebClip.java new file mode 100644 index 0000000000..000374c433 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/beans/ios/WebClip.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios; + +import com.google.gson.Gson; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; + +public class WebClip { + + private String URL; + private String label; + private String icon; + private String isRemovable; + private String UUID; + + public String getUUID() { + return UUID; + } + + public void setUUID(String UUID) { + this.UUID = UUID; + } + + public String getURL() { + return URL; + } + + public void setURL(String URL) { + this.URL = URL; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getIcon() { + return icon; + } + + public void setIcon(String icon) { + this.icon = icon; + } + + public String getIsRemovable() { + return isRemovable; + } + + public void setIsRemovable(String isRemovable) { + this.isRemovable = isRemovable; + } + + public String toJSON() throws DeviceApplicationException { + Gson gson = new Gson(); + return gson.toJson(this); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/common/DeviceApplicationException.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/common/DeviceApplicationException.java new file mode 100644 index 0000000000..84818e4a08 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/common/DeviceApplicationException.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common; + +public class DeviceApplicationException extends Exception { + + private static final long serialVersionUID = 5136875495185597926L; + private String errorMessage; + + public DeviceApplicationException(String msg, Exception e) { + super(msg, e); + setErrorMessage(msg); + } + + public DeviceApplicationException(String msg, Throwable cause) { + super(msg, cause); + setErrorMessage(msg); + } + + public DeviceApplicationException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public DeviceApplicationException() { + super(); + } + + public DeviceApplicationException(Throwable cause) { + super(cause); + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/AndroidApplicationOperationUtil.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/AndroidApplicationOperationUtil.java new file mode 100644 index 0000000000..7c1288b1ac --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/AndroidApplicationOperationUtil.java @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util; + +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.MobileApp; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.android.AppStoreApplication; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.android.EnterpriseApplication; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.android.WebApplication; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; + +/** + * This class contains the all the operations related to Android. + */ +public class AndroidApplicationOperationUtil { + + /** + * Create Install Application operation. + * + * @param application MobileApp application + * @return operation + * @throws DeviceApplicationException + */ + public static Operation createInstallAppOperation(MobileApp application, String schedule) throws + DeviceApplicationException { + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_INSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + switch (application.getType()) { + case ENTERPRISE: + EnterpriseApplication enterpriseApplication = new EnterpriseApplication(); + enterpriseApplication.setType(application.getType().toString()); + enterpriseApplication.setUrl(application.getLocation()); + enterpriseApplication.setSchedule(schedule); + enterpriseApplication.setPackageName(application.getPackageName()); + operation.setPayLoad(enterpriseApplication.toJSON()); + break; + case PUBLIC: + setOperationForPublicApp(operation, application); + break; + case WEBAPP: + setOperationForWebApp(operation, application); + break; + default: + String errorMessage = "Invalid application type."; + throw new DeviceApplicationException(errorMessage); + } + return operation; + } + + /** + * Create Update Application operation. + * + * @param application MobileApp application + * @return operation + * @throws DeviceApplicationException + */ + public static Operation createUpdateAppOperation(MobileApp application, String schedule) throws + DeviceApplicationException { + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UPDATE_APPLICATION); + operation.setType(Operation.Type.PROFILE); + switch (application.getType()) { + case ENTERPRISE: + EnterpriseApplication enterpriseApplication = new EnterpriseApplication(); + enterpriseApplication.setType(application.getType().toString()); + enterpriseApplication.setUrl(application.getLocation()); + enterpriseApplication.setSchedule(schedule); + operation.setPayLoad(enterpriseApplication.toJSON()); + break; + case PUBLIC: + setOperationForPublicApp(operation, application); + break; + case WEBAPP: + setOperationForWebApp(operation, application); + break; + default: + String errorMessage = "Invalid application type."; + throw new DeviceApplicationException(errorMessage); + } + return operation; + } + + /** + * Create Uninstall Application operation. + * + * @param application MobileApp application + * @return operation + * @throws DeviceApplicationException + */ + public static Operation createAppUninstallOperation(MobileApp application, String schedule) throws + DeviceApplicationException { + + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_UNINSTALL_APPLICATION); + operation.setType(Operation.Type.PROFILE); + + switch (application.getType()) { + case ENTERPRISE: + EnterpriseApplication enterpriseApplication = new EnterpriseApplication(); + enterpriseApplication.setType(application.getType().toString()); + enterpriseApplication.setAppIdentifier(application.getIdentifier()); + enterpriseApplication.setSchedule(schedule); + operation.setPayLoad(enterpriseApplication.toJSON()); + break; + case PUBLIC: + setOperationForPublicApp(operation, application); + break; + case WEBAPP: + setOperationForWebApp(operation, application); + break; + default: + String errorMessage = "Invalid application type."; + throw new DeviceApplicationException(errorMessage); + } + return operation; + } + + private static void setOperationForPublicApp(Operation operation, MobileApp application) + throws DeviceApplicationException { + AppStoreApplication appStoreApplication = new AppStoreApplication(); + appStoreApplication.setType(application.getType().toString()); + appStoreApplication.setAppIdentifier(application.getIdentifier()); + operation.setPayLoad(appStoreApplication.toJSON()); + } + + private static void setOperationForWebApp(Operation operation, MobileApp application) + throws DeviceApplicationException { + WebApplication webApplication = new WebApplication(); + webApplication.setUrl(application.getLocation()); + webApplication.setName(application.getName()); + webApplication.setType(application.getType().toString()); + operation.setPayLoad(webApplication.toJSON()); + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/IOSApplicationOperationUtil.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/IOSApplicationOperationUtil.java new file mode 100644 index 0000000000..3167ed8d3c --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/IOSApplicationOperationUtil.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util; + +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.MobileApp; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios.AppStoreApplication; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios.WebClip; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.common.DeviceApplicationException; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios.EnterpriseApplication; +import org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.beans.ios.RemoveApplication; + +import java.util.Properties; + +/** + * This class contains the all the operations related to IOS. + */ +public class IOSApplicationOperationUtil { + + /** + * Create Install Application operation. + * + * @param application MobileApp application + * @return operation + * @throws DeviceApplicationException + */ + public static Operation createInstallAppOperation(MobileApp application) throws + DeviceApplicationException { + + ProfileOperation operation = new ProfileOperation(); + switch (application.getType()) { + 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)); + enterpriseApplication.setRemoveAppUponMDMProfileRemoval( + (Boolean) properties.get(MDMAppConstants.IOSConstants.IS_REMOVE_APP)); + operation.setCode( + MDMAppConstants.IOSConstants.OPCODE_INSTALL_ENTERPRISE_APPLICATION); + operation.setPayLoad(enterpriseApplication.toJSON()); + operation.setType(Operation.Type.COMMAND); + break; + case PUBLIC: + AppStoreApplication appStoreApplication = new AppStoreApplication(); + appStoreApplication.setRemoveAppUponMDMProfileRemoval( + (Boolean) application.getProperties() + .get(MDMAppConstants.IOSConstants.IS_REMOVE_APP)); + appStoreApplication.setIdentifier(application.getIdentifier()); + appStoreApplication.setPreventBackupOfAppData((Boolean) application.getProperties(). + get(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP)); + appStoreApplication.setBundleId(application.getId()); + appStoreApplication.setiTunesStoreID((Integer) application.getProperties(). + get(MDMAppConstants.IOSConstants.I_TUNES_ID)); + operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_STORE_APPLICATION); + operation.setType(Operation.Type.COMMAND); + operation.setPayLoad(appStoreApplication.toJSON()); + break; + case WEBAPP: + WebClip webClip = new WebClip(); + webClip.setIcon(application.getIconImage()); + webClip.setIsRemovable(application.getProperties(). + getProperty(MDMAppConstants.IOSConstants.IS_REMOVE_APP)); + webClip.setLabel(application.getProperties(). + getProperty(MDMAppConstants.IOSConstants.LABEL)); + webClip.setURL(application.getLocation()); + operation.setCode(MDMAppConstants.IOSConstants.OPCODE_INSTALL_WEB_APPLICATION); + operation.setType(Operation.Type.PROFILE); + operation.setPayLoad(webClip.toJSON()); + break; + default: + String errorMessage = "Invalid application type."; + throw new DeviceApplicationException(errorMessage); + } + return operation; + } + + /** + * Create uninstall operations. + * + * @param application + * @return Uninstall operation + * @throws DeviceApplicationException + */ + public static Operation createAppUninstallOperation(MobileApp application) throws + DeviceApplicationException { + ProfileOperation operation = new ProfileOperation(); + operation.setCode(MDMAppConstants.IOSConstants.OPCODE_REMOVE_APPLICATION); + operation.setType(Operation.Type.PROFILE); + RemoveApplication removeApplication = new RemoveApplication(); + removeApplication.setBundleId(application.getIdentifier()); + operation.setPayLoad(removeApplication.toJSON()); + return operation; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMAppConstants.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMAppConstants.java new file mode 100644 index 0000000000..5903b64843 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMAppConstants.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util; + +/** + * This class holds all the constants used for IOS and Android. + */ +public class MDMAppConstants { + + public static final String USER = "user"; + public static final String ROLE = "role"; + public static final String IOS = "ios"; + public static final String ANDROID = "android"; + public static final String WEBAPP = "webapp"; + public static final String INSTALL = "install"; + public static final String UPDATE = "update"; + public static final String ACTIVE = "active"; + public static final String ENTERPRISE = "enterprise"; + public static final String DEVICE = "device"; + public static final String MOBILE_DEVICE = "mobileDevice"; + public static final String NEXUS = "nexus"; + public static final String IPHONE = "iphone"; + public static final String NONE = "none"; + public static final String IMAGE_URL = "ImageURL"; + public static final String TYPE = "type"; + public static final String ID = "id"; + + public class IOSConstants { + + private IOSConstants() { + throw new AssertionError(); + } + + public static final String IS_REMOVE_APP = "isRemoveApp"; + 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 PUBLIC = "public"; + 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"; + public static final String OPCODE_REMOVE_APPLICATION = "REMOVE_APPLICATION"; + } + + public class AndroidConstants { + private AndroidConstants() { + throw new AssertionError(); + } + + public static final String OPCODE_INSTALL_APPLICATION = "INSTALL_APPLICATION"; + public static final String OPCODE_UPDATE_APPLICATION = "UPDATE_APPLICATION"; + public static final String OPCODE_UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION"; + } + + public class RegistryConstants { + private RegistryConstants() { + throw new AssertionError(); + } + + public static final String GENERAL_CONFIG_RESOURCE_PATH = "general"; + } + + public class APPManagerConstants { + private static final String APP_MANAGER_MDM_SERVICE_NAME = + "org.wso2.carbon.appmgt.mobile.interfaces.MDMOperations"; + } + +} diff --git a/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMServiceAPIUtils.java b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMServiceAPIUtils.java new file mode 100644 index 0000000000..922f017326 --- /dev/null +++ b/components/extensions/org.wso2.carbon.appmgt.mdm.osgiconnector/src/main/java/org/wso2/carbon/appmgt/mdm/osgiconnector/mdmmgt/util/MDMServiceAPIUtils.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; + +/** + * MDMServiceAPIUtils class provides utility function. + */ +public class MDMServiceAPIUtils { + + private static Log log = LogFactory.getLog(MDMServiceAPIUtils.class); + + /** + * Returns the DeviceManagementProviderService osgi service. + * + * @param tenantId tenant id + * @return DeviceManagementProviderService + */ + public static DeviceManagementProviderService getDeviceManagementService(int tenantId) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantId(tenantId, true); + DeviceManagementProviderService deviceManagementProviderService = + (DeviceManagementProviderService) ctx + .getOSGiService(DeviceManagementProviderService.class, null); + if (deviceManagementProviderService == null) { + String msg = "Device Management provider service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return deviceManagementProviderService; + } + + /** + * Returns the ApplicationManagementProviderService osgi service. + * + * @param tenantId tenant id + * @return ApplicationManagementProviderService + */ + public static ApplicationManagementProviderService getAppManagementService(int tenantId) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ctx.setTenantId(tenantId, true); + ApplicationManagementProviderService applicationManagementProviderService = + (ApplicationManagementProviderService) ctx. + getOSGiService( + ApplicationManagementProviderService.class, + null); + if (applicationManagementProviderService == null) { + String msg = "Application management service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return applicationManagementProviderService; + } + +} diff --git a/components/extensions/pom.xml b/components/extensions/pom.xml new file mode 100644 index 0000000000..ddd840fb7b --- /dev/null +++ b/components/extensions/pom.xml @@ -0,0 +1,58 @@ + + + + + + + org.wso2.carbon.devicemgt-plugins + carbon-device-mgt-plugins-parent + 2.2.2-SNAPSHOT + ../../pom.xml + + + 4.0.0 + extensions + pom + WSO2 Carbon - Mobile Plugins Extensions + http://wso2.org + + + org.wso2.carbon.appmgt.mdm.osgiconnector + + + + + + + org.apache.felix + maven-scr-plugin + 1.7.2 + + + generate-scr-scrdescriptor + + scr + + + + + + + + diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.devices/devices.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.devices/devices.hbs index 5cee2c06a4..5becb8e14a 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.devices/devices.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/mdm.page.devices/devices.hbs @@ -107,10 +107,13 @@
{{unit "mdm.unit.device.operation-bar"}}
-
-

Enabling Device Operations

+
+

+ + Enabling Bulk Operations on Devices +

- To enable device operations, select the desired platform and + To enable bulk operations, select the desired platform and ownership from above filter.
diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js index 93be0add70..114ffb6014 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-bar/public/js/operation-bar.js @@ -35,6 +35,10 @@ var operations = '.wr-operations', ownershipTypeConstants = { "BYOD": "BYOD", "COPE": "COPE" + }, + operationBarModeConstants = { + "BULK": "BULK_OPERATION_MODE", + "SINGLE": "SINGLE_OPERATION_MODE" }; /* @@ -103,7 +107,7 @@ function getDevicesByTypes(deviceList) { // $(".wr-operations").html(""); //} -function loadOperationBar(deviceType, ownership) { +function loadOperationBar(deviceType, ownership, mode) { var operationBar = $("#operations-bar"); var operationBarSrc = operationBar.attr("src"); @@ -121,9 +125,20 @@ function loadOperationBar(deviceType, ownership) { var j; for (j = 0; j < totalFeatures.length; j++) { if (permissionList[deviceType][i] == totalFeatures[j]["code"]) { - if (deviceType == platformTypeConstants.ANDROID && - totalFeatures[j]["code"] == "DEVICE_UNLOCK") { - if (ownership == ownershipTypeConstants.COPE) { + if (deviceType == platformTypeConstants.ANDROID) { + if (totalFeatures[j]["code"] == "DEVICE_UNLOCK") { + if (ownership == ownershipTypeConstants.COPE) { + permittedOperations.push(totalFeatures[j]); + } + } else if (totalFeatures[j]["code"] == "WIPE_DATA") { + if (mode == operationBarModeConstants.BULK) { + if (ownership == ownershipTypeConstants.COPE) { + permittedOperations.push(totalFeatures[j]); + } + } else { + permittedOperations.push(totalFeatures[j]); + } + } else { permittedOperations.push(totalFeatures[j]); } } else { diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/public/js/operation-mod.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/public/js/operation-mod.js index 735e05321e..0672461471 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/public/js/operation-mod.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.operation-mod/public/js/operation-mod.js @@ -1450,6 +1450,7 @@ var operationModule = function () { } else if (operationDataObj.is(":radio")) { if (operationDataObj.val() == uiPayload[key]) { operationDataObj.attr("checked", true); + operationDataObj.trigger("click"); } } else if (operationDataObj.is("select")) { operationDataObj.val(value); diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.view/public/js/device-detail.js b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.view/public/js/device-detail.js index fbe1e7b9d3..8204c69f93 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.view/public/js/device-detail.js +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.device.view/public/js/device-detail.js @@ -292,7 +292,7 @@ var InitiateViewOption = null; $(document).ready(function () { $(".device-detail-body").removeClass("hidden"); $("#loading-content").remove(); - loadOperationBar(deviceType, ownership); + loadOperationBar(deviceType, ownership, operationBarModeConstants.SINGLE); loadOperationsLog(false); loadApplicationsList(); loadPolicyCompliance(); diff --git a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.create/public/templates/hidden-operations-android.hbs b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.create/public/templates/hidden-operations-android.hbs index 58b2aedad5..2cd1a50382 100644 --- a/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.create/public/templates/hidden-operations-android.hbs +++ b/components/mobile-plugins/mobile-base-plugin/org.wso2.carbon.device.mgt.mobile.ui/src/main/resources/jaggeryapps/devicemgt/app/units/mdm.unit.policy.create/public/templates/hidden-operations-android.hbs @@ -62,7 +62,7 @@ - Applications Restrictions + Application Restrictions @@ -73,8 +73,10 @@   System Update Policy (COSU) - - + + @@ -82,9 +84,11 @@ Whitelist Apps (COSU) - + - +
@@ -104,10 +108,8 @@
- This configuration can be used to set a passcode policy to an Android Device. - Once this configuration profile is installed on a device, corresponding users will not be - able - to modify these settings on their devices. + Configure the passcode policy for Android device. Once the policy is applied on a device, + the device owner will not be able to modify the password settings via the device.
@@ -762,7 +764,7 @@
@@ -775,8 +777,8 @@
@@ -792,12 +794,13 @@ -
+