Fix issue in accessing device shared via group

feature/appm-store/pbac
Charitha Goonetilleke 5 years ago
parent 2d87cfa96b
commit 7b7a6b1ce1

@ -628,7 +628,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
deviceIdentifier.setType(type);
informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService();
deviceLocation = informationManager.getDeviceLocation(deviceIdentifier);
} catch (DeviceDetailsMgtException e) {
String msg = "Error occurred while getting the device location.";
log.error(msg, e);

@ -273,7 +273,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
DeviceLocation location = new DeviceLocation();
DeviceLocation location = null;
try {
conn = this.getConnection();
String sql = "SELECT * FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ? AND ENROLMENT_ID = ?";
@ -282,7 +282,8 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
stmt.setInt(2, enrollmentId);
rs = stmt.executeQuery();
while (rs.next()) {
if (rs.next()) {
location = new DeviceLocation();
location.setDeviceId(deviceId);
location.setLatitude(rs.getDouble("LATITUDE"));
location.setLongitude(rs.getDouble("LONGITUDE"));
@ -294,7 +295,6 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
location.setCountry(rs.getString("COUNTRY"));
location.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP")));
}
location.setDeviceId(deviceId);
return location;
} catch (SQLException e) {

@ -315,9 +315,13 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
getDeviceManagementProvider().getAllDevices(deviceIdentifiers.get(0).getType(), false);
List<DeviceLocation> deviceLocations = new ArrayList<>();
DeviceManagementDAOFactory.openConnection();
DeviceLocation deviceLocation;
for (Device device : devices) {
deviceLocations.add(deviceDetailsDAO.getDeviceLocation(device.getId(),
device.getEnrolmentInfo().getId()));
deviceLocation = deviceDetailsDAO.getDeviceLocation(device.getId(),
device.getEnrolmentInfo().getId());
if (deviceLocation != null) {
deviceLocations.add(deviceLocation);
}
}
return deviceLocations;
} catch (DeviceManagementException e) {

@ -46,6 +46,8 @@ import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.tenant.PlatformConfigurationManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl;
import org.wso2.carbon.device.mgt.core.geo.service.GeoLocationProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.notification.mgt.NotificationManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
@ -57,6 +59,8 @@ import org.wso2.carbon.device.mgt.core.privacy.impl.PrivacyComplianceProviderImp
import org.wso2.carbon.device.mgt.core.push.notification.mgt.PushNotificationProviderRepository;
import org.wso2.carbon.device.mgt.core.push.notification.mgt.task.PushNotificationSchedulerTask;
import org.wso2.carbon.device.mgt.core.report.mgt.ReportManagementServiceImpl;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
import org.wso2.carbon.device.mgt.core.search.mgt.impl.SearchManagerServiceImpl;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
@ -325,6 +329,9 @@ public class DeviceManagementServiceComponent {
/* Registering PermissionManager Service */
PermissionManagerService permissionManagerService = PermissionManagerServiceImpl.getInstance();
bundleContext.registerService(PermissionManagerService.class.getName(), permissionManagerService, null);
bundleContext.registerService(DeviceInformationManager.class, new DeviceInformationManagerImpl(), null);
bundleContext.registerService(SearchManagerService.class, new SearchManagerServiceImpl(), null);
}
private void setupDeviceManagementSchema(DataSourceConfig config) throws DeviceManagementException {

@ -16,21 +16,17 @@
* under the License.
*/
package org.wso2.carbon.device.mgt.core.internal;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService;
import org.wso2.carbon.device.mgt.core.search.mgt.impl.SearchManagerServiceImpl;
import org.wso2.carbon.device.mgt.core.status.task.DeviceStatusTaskException;
import org.wso2.carbon.device.mgt.core.status.task.DeviceStatusTaskManagerService;
import org.wso2.carbon.device.mgt.core.status.task.impl.DeviceStatusTaskManagerServiceImpl;
@ -39,7 +35,6 @@ import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
import org.wso2.carbon.device.mgt.core.task.impl.DeviceTaskManagerServiceImpl;
import org.wso2.carbon.ntask.core.service.TaskService;
import java.util.ArrayList;
import java.util.Map;
/**
@ -52,9 +47,11 @@ import java.util.Map;
* unbind="unsetTaskService"
*/
@SuppressWarnings("unused")
public class DeviceTaskManagerServiceComponent {
private static Log log = LogFactory.getLog(DeviceTaskManagerServiceComponent.class);
private DeviceManagementConfig deviceManagementConfig;
@SuppressWarnings("unused")
protected void activate(ComponentContext componentContext) {
@ -62,45 +59,40 @@ public class DeviceTaskManagerServiceComponent {
if (log.isDebugEnabled()) {
log.debug("Initializing device task manager bundle.");
}
getDeviceOperationMonitoringConfig(componentContext);
startOperationMonitoringTask(componentContext.getBundleContext());
//Start the DeviceStatusMonitoringTask for registered DeviceTypes
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().
deviceManagementConfig = DeviceConfigurationManager.getInstance().
getDeviceManagementConfig();
if (deviceManagementConfig != null && deviceManagementConfig.getDeviceStatusTaskConfig().isEnabled()) {
startDeviceStatusMonitoringTask();
startDeviceStatusMonitoringTask(componentContext.getBundleContext());
}
componentContext.getBundleContext().registerService(DeviceInformationManager.class,
new DeviceInformationManagerImpl(), null);
componentContext.getBundleContext().registerService(SearchManagerService.class,
new SearchManagerServiceImpl(), null);
} catch (Throwable e) {
log.error("Error occurred while initializing device task manager service.", e);
}
}
private void getDeviceOperationMonitoringConfig(ComponentContext componentContext)
private void startOperationMonitoringTask(BundleContext bundleContext)
throws DeviceMgtTaskException {
DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(deviceTaskManagerService);
componentContext.getBundleContext().registerService(DeviceTaskManagerService.class,
deviceTaskManagerService, null);
bundleContext.registerService(DeviceTaskManagerService.class, deviceTaskManagerService, null);
Map<String, OperationMonitoringTaskConfig> deviceConfigMap = DeviceMonitoringOperationDataHolder
.getInstance().getOperationMonitoringConfigFromMap();
for (String platformType : new ArrayList<>(deviceConfigMap.keySet())) {
if (deviceConfigMap.get(platformType).isEnabled()){
deviceTaskManagerService.startTask(platformType, deviceConfigMap.get(platformType));
for (String platformType : deviceConfigMap.keySet()) {
OperationMonitoringTaskConfig taskConfig = deviceConfigMap.get(platformType);
if (taskConfig.isEnabled()) {
deviceTaskManagerService.startTask(platformType, taskConfig);
}
deviceConfigMap.remove(platformType);
}
}
private void startDeviceStatusMonitoringTask() {
private void startDeviceStatusMonitoringTask(BundleContext bundleContext) {
DeviceStatusTaskManagerService deviceStatusTaskManagerService = new DeviceStatusTaskManagerServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceStatusTaskManagerService(deviceStatusTaskManagerService);
bundleContext.registerService(DeviceStatusTaskManagerService.class, deviceStatusTaskManagerService, null);
Map<DeviceType, DeviceStatusTaskPluginConfig> deviceStatusTaskPluginConfigs = DeviceManagementDataHolder.
getInstance().getDeviceStatusTaskPluginConfigs();
for (DeviceType deviceType : new ArrayList<>(deviceStatusTaskPluginConfigs.keySet())) {
for (DeviceType deviceType : deviceStatusTaskPluginConfigs.keySet()) {
try {
deviceStatusTaskManagerService.startTask(deviceType, deviceStatusTaskPluginConfigs.get(deviceType));
} catch (DeviceStatusTaskException e) {
@ -113,10 +105,41 @@ public class DeviceTaskManagerServiceComponent {
@SuppressWarnings("unused")
protected void deactivate(ComponentContext componentContext) {
try {
// DeviceTaskManagerService taskManagerService = new DeviceTaskManagerServiceImpl();
// taskManagerService.stopTask();
stopOperationMonitoringTask();
if (deviceManagementConfig != null && deviceManagementConfig.getDeviceStatusTaskConfig().isEnabled()) {
stopDeviceStatusMonitoringTask();
}
} catch (Throwable e) {
log.error("Error occurred while destroying the device details retrieving task manager service.", e);
log.error("Error occurred while shutting down device task manager service.", e);
}
}
private void stopOperationMonitoringTask()
throws DeviceMgtTaskException {
DeviceTaskManagerService deviceTaskManagerService = DeviceManagementDataHolder.getInstance()
.getDeviceTaskManagerService();
Map<String, OperationMonitoringTaskConfig> deviceConfigMap = DeviceMonitoringOperationDataHolder
.getInstance().getOperationMonitoringConfigFromMap();
for (String platformType : deviceConfigMap.keySet()) {
OperationMonitoringTaskConfig taskConfig = deviceConfigMap.get(platformType);
if (taskConfig.isEnabled()) {
deviceTaskManagerService.stopTask(platformType, taskConfig);
}
}
}
private void stopDeviceStatusMonitoringTask() {
DeviceStatusTaskManagerService deviceStatusTaskManagerService = DeviceManagementDataHolder.getInstance()
.getDeviceStatusTaskManagerService();
Map<DeviceType, DeviceStatusTaskPluginConfig> deviceStatusTaskPluginConfigs = DeviceManagementDataHolder.
getInstance().getDeviceStatusTaskPluginConfigs();
for (DeviceType deviceType : deviceStatusTaskPluginConfigs.keySet()) {
try {
deviceStatusTaskManagerService.stopTask(deviceType, deviceStatusTaskPluginConfigs.get(deviceType));
} catch (DeviceStatusTaskException e) {
log.error("Exception occurred while stopping the DeviceStatusMonitoring Task for deviceType '" +
deviceType + "'", e);
}
}
}

@ -1165,4 +1165,41 @@ public class OperationManagerImpl implements OperationManager {
private boolean isSameUser(String user, String owner) {
return user.equalsIgnoreCase(owner);
}
private List<? extends Operation> getOperations(DeviceIdentifier deviceId, Operation.Status status, int enrolmentId)
throws OperationManagementException {
List<Operation> operations = new ArrayList<>();
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = new ArrayList<>();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status internalStatus =
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf(status.name());
try {
OperationManagementDAOFactory.openConnection();
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(
enrolmentId, internalStatus));
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(
enrolmentId, internalStatus));
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(
enrolmentId, internalStatus));
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(
enrolmentId, internalStatus));
Operation operation;
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
operation = OperationDAOUtil.convertOperation(dtoOperation);
operations.add(operation);
}
operations.sort(new OperationIdComparator());
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " +
"pending operations assigned for '" + deviceId.getType() +
"' device '" + deviceId.getId() + "'", e);
} catch (SQLException e) {
throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
return operations;
}
}

@ -100,7 +100,7 @@ public class DeviceStatusTaskManagerServiceImpl implements DeviceStatusTaskManag
try {
TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService();
String taskName = DEVICE_STATUS_MONITORING_TASK_TYPE + "_" + deviceType.getName() + "_" + deviceType.getId();
if (taskService.isServerInit()) {
if (taskService != null && taskService.isServerInit()) {
TaskManager taskManager = taskService.getTaskManager(DEVICE_STATUS_MONITORING_TASK_TYPE);
taskManager.deleteTask(taskName);
}

@ -109,9 +109,9 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
try {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService();
if (taskService.isServerInit()) {
if (taskService != null && taskService.isServerInit()) {
TaskManager taskManager = taskService.getTaskManager(TASK_TYPE);
String taskName = deviceType + String.valueOf(tenantId);
String taskName = deviceType + tenantId;
taskManager.deleteTask(taskName);
}
} catch (TaskException e) {
@ -133,7 +133,7 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService {
TaskManager taskManager = taskService.getTaskManager(TASK_TYPE);
if (taskManager.isTaskScheduled(deviceType)) {
String taskName = deviceType + String.valueOf(tenantId);
String taskName = deviceType + tenantId;
taskManager.deleteTask(taskName);
TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo();
triggerInfo.setIntervalMillis(operationMonitoringTaskConfig.getFrequency());

Loading…
Cancel
Save