From 1fb777264de12a299f7d9db7fdb536929c1f9ac4 Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Thu, 1 Jun 2023 22:55:04 +0530 Subject: [PATCH] Check for logged in tenant id --- .../core/dao/impl/geofence/SQLServerGeofenceDAOImpl.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/geofence/SQLServerGeofenceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/geofence/SQLServerGeofenceDAOImpl.java index 0713f3c578..fa04264286 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/geofence/SQLServerGeofenceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/geofence/SQLServerGeofenceDAOImpl.java @@ -26,6 +26,7 @@ import io.entgra.device.mgt.core.device.mgt.common.geo.service.GeofenceData; import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.dao.EventManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.dao.impl.AbstractGeofenceDAOImpl; +import org.wso2.carbon.context.CarbonContext; import java.sql.Connection; import java.sql.PreparedStatement; @@ -114,7 +115,7 @@ public class SQLServerGeofenceDAOImpl extends AbstractGeofenceDAOImpl { if (!requireGroupData) { return getGeofence(fenceId); } - + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); try { Connection con = this.getConnection(); String sql = "SELECT " + @@ -131,9 +132,11 @@ public class SQLServerGeofenceDAOImpl extends AbstractGeofenceDAOImpl { "FROM DM_GEOFENCE G, DM_GEOFENCE_GROUP_MAPPING M, DM_GROUP GR " + "WHERE G.ID = M.FENCE_ID " + "AND M.GROUP_ID = GR.ID " + - "AND G.ID = ?"; + "AND G.ID = ? " + + "AND G.TENANT_ID = ?"; try (PreparedStatement stmt = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)) { stmt.setInt(1, fenceId); + stmt.setInt(2, tenantId); try (ResultSet rst = stmt.executeQuery()) { Map groupMap = new HashMap<>(); GeofenceData geofenceData = null;