From e786fa410b33d38c5bb59211969f15bc1f469471 Mon Sep 17 00:00:00 2001 From: Madawa Soysa Date: Thu, 21 Dec 2017 17:06:28 +0530 Subject: [PATCH] Checking if the user store manager class is a sub class of the default This commit is to modify the current logic which checks if the UserStoreManager class is equal to the JDBCUserStoreManager class to support subclasses of the JDBCUserStoreManager class to return correct total user count. In this commit, instead of comparing the string name, tests the UserStoreManager instance is a type of JDBCUserStoreManager. Resolves wso2/product-iots#1556 --- .../wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.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/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index cbbfaf32ce3..02f8ce62a97 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -222,14 +222,13 @@ public class DeviceMgtAPIUtils { public static UserStoreCountRetriever getUserStoreCountRetrieverService() - throws UserStoreCounterException { + throws UserStoreCounterException, UserStoreException { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); List countRetrieverFactories = ctx.getOSGiServices(AbstractCountRetrieverFactory.class, null); RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null); RealmConfiguration realmConfiguration = realmService.getBootstrapRealmConfiguration(); String userStoreType; - //Ignoring Sonar warning as getUserStoreClass() returning string name of the class. So cannot use 'instanceof'. - if (JDBCUserStoreManager.class.getName().equals(realmConfiguration.getUserStoreClass())) { + if(DeviceMgtAPIUtils.getUserStoreManager() instanceof JDBCUserStoreManager) { userStoreType = JDBCCountRetrieverFactory.JDBC; } else { userStoreType = InternalCountRetrieverFactory.INTERNAL;