@ -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 ;
@ -233,25 +235,32 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
List < Device > devices ;
List < Device > devices ;
List < org . wso2 . carbon . device . mgt . common . Device > deviceList ;
List < org . wso2 . carbon . device . mgt . common . Device > deviceList ;
try {
try {
DeviceManagementProviderService deviceManagementService = MDMServiceAPIUtils
final int tenantId = applicationOperationDevice . getTenantId ( ) ;
. getDeviceManagementService ( applicationOperationDevice . getTenantId ( ) ) ;
final String username = applicationOperationDevice . getCurrentUser ( ) . getUsername ( ) ;
final String username = applicationOperationDevice . getCurrentUser ( ) . getUsername ( ) ;
final String platform = applicationOperationDevice . getPlatform ( ) ;
final String platform = applicationOperationDevice . getPlatform ( ) ;
DeviceAccessAuthorizationService deviceAccessAuthorizationService = MDMServiceAPIUtils
. getDeviceAccessAuthorizationService ( applicationOperationDevice . getTenantId ( ) ) ;
DeviceManagementProviderService deviceManagementService = MDMServiceAPIUtils
. getDeviceManagementService ( tenantId ) ;
boolean isAdmin = deviceAccessAuthorizationService . isDeviceAdminUser ( ) ;
switch ( platform ) {
switch ( platform ) {
case MDMAppConstants . WEBAPP :
case MDMAppConstants . WEBAPP :
deviceList = deviceManagementService . getDevicesOfUser ( username ) ;
deviceList = isAdmin ? deviceManagementService . getAllDevices ( ) :
deviceManagementService . getDevicesOfUser ( username ) ;
break ;
break ;
case MDMAppConstants . ANDROID :
case MDMAppConstants . ANDROID :
deviceList = deviceManagementService . getDevicesOfUser ( username , MDMAppConstants . ANDROID ) ;
deviceList = isAdmin ? deviceManagementService . getAllDevices ( MDMAppConstants . ANDROID ) :
deviceManagementService . getDevicesOfUser ( username , MDMAppConstants . ANDROID ) ;
break ;
break ;
case MDMAppConstants . IOS :
case MDMAppConstants . IOS :
deviceList = deviceManagementService . getDevicesOfUser ( username , MDMAppConstants . IOS ) ;
deviceList = isAdmin ? deviceManagementService . getAllDevices ( MDMAppConstants . IOS ) :
deviceManagementService . getDevicesOfUser ( username , MDMAppConstants . IOS ) ;
break ;
break ;
default :
default :
String msg = "App platform:" + platform + "is not supported." ;
throw new MobileApplicationException ( "App platform: [" + platform + "] is not supported." ) ;
log . error ( msg ) ;
throw new MobileApplicationException ( msg ) ;
}
}
devices = new ArrayList < > ( deviceList . size ( ) ) ;
devices = new ArrayList < > ( deviceList . size ( ) ) ;
if ( log . isDebugEnabled ( ) ) {
if ( log . isDebugEnabled ( ) ) {
log . debug ( "device list got from mdm " + deviceList . toString ( ) ) ;
log . debug ( "device list got from mdm " + deviceList . toString ( ) ) ;
@ -291,7 +300,8 @@ public class ApplicationOperationsImpl implements ApplicationOperations {
} 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 ;
}
}