|
|
|
@ -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();
|
|
|
|
|
}
|
|
|
|
|