diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index 6097b4e43a..ce403fa281 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -288,12 +288,12 @@ public interface UserManagementService { httpMethod = "GET", value = "Get user list", notes = "If you wish to get the details of all the users registered with EMM, you can do so " - + "using the REST API", + + "using this REST API", tags = "User Management") @ApiResponses(value = { @ApiResponse( code = 200, - message = "OK. \n Successfully fetched the requested role.", + message = "OK. \n Successfully fetched the requested users.", response = BasicUserInfoList.class, responseHeaders = { @ResponseHeader( @@ -343,6 +343,36 @@ public interface UserManagementService { required = false) @QueryParam("limit") int limit); + @GET + @Path("/count") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Get user count", + notes = "If you wish to get the user count registered with EMM, you can do so using this REST API", + tags = "User Management") + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the user count.", + response = BasicUserInfoList.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body") + }), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching the user list.", + response = ErrorResponse.class) + }) + @Permission(name = "View Users", permission = "/device-mgt/users/view") + Response getUserCount(); + @GET @Path("/search/usernames") @ApiOperation( 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 6df497f8c1..df34771125 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 @@ -316,6 +316,26 @@ public class UserManagementServiceImpl implements UserManagementService { } } + @GET + @Path("/count") + @Override + public Response getUserCount() { + if (log.isDebugEnabled()) { + log.debug("Getting the user count"); + } + + try { + UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); + int userCount = userStoreManager.listUsers("*", -1).length; + return Response.status(Response.Status.OK).entity(userCount).build(); + } catch (UserStoreException e) { + String msg = "Error occurred while retrieving the user count."; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + } + @GET @Path("/search/usernames") @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index 4b205346d9..b970b04cf9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -40,7 +40,7 @@ deviceModule = function () { // var deviceCloudService = devicemgtProps["httpsURL"] + "/common/device_manager"; -/** + /** * Only GET method is implemented for now since there are no other type of methods used this method. * @param url - URL to call the backend without the host * @param method - HTTP Method (GET, POST) @@ -273,6 +273,9 @@ deviceModule = function () { deviceObject[constants["DEVICE_PROPERTIES"]] = properties; response["content"] = deviceObject; return response; + } else if (backendResponse.status == 401) { + response["status"] = "unauthorized"; + return response; } else { response["status"] = "error"; return response; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.certificates/certificates.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.certificates/certificates.hbs index d17a3bd4d3..6d2322f82c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.certificates/certificates.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.certificates/certificates.hbs @@ -131,48 +131,49 @@