From 1721824d53cf649315fcd8fe555ee17ab977e7b4 Mon Sep 17 00:00:00 2001 From: Ace Date: Wed, 17 Oct 2018 16:49:29 +0530 Subject: [PATCH 1/5] Fixing issue where super tenant table space is querried instead of relavent tenant when retrieving geo location data --- .../mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index a8811e54186..854972b833d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -97,7 +97,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { // this is the user who initiates the request String authorizedUser = MultitenantUtils.getTenantAwareUsername( - CarbonContext.getThreadLocalCarbonContext().getUsername()); + CarbonContext.getThreadLocalCarbonContext().getUsername() + "@" + + CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); try { String tenantDomain = MultitenantUtils.getTenantDomain(authorizedUser); From 4aee621039621559c28f6103aaeef87fcc2a0525 Mon Sep 17 00:00:00 2001 From: Ace Date: Wed, 17 Oct 2018 20:30:17 +0530 Subject: [PATCH 2/5] Fixing tenanted username --- .../mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index 854972b833d..fecf3ea6b4c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -96,9 +96,8 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { sortByFields.add(sortByField); // this is the user who initiates the request - String authorizedUser = MultitenantUtils.getTenantAwareUsername( - CarbonContext.getThreadLocalCarbonContext().getUsername() + "@" + - CarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername() + "@" + + CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); try { String tenantDomain = MultitenantUtils.getTenantDomain(authorizedUser); From b39be48919980698c7428a29fcea9c3c8730c57c Mon Sep 17 00:00:00 2001 From: Ace Date: Thu, 18 Oct 2018 11:31:10 +0530 Subject: [PATCH 3/5] Adding constants --- .../impl/GeoLocationBasedServiceImpl.java | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index fecf3ea6b4c..955b3386808 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -63,6 +63,12 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { private static Log log = LogFactory.getLog(GeoLocationBasedServiceImpl.class); + public static final String EMAIL_DOMAIN_SEPARATOR = "@"; + + public static final String EMAIL_DOMAIN_SEPARATOR_REPLACEMENT = "-AT-"; + public static final String SECONDERY_USER_STORE_SEPERATOR = ":"; + public static final String SECONDERY_USER_STORE_DEFAULT_SEPERATOR = "/"; + @Path("stats/{deviceType}/{deviceId}") @GET @Consumes("application/json") @@ -96,7 +102,7 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { sortByFields.add(sortByField); // this is the user who initiates the request - String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername() + "@" + + String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername() + EMAIL_DOMAIN_SEPARATOR + CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); try { @@ -577,4 +583,46 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { eventBean.setValues(record.getValues()); return eventBean; } + + + + /** + * When an input is having '@',replace it with '-AT-' [This is required to + * persist WebApp data in registry,as registry paths don't allow '@' sign.] + * + * @param input + * inputString + * @return String modifiedString + */ + public static String replaceEmailDomain(String input) { + if (input != null && input.contains(EMAIL_DOMAIN_SEPARATOR)) { + input = + input.replace(EMAIL_DOMAIN_SEPARATOR, + EMAIL_DOMAIN_SEPARATOR_REPLACEMENT); + } + return input; + } + + /** + * When an input is having '-AT-',replace it with @ [This is required to + * persist WebApp data between registry and database] + * + * @param input + * inputString + * @return String modifiedString + */ + public static String replaceEmailDomainBack(String input) { + if (input != null){ + if (input.contains(EMAIL_DOMAIN_SEPARATOR_REPLACEMENT)) { + input = + input.replace(EMAIL_DOMAIN_SEPARATOR_REPLACEMENT, + EMAIL_DOMAIN_SEPARATOR); + }else if (input.contains(SECONDERY_USER_STORE_SEPERATOR)){ + input = + input.replace(SECONDERY_USER_STORE_SEPERATOR, + SECONDERY_USER_STORE_DEFAULT_SEPERATOR); + } + } + return input; + } } From 92bf6f4140a3af89098b77b02813787615c71175 Mon Sep 17 00:00:00 2001 From: Ace Date: Thu, 18 Oct 2018 11:36:12 +0530 Subject: [PATCH 4/5] Fixing formatting issues --- .../service/impl/GeoLocationBasedServiceImpl.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index 955b3386808..2b93290777f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -585,13 +585,11 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { } - /** * When an input is having '@',replace it with '-AT-' [This is required to * persist WebApp data in registry,as registry paths don't allow '@' sign.] * - * @param input - * inputString + * @param input inputString * @return String modifiedString */ public static String replaceEmailDomain(String input) { @@ -607,17 +605,16 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { * When an input is having '-AT-',replace it with @ [This is required to * persist WebApp data between registry and database] * - * @param input - * inputString + * @param input inputString * @return String modifiedString */ public static String replaceEmailDomainBack(String input) { - if (input != null){ + if (input != null) { if (input.contains(EMAIL_DOMAIN_SEPARATOR_REPLACEMENT)) { input = input.replace(EMAIL_DOMAIN_SEPARATOR_REPLACEMENT, EMAIL_DOMAIN_SEPARATOR); - }else if (input.contains(SECONDERY_USER_STORE_SEPERATOR)){ + } else if (input.contains(SECONDERY_USER_STORE_SEPERATOR)) { input = input.replace(SECONDERY_USER_STORE_SEPERATOR, SECONDERY_USER_STORE_DEFAULT_SEPERATOR); From 3f77a3b27c540cf0d34cdfe87d3d11757b0b21e8 Mon Sep 17 00:00:00 2001 From: Ace Date: Thu, 18 Oct 2018 11:55:20 +0530 Subject: [PATCH 5/5] Adding correct tenant ID --- .../impl/GeoLocationBasedServiceImpl.java | 51 ++----------------- 1 file changed, 3 insertions(+), 48 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java index 2b93290777f..add4acef72a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/GeoLocationBasedServiceImpl.java @@ -63,12 +63,6 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { private static Log log = LogFactory.getLog(GeoLocationBasedServiceImpl.class); - public static final String EMAIL_DOMAIN_SEPARATOR = "@"; - - public static final String EMAIL_DOMAIN_SEPARATOR_REPLACEMENT = "-AT-"; - public static final String SECONDERY_USER_STORE_SEPERATOR = ":"; - public static final String SECONDERY_USER_STORE_DEFAULT_SEPERATOR = "/"; - @Path("stats/{deviceType}/{deviceId}") @GET @Consumes("application/json") @@ -102,11 +96,11 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { sortByFields.add(sortByField); // this is the user who initiates the request - String authorizedUser = CarbonContext.getThreadLocalCarbonContext().getUsername() + EMAIL_DOMAIN_SEPARATOR + - CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + String authorizedUser = MultitenantUtils.getTenantAwareUsername( + CarbonContext.getThreadLocalCarbonContext().getUsername()); try { - String tenantDomain = MultitenantUtils.getTenantDomain(authorizedUser); + String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); int tenantId = DeviceMgtAPIUtils.getRealmService().getTenantManager().getTenantId(tenantDomain); AnalyticsDataAPI analyticsDataAPI = DeviceMgtAPIUtils.getAnalyticsDataAPI(); List searchResults = analyticsDataAPI.search(tenantId, tableName, query, @@ -583,43 +577,4 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService { eventBean.setValues(record.getValues()); return eventBean; } - - - /** - * When an input is having '@',replace it with '-AT-' [This is required to - * persist WebApp data in registry,as registry paths don't allow '@' sign.] - * - * @param input inputString - * @return String modifiedString - */ - public static String replaceEmailDomain(String input) { - if (input != null && input.contains(EMAIL_DOMAIN_SEPARATOR)) { - input = - input.replace(EMAIL_DOMAIN_SEPARATOR, - EMAIL_DOMAIN_SEPARATOR_REPLACEMENT); - } - return input; - } - - /** - * When an input is having '-AT-',replace it with @ [This is required to - * persist WebApp data between registry and database] - * - * @param input inputString - * @return String modifiedString - */ - public static String replaceEmailDomainBack(String input) { - if (input != null) { - if (input.contains(EMAIL_DOMAIN_SEPARATOR_REPLACEMENT)) { - input = - input.replace(EMAIL_DOMAIN_SEPARATOR_REPLACEMENT, - EMAIL_DOMAIN_SEPARATOR); - } else if (input.contains(SECONDERY_USER_STORE_SEPERATOR)) { - input = - input.replace(SECONDERY_USER_STORE_SEPERATOR, - SECONDERY_USER_STORE_DEFAULT_SEPERATOR); - } - } - return input; - } }