From 9206f747907cdf972106fb3aceeab533a743cd6e Mon Sep 17 00:00:00 2001 From: Hasunie Date: Fri, 23 Jun 2017 17:39:42 +0530 Subject: [PATCH] Fixing issue wso2/product-iot##527 --- .../service/impl/UserManagementServiceImpl.java | 15 +++++++++++++++ .../carbon/device/mgt/jaxrs/util/Constants.java | 1 + 2 files changed, 16 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index a90b51d409..23ddfe69cf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -22,6 +22,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.eclipse.wst.common.uriresolver.internal.util.URIEncoder; +import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; @@ -41,6 +42,7 @@ import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.identity.user.store.count.UserStoreCountRetriever; import org.wso2.carbon.identity.user.store.count.exception.UserStoreCounterException; import org.wso2.carbon.user.api.Permission; +import org.wso2.carbon.user.api.RealmConfiguration; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.utils.CarbonUtils; @@ -412,6 +414,15 @@ public class UserManagementServiceImpl implements UserManagementService { public Response getUserCount() { try { UserStoreCountRetriever userStoreCountRetrieverService = DeviceMgtAPIUtils.getUserStoreCountRetrieverService(); + RealmConfiguration secondaryRealmConfiguration = CarbonContext.getThreadLocalCarbonContext().getUserRealm(). + getRealmConfiguration().getSecondaryRealmConfig(); + + if (secondaryRealmConfiguration != null) { + if (!secondaryRealmConfiguration.isPrimary() && !Constants.JDBC_USERSTOREMANAGER. + equals(secondaryRealmConfiguration.getUserStoreClass().getClass())) { + return getUserCountViaUserStoreManager(); + } + } if (userStoreCountRetrieverService != null) { long count = userStoreCountRetrieverService.countUsers(""); if (count != -1) { @@ -424,6 +435,10 @@ public class UserManagementServiceImpl implements UserManagementService { String msg = "Error occurred while retrieving the count of users that exist within the current tenant"; log.error(msg, e); + } catch (UserStoreException e) { + String msg = + "Error occurred while retrieving user stores."; + log.error(msg, e); } return getUserCountViaUserStoreManager(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java index c5fa21ae89..6e203dd860 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/Constants.java @@ -28,6 +28,7 @@ public class Constants { public static final String USER_CLAIM_LAST_NAME = "http://wso2.org/claims/lastname"; public static final String PRIMARY_USER_STORE = "PRIMARY"; public static final String SCOPE = "scope"; + public static final String JDBC_USERSTOREMANAGER = "org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager"; public final class ErrorMessages { private ErrorMessages () { throw new AssertionError(); }