Set tenant through tenant domain auto resolve method

revert-70ac1926
Saad Sahibjan 5 years ago
parent da5a1caf2b
commit 07e56d68f5

@ -37,6 +37,7 @@ package org.wso2.carbon.device.mgt.core.task.impl;
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.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
@ -55,7 +56,6 @@ public class DeviceDetailsRetrieverTask implements Task {
private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class); private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class);
private String deviceType; private String deviceType;
private static final int SUPER_TENANT_ID = -1234;
private DeviceManagementProviderService deviceManagementProviderService; private DeviceManagementProviderService deviceManagementProviderService;
@Override @Override
@ -90,25 +90,19 @@ public class DeviceDetailsRetrieverTask implements Task {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Task is running for " + tenants.size() + " tenants and the device type is " + deviceType); log.debug("Task is running for " + tenants.size() + " tenants and the device type is " + deviceType);
} }
for (Integer tenant : tenants) { for (Integer tenant : tenants) {
if (SUPER_TENANT_ID == tenant) { if (MultitenantConstants.SUPER_TENANT_ID == tenant) {
this.executeTask(operationMonitoringTaskConfig, startupOperationConfig); this.executeTask(operationMonitoringTaskConfig, startupOperationConfig);
continue; continue;
} }
String tenantDomain = DeviceManagementDataHolder.getInstance().
getRealmService().getTenantManager().getDomain(tenant);
try { try {
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant);
this.executeTask(operationMonitoringTaskConfig, startupOperationConfig); this.executeTask(operationMonitoringTaskConfig, startupOperationConfig);
} finally { } finally {
PrivilegedCarbonContext.endTenantFlow(); PrivilegedCarbonContext.endTenantFlow();
} }
} }
} catch (UserStoreException e) {
log.error("Error occurred while trying to get the available tenants", e);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while trying to get the available tenants " + log.error("Error occurred while trying to get the available tenants " +
"from device manager provider service.", e); "from device manager provider service.", e);

@ -21,6 +21,7 @@ package org.wso2.carbon.policy.mgt.core.task;
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.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
@ -42,8 +43,6 @@ public class MonitoringTask implements Task {
private static final Log log = LogFactory.getLog(MonitoringTask.class); private static final Log log = LogFactory.getLog(MonitoringTask.class);
private static final int SUPER_TENANT_ID = -1234;
Map<String, String> properties; Map<String, String> properties;
@Override @Override
@ -88,23 +87,18 @@ public class MonitoringTask implements Task {
DeviceManagementProviderService deviceManagementService = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService deviceManagementService = new DeviceManagementProviderServiceImpl();
List<Integer> tenants = deviceManagementService.getDeviceEnrolledTenants(); List<Integer> tenants = deviceManagementService.getDeviceEnrolledTenants();
for (Integer tenant : tenants) { for (Integer tenant : tenants) {
if (SUPER_TENANT_ID == tenant) { if (MultitenantConstants.SUPER_TENANT_ID == tenant) {
this.executeTask(); this.executeTask();
continue; continue;
} }
String tenantDomain = PolicyManagementDataHolder.getInstance().
getRealmService().getTenantManager().getDomain(tenant);
try { try {
PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant, true);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant);
this.executeTask(); this.executeTask();
} finally { } finally {
PrivilegedCarbonContext.endTenantFlow(); PrivilegedCarbonContext.endTenantFlow();
} }
} }
} catch (UserStoreException e) {
log.error("Error occurred while trying to get the available tenants", e);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
log.error("Error occurred while trying to get the available tenants from device manager service ", e); log.error("Error occurred while trying to get the available tenants from device manager service ", e);
} }

Loading…
Cancel
Save