Adding user management API bug fixes and improvements

revert-70aa11f8
Ace 9 years ago
parent d13368d144
commit ddfd678b2a

@ -22,6 +22,7 @@ import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserList;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper;
import javax.ws.rs.*;
@ -279,14 +280,14 @@ public interface UserManagementService {
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",
response = UserWrapper.class,
response = UserList.class,
responseContainer = "List",
tags = "User Management")
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched the requested role.",
response = UserWrapper.class,
response = UserList.class,
responseContainer = "List",
responseHeaders = {
@ResponseHeader(
@ -303,7 +304,7 @@ public interface UserManagementService {
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),

@ -27,6 +27,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserList;
import org.wso2.carbon.device.mgt.jaxrs.beans.UserWrapper;
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
@ -142,10 +143,10 @@ public class UserManagementServiceImpl implements UserManagementService {
Properties props = new Properties();
props.setProperty("username", usernameBits[1]);
props.setProperty("domain-name", tenantDomain);
props.setProperty("first-name", getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
props.setProperty("first-name", getClaimValue(usernameBits[1], Constants.USER_CLAIM_FIRST_NAME));
props.setProperty("password", password);
String recipient = getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS);
String recipient = getClaimValue(usernameBits[1], Constants.USER_CLAIM_EMAIL_ADDRESS);
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
@ -329,10 +330,15 @@ public class UserManagementServiceImpl implements UserManagementService {
if (log.isDebugEnabled()) {
log.debug("Getting the list of users with all user-related information");
}
List<UserWrapper> userList;
List<UserWrapper> userList, offsetList;
String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter);
int appliedLimit = (limit <= 0) ? -1 : (limit + offset);
try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
String[] users = userStoreManager.listUsers("*", -1);
//As the listUsers function accepts limit only to accommodate offset we are passing offset + limit
String[] users = userStoreManager.listUsers(appliedFilter, appliedLimit);
userList = new ArrayList<>(users.length);
UserWrapper user;
for (String username : users) {
@ -343,12 +349,24 @@ public class UserManagementServiceImpl implements UserManagementService {
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
userList.add(user);
}
if (userList.size() <= 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No user is available to be retrieved").build();
if (offset <= userList.size()) {
offsetList = userList.subList(offset, userList.size());
} else {
offsetList = new ArrayList<>();
}
return Response.status(Response.Status.OK).entity(userList).build();
if (offsetList.size() <= 0) {
return Response.status(Response.Status.NOT_FOUND).entity("No users available for retrieval").build();
}
UserList result = new UserList();
result.setList(offsetList);
result.setCount(offsetList.size());
return Response.status(Response.Status.OK).entity(result).build();
} catch (UserStoreException e) {
String msg = "ErrorResponse occurred while retrieving the list of users";
String msg = "ErrorResponse occurred while retrieving the list of users.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}

Loading…
Cancel
Save