Merge branch 'iots-54' into 'master'

Fix issues with APPM Connector

Closes product-iots#55 and product-iots#54

See merge request entgra/carbon-device-mgt-plugins!18
revert-dabc3590
Dharmakeerthi Lasantha 6 years ago
commit 0b1deff245

@ -39,6 +39,8 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.Platform; 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.app.mgt.ApplicationManagementException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.appmgt.mobile.utils.User; import org.wso2.carbon.appmgt.mobile.utils.User;
@ -57,234 +59,227 @@ import java.util.List;
import java.util.Properties; import java.util.Properties;
public class ApplicationOperationsImpl implements ApplicationOperations { public class ApplicationOperationsImpl implements ApplicationOperations {
private static final Log log = LogFactory.getLog(ApplicationOperationsImpl.class);
private static final Log log = LogFactory.getLog(ApplicationOperationsImpl.class); private static final String MEDIA_TYPE_XML = "application/xml";
public static final String MEDIA_TYPE_XML = "application/xml"; private static final String INSTALL = "install";
public static final String INSTALL = "install"; private static final String UNINSTALL = "uninstall";
public static final String UNINSTALL = "uninstall";
/**
/** * @param applicationOperationAction holds the information needs to perform an action on mdm.
* @param applicationOperationAction holds the information needs to perform an action on mdm. * @throws MobileApplicationException If error occurred while performing the action.
* @throws MobileApplicationException */
*/ public String performAction(ApplicationOperationAction applicationOperationAction)
public String performAction(ApplicationOperationAction applicationOperationAction) throws MobileApplicationException {
throws MobileApplicationException { if (log.isDebugEnabled()) {
if (log.isDebugEnabled()) { log.debug(applicationOperationAction.getAction() + " action is triggered for " +
log.debug(applicationOperationAction.getAction() + " action is triggered for " + applicationOperationAction.getType() + ".");
applicationOperationAction.getType() +"."); }
} Operation operation = null;
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
Operation operation = null; List<org.wso2.carbon.device.mgt.common.Device> deviceList;
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>(); if (MDMAppConstants.USER.equals(applicationOperationAction.getType())) {
List<org.wso2.carbon.device.mgt.common.Device> deviceList; String userName = null;
if (MDMAppConstants.USER.equals(applicationOperationAction.getType())) { try {
String userName = null; for (String param : applicationOperationAction.getParams()) {
try { userName = param;
for (String param : applicationOperationAction.getParams()) { deviceList = MDMServiceAPIUtils
userName = param; .getDeviceManagementService(applicationOperationAction.getTenantId()).
getDevicesOfUser(userName);
deviceList = MDMServiceAPIUtils for (org.wso2.carbon.device.mgt.common.Device device : deviceList) {
.getDeviceManagementService(applicationOperationAction.getTenantId()).
getDevicesOfUser(userName);
for (org.wso2.carbon.device.mgt.common.Device device : deviceList) {
if (MDMAppConstants.WEBAPP.equals(applicationOperationAction.getApp().getPlatform()) || if (MDMAppConstants.WEBAPP.equals(applicationOperationAction.getApp().getPlatform()) ||
applicationOperationAction.getApp().getPlatform().equalsIgnoreCase(device.getType())) { applicationOperationAction.getApp().getPlatform().equalsIgnoreCase(device.getType())) {
if (MDMAppConstants.ACTIVE.equalsIgnoreCase(device.getEnrolmentInfo(). if (MDMAppConstants.ACTIVE.equalsIgnoreCase(device.getEnrolmentInfo().
getStatus().toString())) { getStatus().toString())) {
deviceIdentifiers.add(getDeviceIdentifierByDevice(device)); deviceIdentifiers.add(getDeviceIdentifierByDevice(device));
} }
} }
} }
} }
} catch (DeviceManagementException devEx) { } catch (DeviceManagementException devEx) {
String errorMsg = "Error occurred fetch device for user " + userName + String errorMsg = "Error occurred fetch device for user " + userName + " at app installation";
" at app installation";
logError(errorMsg, devEx); logError(errorMsg, devEx);
throw new MobileApplicationException(errorMsg, devEx); throw new MobileApplicationException(errorMsg, devEx);
} }
} else if (MDMAppConstants.ROLE.equals(applicationOperationAction.getType())) { } else if (MDMAppConstants.ROLE.equals(applicationOperationAction.getType())) {
String userRole = null; String userRole = null;
try { try {
for (String param : applicationOperationAction.getParams()) { for (String param : applicationOperationAction.getParams()) {
userRole = param; userRole = param;
deviceList = MDMServiceAPIUtils
deviceList = MDMServiceAPIUtils .getDeviceManagementService(applicationOperationAction.getTenantId()).
.getDeviceManagementService(applicationOperationAction.getTenantId()). getAllDevicesOfRole(userRole);
getAllDevicesOfRole(userRole); for (org.wso2.carbon.device.mgt.common.Device device : deviceList) {
if (MDMAppConstants.ACTIVE.equalsIgnoreCase(device.getEnrolmentInfo().getStatus().toString())) {
for (org.wso2.carbon.device.mgt.common.Device device : deviceList) { deviceIdentifiers.add(getDeviceIdentifierByDevice(device));
if (MDMAppConstants.ACTIVE.equalsIgnoreCase(device.getEnrolmentInfo().getStatus().toString())) { }
deviceIdentifiers.add(getDeviceIdentifierByDevice(device)); }
} }
} } catch (DeviceManagementException devMgtEx) {
} String errorMsg = "Error occurred fetch device for user role " + userRole + " at app installation";
} catch (DeviceManagementException devMgtEx) {
String errorMsg = "Error occurred fetch device for user role " + userRole +
" at app installation";
logError(errorMsg, devMgtEx); logError(errorMsg, devMgtEx);
throw new MobileApplicationException(errorMsg, devMgtEx); throw new MobileApplicationException(errorMsg, devMgtEx);
} }
} else if (MDMAppConstants.DEVICE.equals(applicationOperationAction.getType())) {
} else if (MDMAppConstants.DEVICE.equals(applicationOperationAction.getType())) { DeviceIdentifier deviceIdentifier;
DeviceIdentifier deviceIdentifier; for (String param : applicationOperationAction.getParams()) {
for (String param : applicationOperationAction.getParams()) { deviceIdentifier = new DeviceIdentifier();
deviceIdentifier = new DeviceIdentifier(); if (isValidJSON(param)) {
if (isValidJSON(param)) { JSONParser parser = new JSONParser();
JSONParser parser = new JSONParser(); try {
try { JSONObject parsedObj = (JSONObject) parser.parse(param);
JSONObject parsedObj = (JSONObject) parser.parse(param); deviceIdentifier.setId((String) parsedObj.get(MDMAppConstants.ID));
deviceIdentifier.setId((String) parsedObj.get(MDMAppConstants.ID)); deviceIdentifier.setType((String) parsedObj.get(MDMAppConstants.TYPE));
deviceIdentifier.setType((String) parsedObj.get(MDMAppConstants.TYPE)); deviceIdentifiers.add(deviceIdentifier);
deviceIdentifiers.add(deviceIdentifier); } catch (ParseException e) {
} catch (ParseException e) { logError("Device Identifier is not valid json object.", e);
logError("Device Identifier is not valid json object.", e); throw new MobileApplicationException(e);
throw new MobileApplicationException(e); }
} }
}
} } else {
} throw new IllegalStateException("invalid type is received from app store.");
} else { }
throw new IllegalStateException("invalid type is received from app store."); App app = applicationOperationAction.getApp();
} MobileApp mobileApp = new MobileApp();
App app = applicationOperationAction.getApp(); mobileApp.setId(app.getId());
MobileApp mobileApp = new MobileApp(); mobileApp.setType(MobileAppTypes.valueOf(app.getType().toUpperCase()));
mobileApp.setId(app.getId()); mobileApp.setAppIdentifier(app.getAppIdentifier());
mobileApp.setType(MobileAppTypes.valueOf(app.getType().toUpperCase())); mobileApp.setIconImage(app.getIconImage());
mobileApp.setAppIdentifier(app.getAppIdentifier()); mobileApp.setIdentifier(app.getIdentifier());
mobileApp.setIconImage(app.getIconImage()); mobileApp.setLocation(app.getLocation());
mobileApp.setIdentifier(app.getIdentifier()); mobileApp.setName(app.getName());
mobileApp.setLocation(app.getLocation()); mobileApp.setPackageName(app.getPackageName());
mobileApp.setName(app.getName()); mobileApp.setPlatform(app.getPlatform());
mobileApp.setPackageName(app.getPackageName()); mobileApp.setVersion(app.getVersion());
mobileApp.setPlatform(app.getPlatform()); Properties properties = new Properties();
mobileApp.setVersion(app.getVersion());
Properties properties = new Properties(); if (MDMAppConstants.IOS.equals(app.getPlatform())) {
if (MDMAppConstants.ENTERPRISE.equals(app.getType())) {
if (MDMAppConstants.IOS.equals(app.getPlatform())) { properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true);
if (MDMAppConstants.ENTERPRISE.equals(app.getType())) { properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true);
properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); } else if (MDMAppConstants.IOSConstants.PUBLIC.equals(app.getType())) {
properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true); properties.put(MDMAppConstants.IOSConstants.I_TUNES_ID, app.getIdentifier());
} else if (MDMAppConstants.IOSConstants.PUBLIC.equals(app.getType())) { properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true);
properties.put(MDMAppConstants.IOSConstants.I_TUNES_ID, app.getIdentifier()); properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true);
properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); } else if (MDMAppConstants.WEBAPP.equals(app.getType())) {
properties.put(MDMAppConstants.IOSConstants.IS_PREVENT_BACKUP, true); properties.put(MDMAppConstants.IOSConstants.LABEL, app.getName());
} else if (MDMAppConstants.WEBAPP.equals(app.getType())) { properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true);
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());
} else if (MDMAppConstants.WEBAPP.equals(app.getPlatform())) { properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true);
properties.put(MDMAppConstants.IOSConstants.LABEL, app.getName()); }
properties.put(MDMAppConstants.IOSConstants.IS_REMOVE_APP, true); mobileApp.setProperties(properties);
} Activity activity = null;
mobileApp.setProperties(properties); try {
Activity activity = null; if (deviceIdentifiers.size() > 0) {
try { if (deviceIdentifiers.get(0).getType().equalsIgnoreCase(Platform.ANDROID.toString())) {
if (deviceIdentifiers.size() > 0) { if (MDMAppConstants.INSTALL.equals(applicationOperationAction.getAction())) {
if (deviceIdentifiers.get(0).getType().equalsIgnoreCase(Platform.ANDROID.toString())) { operation = AndroidApplicationOperationUtil
if (MDMAppConstants.INSTALL.equals(applicationOperationAction.getAction())) { .createInstallAppOperation(mobileApp, applicationOperationAction.getSchedule());
operation = AndroidApplicationOperationUtil } else if (MDMAppConstants.UPDATE.equals(applicationOperationAction.getAction())) {
.createInstallAppOperation(mobileApp, applicationOperationAction.getSchedule()); operation = AndroidApplicationOperationUtil
} else if (MDMAppConstants.UPDATE.equals(applicationOperationAction.getAction())) { .createUpdateAppOperation(mobileApp, applicationOperationAction.getSchedule());
operation = AndroidApplicationOperationUtil } else {
.createUpdateAppOperation(mobileApp, applicationOperationAction.getSchedule()); operation = AndroidApplicationOperationUtil
} else { .createAppUninstallOperation(mobileApp, applicationOperationAction.getSchedule());
operation = AndroidApplicationOperationUtil }
.createAppUninstallOperation(mobileApp, applicationOperationAction.getSchedule()); } else if (deviceIdentifiers.get(0).getType().equalsIgnoreCase(Platform.IOS.toString())) {
} if (MDMAppConstants.INSTALL.equals(applicationOperationAction.getAction())) {
} else if (deviceIdentifiers.get(0).getType().equalsIgnoreCase(Platform.IOS.toString())) { operation =
if (MDMAppConstants.INSTALL.equals(applicationOperationAction.getAction())) { IOSApplicationOperationUtil.createInstallAppOperation(mobileApp);
operation = } else {
IOSApplicationOperationUtil.createInstallAppOperation(mobileApp); if (MDMAppConstants.WEBAPP.equals(app.getPlatform())) {
} else { operation = IOSApplicationOperationUtil.createWebClipUninstallOperation(mobileApp);
if (MDMAppConstants.WEBAPP.equals(app.getPlatform())) { } else {
operation = IOSApplicationOperationUtil.createWebClipUninstallOperation(mobileApp); operation = IOSApplicationOperationUtil.createAppUninstallOperation(mobileApp);
} else { }
operation = IOSApplicationOperationUtil.createAppUninstallOperation(mobileApp); }
} }
}
}
activity = MDMServiceAPIUtils.getAppManagementService(applicationOperationAction.getTenantId()) activity = MDMServiceAPIUtils.getAppManagementService(applicationOperationAction.getTenantId())
.installApplicationForDevices(operation, deviceIdentifiers); .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.
if(activity != null){ * @return List of devices
return activity.getActivityId(); * @throws MobileApplicationException If an error occurred in getting devices or if app platform is not supported.
} */
public List<Device> getDevices(ApplicationOperationDevice applicationOperationDevice)
return null; throws MobileApplicationException {
List<Device> devices;
} catch (DeviceApplicationException mdmExce) { List<org.wso2.carbon.device.mgt.common.Device> deviceList;
logError("Error in creating operation object using app.", mdmExce); try {
throw new MobileApplicationException(mdmExce.getMessage()); final int tenantId = applicationOperationDevice.getTenantId();
} catch (ApplicationManagementException appMgtExce) { final String username = applicationOperationDevice.getCurrentUser().getUsername();
logError("Error in app installation.", appMgtExce); final String platform = applicationOperationDevice.getPlatform();
throw new MobileApplicationException(appMgtExce.getErrorMessage()); DeviceAccessAuthorizationService deviceAccessAuthorizationService = MDMServiceAPIUtils
} .getDeviceAccessAuthorizationService(applicationOperationDevice.getTenantId());
DeviceManagementProviderService deviceManagementService = MDMServiceAPIUtils
} .getDeviceManagementService(tenantId);
boolean isAdmin = deviceAccessAuthorizationService.isDeviceAdminUser();
/**
* Create a new device identifier from Device object. switch (platform) {
* @param device device which is to be retrieved type and id case MDMAppConstants.WEBAPP:
* @return created device identifier deviceList = isAdmin ? deviceManagementService.getAllDevices() :
*/ deviceManagementService.getDevicesOfUser(username);
private static DeviceIdentifier getDeviceIdentifierByDevice( break;
org.wso2.carbon.device.mgt.common.Device device) { case MDMAppConstants.ANDROID:
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); deviceList = isAdmin ? deviceManagementService.getAllDevices(MDMAppConstants.ANDROID) :
deviceIdentifier.setId(device.getDeviceIdentifier()); deviceManagementService.getDevicesOfUser(username, MDMAppConstants.ANDROID);
deviceIdentifier.setType(device.getType()); break;
case MDMAppConstants.IOS:
return deviceIdentifier; deviceList = isAdmin ? deviceManagementService.getAllDevices(MDMAppConstants.IOS) :
} deviceManagementService.getDevicesOfUser(username, MDMAppConstants.IOS);
break;
/** default:
* @param applicationOperationDevice holds the information needs to retrieve device list. throw new MobileApplicationException("App platform: [" + platform + "] is not supported.");
* @return List of devices }
* @throws MobileApplicationException
*/
public List<Device> getDevices(ApplicationOperationDevice applicationOperationDevice)
throws MobileApplicationException {
List<Device> devices; devices = new ArrayList<>(deviceList.size());
List<org.wso2.carbon.device.mgt.common.Device> deviceList = null; if (log.isDebugEnabled()) {
try { log.debug("device list got from mdm " + deviceList.toString());
DeviceManagementProviderService deviceManagementService = MDMServiceAPIUtils }
.getDeviceManagementService(applicationOperationDevice.getTenantId()); for (org.wso2.carbon.device.mgt.common.Device commonDevice : deviceList) {
final String username = applicationOperationDevice.getCurrentUser().getUsername(); if (MDMAppConstants.ACTIVE
if (MDMAppConstants.WEBAPP.equals .equals(commonDevice.getEnrolmentInfo().getStatus().toString().
(applicationOperationDevice.getPlatform())) { toLowerCase())) {
deviceList = deviceManagementService. Device device = new Device();
getDevicesOfUser(username); org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier deviceIdentifier =
} else { new org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier();
deviceList = deviceManagementService. deviceIdentifier.setId(commonDevice.getDeviceIdentifier());
getDevicesOfUser(username, deviceIdentifier.setType(commonDevice.getType());
MDMAppConstants.ANDROID); device.setDeviceIdentifier(deviceIdentifier);
deviceList.addAll(deviceManagementService. device.setName(commonDevice.getName());
getDevicesOfUser(username, device.setModel(commonDevice.getName());
MDMAppConstants.IOS)); device.setType(MDMAppConstants.MOBILE_DEVICE);
} String imgUrl;
devices = new ArrayList<>(deviceList.size()); if (MDMAppConstants.ANDROID.equalsIgnoreCase(commonDevice.getType())) {
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() imgUrl = String.format(applicationOperationDevice.getConfigParams()
.get(MDMAppConstants.IMAGE_URL), .get(MDMAppConstants.IMAGE_URL),
MDMAppConstants.NEXUS); MDMAppConstants.NEXUS);
@ -297,38 +292,39 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
.get(MDMAppConstants.IMAGE_URL), .get(MDMAppConstants.IMAGE_URL),
MDMAppConstants.NONE); MDMAppConstants.NONE);
} }
device.setImage(imgUrl); device.setImage(imgUrl);
device.setPlatform(commonDevice.getType()); device.setPlatform(commonDevice.getType());
devices.add(device); devices.add(device);
} }
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
logError("Error While retrieving Device List.", e); logError("Error While retrieving Device List.", e);
throw new MobileApplicationException(e.getMessage()); throw new MobileApplicationException(e.getMessage());
} catch (DeviceAccessAuthorizationException e) {
} throw new MobileApplicationException("Error while checking user permissions", e);
return devices; }
} return devices;
}
private boolean isValidJSON(String json) { private boolean isValidJSON(String json) {
JSONParser parser = new JSONParser(); JSONParser parser = new JSONParser();
try { try {
parser.parse(json); parser.parse(json);
} catch (ParseException e) { } catch (ParseException e) {
return false; return false;
} }
return true; return true;
} }
private void logError(String errorMessage, Throwable e) { private void logError(String errorMessage, Throwable e) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.error(errorMessage, e); log.error(errorMessage, e);
} else { } else {
log.error(errorMessage); log.error(errorMessage);
} }
} }
public static UserStoreManager getUserStoreManager() throws UserStoreException { private static UserStoreManager getUserStoreManager() throws UserStoreException {
RealmService realmService; RealmService realmService;
UserStoreManager userStoreManager; UserStoreManager userStoreManager;
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
@ -366,7 +362,6 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
@Override @Override
public void run() { public void run() {
try { try {
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
@ -460,6 +455,4 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
} }
} }
} }
} }

@ -19,6 +19,7 @@ package org.wso2.carbon.appmgt.mdm.osgiconnector.mdmmgt.util;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
@ -49,6 +50,26 @@ public class MDMServiceAPIUtils {
return deviceManagementProviderService; return deviceManagementProviderService;
} }
/**
* Returns the DeviceAccessAuthorizationService osgi service.
*
* @param tenantId tenant id
* @return {@link DeviceAccessAuthorizationService}
*/
public static DeviceAccessAuthorizationService getDeviceAccessAuthorizationService(int tenantId) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
ctx.setTenantId(tenantId, true);
DeviceAccessAuthorizationService deviceAccessAuthorizationService =
(DeviceAccessAuthorizationService) ctx
.getOSGiService(DeviceAccessAuthorizationService.class, null);
if (deviceAccessAuthorizationService == null) {
String msg = "Device Access Authorization service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return deviceAccessAuthorizationService;
}
/** /**
* Returns the ApplicationManagementProviderService osgi service. * Returns the ApplicationManagementProviderService osgi service.
* *

Loading…
Cancel
Save