From 79018f9a4c84d2704c8d2ccd56967299986ec91d Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 2 Feb 2017 15:52:41 +0530 Subject: [PATCH 1/4] Fix https://wso2.org/jira/browse/IOTS-436 --- .../org.wso2.carbon.device.mgt.api/pom.xml | 6 ++++ .../mgt/jaxrs/beans/BasePaginatedResult.java | 6 ++-- .../impl/UserManagementServiceImpl.java | 26 +++++++++++++++ .../mgt/jaxrs/util/DeviceMgtAPIUtils.java | 33 +++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index b572c746c5f..b0e27a25a91 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -281,6 +281,12 @@ javax.ws.rs javax.ws.rs-api + + org.wso2.carbon.identity.framework + org.wso2.carbon.identity.user.store.count + ${carbon.identity.framework.version} + provided + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java index 8d1c82d8d75..5c2936a1a3d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/BasePaginatedResult.java @@ -30,13 +30,13 @@ public class BasePaginatedResult { value = "Number of total resources.", example = "1") @JsonProperty("count") - private int count; + private long count; - public int getCount() { + public long getCount() { return count; } - public void setCount(int count) { + public void setCount(long count) { this.count = count; } } \ No newline at end of file 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 2b5a2e8d455..ca1ad45d1d3 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 @@ -38,6 +38,8 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder; 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.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.utils.CarbonUtils; @@ -395,6 +397,30 @@ public class UserManagementServiceImpl implements UserManagementService { @Path("/count") @Override public Response getUserCount() { + try { + UserStoreCountRetriever userStoreCountRetrieverService = DeviceMgtAPIUtils.getUserStoreCountRetrieverService(); + if (userStoreCountRetrieverService != null) { + long count = userStoreCountRetrieverService.countUsers(""); + if (count != -1) { + BasicUserInfoList result = new BasicUserInfoList(); + result.setCount(count); + return Response.status(Response.Status.OK).entity(result).build(); + } + } + } catch (UserStoreCounterException e) { + String msg = + "Error occurred while retrieving the count of users that exist within the current tenant"; + log.error(msg, e); + } + return getUserCountViaUserStoreManager(); + } + + /** + * This method returns the count of users using UserStoreManager. + * + * @return user count + */ + private Response getUserCountViaUserStoreManager() { if (log.isDebugEnabled()) { log.debug("Getting the user count"); } 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 afc03336d55..e372cf52c46 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 @@ -37,13 +37,20 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.InputValidationException; +import org.wso2.carbon.identity.user.store.count.AbstractCountRetrieverFactory; +import org.wso2.carbon.identity.user.store.count.UserStoreCountRetriever; +import org.wso2.carbon.identity.user.store.count.exception.UserStoreCounterException; +import org.wso2.carbon.identity.user.store.count.jdbc.JDBCCountRetrieverFactory; +import org.wso2.carbon.identity.user.store.count.jdbc.internal.InternalCountRetrieverFactory; import org.wso2.carbon.policy.mgt.common.PolicyMonitoringTaskException; import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.policy.mgt.core.task.TaskScheduleService; import org.wso2.carbon.user.api.AuthorizationManager; +import org.wso2.carbon.user.api.RealmConfiguration; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; +import org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager; import org.wso2.carbon.user.core.service.RealmService; import javax.ws.rs.core.MediaType; @@ -105,6 +112,32 @@ public class DeviceMgtAPIUtils { return deviceManagementProviderService; } + public static UserStoreCountRetriever getUserStoreCountRetrieverService() + throws UserStoreCounterException { + 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())) { + userStoreType = JDBCCountRetrieverFactory.JDBC; + } else { + userStoreType = InternalCountRetrieverFactory.INTERNAL; + } + AbstractCountRetrieverFactory countRetrieverFactory = null; + for (Object countRetrieverFactoryObj : countRetrieverFactories) { + countRetrieverFactory = (AbstractCountRetrieverFactory) countRetrieverFactoryObj; + if (userStoreType.equals(countRetrieverFactory.getCounterType())) { + break; + } + } + if (countRetrieverFactory == null) { + return null; + } + return countRetrieverFactory.buildCountRetriever(realmConfiguration); + } + public static DeviceAccessAuthorizationService getDeviceAccessAuthorizationService() { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); DeviceAccessAuthorizationService deviceAccessAuthorizationService = From c224fe7cab68924939038d4c69b98f3e3c31181f Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 2 Feb 2017 19:28:07 +0530 Subject: [PATCH 2/4] Fix https://wso2.org/jira/browse/IOTS-436 --- .../devicemgt/app/modules/business-controllers/user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index c6ed7da1bdb..31567cf4ce4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -174,7 +174,7 @@ var userModule = function () { } try { utility.startTenantFlow(carbonUser); - var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users?offset=0&limit=1"; + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + "/users/count"; return serviceInvokers.XMLHttp.get( url, function (responsePayload) { return parse(responsePayload["responseText"])["count"]; From b5768dde117141af0f8660eb2ffedc9f9281de88 Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 28 Feb 2017 14:49:06 +0530 Subject: [PATCH 3/4] Fix minor issues found with jmeter tests --- .../mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java | 9 --------- .../provider/gcm/GCMNotificationStrategy.java | 2 +- .../wso2/carbon/device/mgt/common/search/Condition.java | 2 +- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java index e119746c911..be0bb8edce3 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java @@ -21,15 +21,6 @@ package org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans; public class EnrollmentCertificate { String serial; String pem; - int tenantId; - - public int getTenantId() { - return tenantId; - } - - public void setTenantId(int tenantId) { - this.tenantId = tenantId; - } public String getSerial() { return serial; diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java index af93b692a47..f894e182499 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm/src/main/java/org/wso2/carbon/device/mgt/extensions/push/notification/provider/gcm/GCMNotificationStrategy.java @@ -38,7 +38,7 @@ import java.util.List; public class GCMNotificationStrategy implements NotificationStrategy { private static final String GCM_TOKEN = "GCM_TOKEN"; - private final static String GCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send"; + private static final String GCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send"; private static final String GCM_API_KEY = "gcmAPIKey"; private static final int TIME_TO_LIVE = 60; private static final int HTTP_STATUS_CODE_OK = 200; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java index 2007a3f121b..8483788e9d2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/Condition.java @@ -25,7 +25,7 @@ import io.swagger.annotations.ApiModelProperty; @ApiModel(value = "Condition", description = "Contains the advance search parameters.") public class Condition { - @ApiModelProperty(name = "conditions", value = "Provide the operation code. You can assign the following operation " + + @ApiModelProperty(name = "key", value = "Provide the operation code. You can assign the following operation " + "codes:\n" + "DEVICE_MODEL : The model of the device.\n" + "VENDOR : The name of the device vendor.\n" + From 8ad49c86f8bdb0b749a8432a17f95af71bb9d9a1 Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 28 Feb 2017 14:59:29 +0530 Subject: [PATCH 4/4] Add tenant id to Enrollment Certificate --- .../mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java index be0bb8edce3..e119746c911 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/beans/EnrollmentCertificate.java @@ -21,6 +21,15 @@ package org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans; public class EnrollmentCertificate { String serial; String pem; + int tenantId; + + public int getTenantId() { + return tenantId; + } + + public void setTenantId(int tenantId) { + this.tenantId = tenantId; + } public String getSerial() { return serial;