forked from community/device-mgt-core
parent
8983fd6d51
commit
a4e17ef99b
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.device.application.mgt.common;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.DeviceConnectorException;
|
||||
|
||||
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 DeviceConnectorException {
|
||||
Gson gson = new Gson();
|
||||
return gson.toJson(this);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.device.application.mgt.common;
|
||||
|
||||
public class AppOperation {
|
||||
|
||||
private static final long serialVersionUID = 7603215716452548282L;
|
||||
|
||||
private Application application;
|
||||
private int tenantId;
|
||||
private String activityId;
|
||||
private String scheduledDateTime;
|
||||
private OperationType type;
|
||||
private String subscribedBy;
|
||||
private int appReleaseId;
|
||||
private InstallState installState;
|
||||
|
||||
public InstallState getInstallState() {
|
||||
return installState;
|
||||
}
|
||||
|
||||
public void setInstallState(InstallState installState) {
|
||||
this.installState = installState;
|
||||
}
|
||||
|
||||
public enum InstallState {
|
||||
PENDING, INPROGRESS, INSTALLED, UNINSTALLED, ERROR
|
||||
}
|
||||
|
||||
public int getAppReleaseId() {
|
||||
return appReleaseId;
|
||||
}
|
||||
|
||||
public void setAppReleaseId(int appReleaseId) {
|
||||
this.appReleaseId = appReleaseId;
|
||||
}
|
||||
|
||||
public String getSubscribedBy() {
|
||||
return subscribedBy;
|
||||
}
|
||||
|
||||
public void setSubscribedBy(String subscribedBy) {
|
||||
this.subscribedBy = subscribedBy;
|
||||
}
|
||||
|
||||
public enum OperationType {
|
||||
INSTALL, UNINSTALL, UPDATE
|
||||
}
|
||||
|
||||
public OperationType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(OperationType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Application getApplication() {
|
||||
return application;
|
||||
}
|
||||
|
||||
public void setApplication(Application application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public int getTenantId() {
|
||||
return tenantId;
|
||||
}
|
||||
|
||||
public void setTenantId(int tenantId) {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
public String getActivityId() {
|
||||
return activityId;
|
||||
}
|
||||
|
||||
public void setActivityId(String activityId) {
|
||||
this.activityId = activityId;
|
||||
}
|
||||
|
||||
public String getScheduledDateTime() {
|
||||
return scheduledDateTime;
|
||||
}
|
||||
|
||||
public void setScheduledDateTime(String scheduledDateTime) {
|
||||
this.scheduledDateTime = scheduledDateTime;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.device.application.mgt.common;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 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.device.application.mgt.common.exception;
|
||||
|
||||
/**
|
||||
* Represents the exception thrown during device connections.
|
||||
*/
|
||||
public class DeviceConnectorException extends Exception {
|
||||
private String message;
|
||||
|
||||
public DeviceConnectorException(String message, Throwable throwable) {
|
||||
super(message, throwable);
|
||||
setMessage(message);
|
||||
}
|
||||
|
||||
public DeviceConnectorException(String message) {
|
||||
super(message);
|
||||
setMessage(message);
|
||||
}
|
||||
|
||||
public DeviceConnectorException() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.device.application.mgt.common.services;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.AppOperation;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.DeviceConnectorException;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This interface contains operations necessary to perform actions on a device such as install and application on a
|
||||
* device, uninstall or upgrade. This must be implemented to connect to an external device management server.
|
||||
*/
|
||||
public interface DeviceConnector {
|
||||
|
||||
Boolean sendOperationToDevice(AppOperation appOperation, DeviceIdentifier deviceIdentifier) throws
|
||||
DeviceConnectorException;
|
||||
|
||||
Boolean sendOperationToGroup(AppOperation appOperation, String groupID) throws DeviceConnectorException;
|
||||
|
||||
Boolean sendOperationToUser(AppOperation appOperation, List<String> userList) throws DeviceConnectorException;
|
||||
|
||||
Boolean sendOperationToRole(AppOperation appOperation, String role) throws DeviceConnectorException;
|
||||
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.device.application.mgt.core.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.application.mgt.common.AppOperation;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.DeviceConnectorException;
|
||||
import org.wso2.carbon.device.application.mgt.common.services.DeviceConnector;
|
||||
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;
|
||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;;
|
||||
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MAMDeviceConnectorImpl implements DeviceConnector{
|
||||
private static final Log log = LogFactory.getLog(MAMDeviceConnectorImpl.class);
|
||||
private ApplicationDAO applicationDAO;
|
||||
private SubscriptionDAO subscriptionDAO;
|
||||
|
||||
public MAMDeviceConnectorImpl() {
|
||||
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
||||
this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean sendOperationToDevice(AppOperation appOperation, DeviceIdentifier deviceIdentifier) throws DeviceConnectorException {
|
||||
if (String.valueOf(appOperation.getType()).equals("INSTALL")) {
|
||||
|
||||
} else if (String.valueOf(appOperation.getType()).equals("UNINSTALL")) {
|
||||
|
||||
} else if (String.valueOf(appOperation.getType()).equals("UPDATE")) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean sendOperationToGroup(AppOperation appOperation, String groupID) throws DeviceConnectorException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean sendOperationToUser(AppOperation appOperation, List<String> userList) throws DeviceConnectorException {
|
||||
if (String.valueOf(appOperation.getType()).equals("INSTALL")) {
|
||||
//First subscribe the user to the app.
|
||||
try {
|
||||
|
||||
subscriptionDAO.subscribeUserToApplication(appOperation.getTenantId(), appOperation.getSubscribedBy(),
|
||||
userList, appOperation.getApplication().getId(), appOperation.getAppReleaseId());
|
||||
for (String username: userList) {
|
||||
List<Device> devices = getDeviceManagementService().getDevicesOfUser(username);
|
||||
List<DeviceIdentifier> deviceIdentifiers = convertDeviceToDeviceIdentifier(devices);
|
||||
// getDeviceManagementService().addOperation(appOperation.getApplication().getDeviceType(),
|
||||
// operationEKA, devices);
|
||||
subscriptionDAO.subscribeDeviceToApplication(appOperation.getTenantId(), appOperation.getSubscribedBy(),
|
||||
devices, appOperation.getApplication().getId(), appOperation.getAppReleaseId(),
|
||||
String.valueOf(AppOperation.InstallState.PENDING));
|
||||
}
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
String msg = "Error subscribing the user to the application Id" + appOperation.getApplication().getId();
|
||||
log.error(msg, e);
|
||||
throw new DeviceConnectorException(msg, e);
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error getting the list of user devices.";
|
||||
log.error(msg, e);
|
||||
throw new DeviceConnectorException(msg, e);
|
||||
}
|
||||
|
||||
} else if (String.valueOf(appOperation.getType()).equals("UNINSTALL")) {
|
||||
|
||||
} else if (String.valueOf(appOperation.getType()).equals("UPDATE")) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean sendOperationToRole(AppOperation appOperation, String role) throws DeviceConnectorException {
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<DeviceIdentifier> convertDeviceToDeviceIdentifier(List<Device> devices) {
|
||||
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||
for (Device device:devices) {
|
||||
deviceIdentifiers.add(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
|
||||
}
|
||||
return deviceIdentifiers;
|
||||
}
|
||||
|
||||
public DeviceManagementProviderService getDeviceManagementService() {
|
||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||
DeviceManagementProviderService deviceManagementProviderService =
|
||||
(DeviceManagementProviderService) ctx.getOSGiService(DeviceManagementProviderService.class, null);
|
||||
if (deviceManagementProviderService == null) {
|
||||
String msg = "DeviceImpl Management provider service has not initialized.";
|
||||
log.error(msg);
|
||||
throw new IllegalStateException(msg);
|
||||
}
|
||||
return deviceManagementProviderService;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.device.application.mgt.core.util;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.AppOperation;
|
||||
import org.wso2.carbon.device.application.mgt.common.EnterpriseApplication;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation;
|
||||
|
||||
public class AndroidApplicationOperationUtil {
|
||||
// public static Operation installApp(AppOperation appOperation) {
|
||||
// ProfileOperation operation = new ProfileOperation();
|
||||
// operation.setCode(MDMAppConstants.AndroidConstants.OPCODE_INSTALL_APPLICATION);
|
||||
// operation.setType(Operation.Type.PROFILE);
|
||||
// switch (appOperation.getApplication().getType()) {
|
||||
// case "ENTERPRISE"://TODO: fix with ENUM
|
||||
// EnterpriseApplication enterpriseApplication = new EnterpriseApplication();
|
||||
// enterpriseApplication.setType(appOperation.getApplication().toString());
|
||||
// enterpriseApplication.setUrl(application.getLocation());
|
||||
// enterpriseApplication.setSchedule(appOperation.getScheduledDateTime());
|
||||
// enterpriseApplication.setPackageName(appOperation.getApplication().get);
|
||||
// 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;
|
||||
// }
|
||||
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 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.device.application.mgt.core.util;
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue