sinthuja 7 years ago
parent ddb8f4e9b3
commit c308147357

@ -88,12 +88,12 @@ public class UserManagementServiceImpl implements UserManagementService {
// Permissions that are given for a normal device user. // Permissions that are given for a normal device user.
private static final Permission[] PERMISSIONS_FOR_DEVICE_USER = { private static final Permission[] PERMISSIONS_FOR_DEVICE_USER = {
new Permission("/permission/admin/Login", "ui.execute"), new Permission("/permission/admin/Login", "ui.execute"),
new Permission("/permission/admin/device-mgt/device/api/subscribe", "ui.execute"), new Permission("/permission/admin/device-mgt/device/api/subscribe", "ui.execute"),
new Permission("/permission/admin/device-mgt/devices/enroll", "ui.execute"), new Permission("/permission/admin/device-mgt/devices/enroll", "ui.execute"),
new Permission("/permission/admin/device-mgt/devices/disenroll", "ui.execute"), new Permission("/permission/admin/device-mgt/devices/disenroll", "ui.execute"),
new Permission("/permission/admin/device-mgt/devices/owning-device/view", "ui.execute"), new Permission("/permission/admin/device-mgt/devices/owning-device/view", "ui.execute"),
new Permission("/permission/admin/manage/portal", "ui.execute") new Permission("/permission/admin/manage/portal", "ui.execute")
}; };
@POST @POST
@ -134,7 +134,7 @@ public class UserManagementServiceImpl implements UserManagementService {
} }
userStoreManager.addUser(userInfo.getUsername(), initialUserPassword, userStoreManager.addUser(userInfo.getUsername(), initialUserPassword,
roles, defaultUserClaims, null); roles, defaultUserClaims, null);
// Outputting debug message upon successful addition of user // Outputting debug message upon successful addition of user
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("User '" + userInfo.getUsername() + "' has successfully been added."); log.debug("User '" + userInfo.getUsername() + "' has successfully been added.");
@ -158,7 +158,7 @@ public class UserManagementServiceImpl implements UserManagementService {
dms.sendRegistrationEmail(metaInfo); dms.sendRegistrationEmail(metaInfo);
return Response.created(new URI(API_BASE_PATH + "/" + URIEncoder.encode(userInfo.getUsername(), "UTF-8"))) return Response.created(new URI(API_BASE_PATH + "/" + URIEncoder.encode(userInfo.getUsername(), "UTF-8")))
.entity( .entity(
createdUserInfo).build(); createdUserInfo).build();
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred while trying to add user '" + userInfo.getUsername() + "' to the " + String msg = "Error occurred while trying to add user '" + userInfo.getUsername() + "' to the " +
"underlying user management system"; "underlying user management system";
@ -227,11 +227,11 @@ public class UserManagementServiceImpl implements UserManagementService {
if (!userStoreManager.isExistingUser(username)) { if (!userStoreManager.isExistingUser(username)) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("User by username: " + username + log.debug("User by username: " + username +
" doesn't exists. Therefore, request made to update user was refused."); " doesn't exists. Therefore, request made to update user was refused.");
} }
return Response.status(Response.Status.NOT_FOUND).entity( return Response.status(Response.Status.NOT_FOUND).entity(
new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " + new ErrorResponse.ErrorResponseBuilder().setMessage("User by username: " +
username + " doesn't exist.").build()).build(); username + " doesn't exist.").build()).build();
} }
Map<String, String> defaultUserClaims = Map<String, String> defaultUserClaims =
@ -240,7 +240,7 @@ public class UserManagementServiceImpl implements UserManagementService {
if (StringUtils.isNotEmpty(userInfo.getPassword())) { if (StringUtils.isNotEmpty(userInfo.getPassword())) {
// Decoding Base64 encoded password // Decoding Base64 encoded password
userStoreManager.updateCredentialByAdmin(username, userStoreManager.updateCredentialByAdmin(username,
userInfo.getPassword()); userInfo.getPassword());
log.debug("User credential of username: " + username + " has been changed"); log.debug("User credential of username: " + username + " has been changed");
} }
List<String> currentRoles = this.getFilteredRoles(userStoreManager, username); List<String> currentRoles = this.getFilteredRoles(userStoreManager, username);
@ -259,8 +259,8 @@ public class UserManagementServiceImpl implements UserManagementService {
rolesToDelete.remove(ROLE_EVERYONE); rolesToDelete.remove(ROLE_EVERYONE);
rolesToAdd.remove(ROLE_EVERYONE); rolesToAdd.remove(ROLE_EVERYONE);
userStoreManager.updateRoleListOfUser(username, userStoreManager.updateRoleListOfUser(username,
rolesToDelete.toArray(new String[rolesToDelete.size()]), rolesToDelete.toArray(new String[rolesToDelete.size()]),
rolesToAdd.toArray(new String[rolesToAdd.size()])); rolesToAdd.toArray(new String[rolesToAdd.size()]));
userStoreManager.setUserClaimValues(username, defaultUserClaims, null); userStoreManager.setUserClaimValues(username, defaultUserClaims, null);
// Outputting debug message upon successful addition of user // Outputting debug message upon successful addition of user
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -363,7 +363,7 @@ public class UserManagementServiceImpl implements UserManagementService {
} }
RequestValidationUtil.validatePaginationParameters(offset, limit); RequestValidationUtil.validatePaginationParameters(offset, limit);
if (limit == 0){ if (limit == 0) {
limit = Constants.DEFAULT_PAGE_LIMIT; limit = Constants.DEFAULT_PAGE_LIMIT;
} }
List<BasicUserInfo> userList, offsetList; List<BasicUserInfo> userList, offsetList;
@ -475,7 +475,8 @@ public class UserManagementServiceImpl implements UserManagementService {
@GET @GET
@Path("/checkUser") @Path("/checkUser")
@Override public Response isUserExists(@QueryParam("username") String userName) { @Override
public Response isUserExists(@QueryParam("username") String userName) {
try { try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
boolean userExists = false; boolean userExists = false;
@ -496,7 +497,7 @@ public class UserManagementServiceImpl implements UserManagementService {
@Path("/search/usernames") @Path("/search/usernames")
@Override @Override
public Response getUserNames(@QueryParam("filter") String filter, @QueryParam("domain") String domain, public Response getUserNames(@QueryParam("filter") String filter, @QueryParam("domain") String domain,
@HeaderParam("If-Modified-Since") String timestamp, @HeaderParam("If-Modified-Since") String timestamp,
@QueryParam("offset") int offset, @QueryParam("limit") int limit) { @QueryParam("offset") int offset, @QueryParam("limit") int limit) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting the list of users with all user-related information using the filter : " + filter); log.debug("Getting the list of users with all user-related information using the filter : " + filter);
@ -505,21 +506,23 @@ public class UserManagementServiceImpl implements UserManagementService {
if (domain != null && !domain.isEmpty()) { if (domain != null && !domain.isEmpty()) {
userStoreDomain = domain; userStoreDomain = domain;
} }
if (limit == 0){
//If there is no limit is passed, then return all.
limit = -1;
}
List<UserInfo> userList; List<UserInfo> userList;
try { try {
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
String[] users = userStoreManager.listUsers(userStoreDomain + "/*", -1); String[] users = userStoreManager.listUsers(userStoreDomain + "/" + filter + "*", limit);
userList = new ArrayList<>(); userList = new ArrayList<>();
UserInfo user; UserInfo user;
for (String username : users) { for (String username : users) {
if (username.contains(filter)) { user = new UserInfo();
user = new UserInfo(); user.setUsername(username);
user.setUsername(username); user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS));
user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
user.setFirstname(getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME)); user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME));
user.setLastname(getClaimValue(username, Constants.USER_CLAIM_LAST_NAME)); userList.add(user);
userList.add(user);
}
} }
return Response.status(Response.Status.OK).entity(userList).build(); return Response.status(Response.Status.OK).entity(userList).build();
} catch (UserStoreException e) { } catch (UserStoreException e) {
@ -560,7 +563,7 @@ public class UserManagementServiceImpl implements UserManagementService {
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props); EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
dms.sendEnrolmentInvitation(DeviceManagementConstants.EmailAttributes.USER_ENROLLMENT_TEMPLATE, dms.sendEnrolmentInvitation(DeviceManagementConstants.EmailAttributes.USER_ENROLLMENT_TEMPLATE,
metaInfo); metaInfo);
} }
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
String msg = "Error occurred while inviting user to enrol their device"; String msg = "Error occurred while inviting user to enrol their device";
@ -662,8 +665,8 @@ public class UserManagementServiceImpl implements UserManagementService {
private String getEnrollmentTemplateName(String deviceType) { private String getEnrollmentTemplateName(String deviceType) {
String templateName = deviceType + "-enrollment-invitation"; String templateName = deviceType + "-enrollment-invitation";
File template = new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator File template = new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator
+ "resources" + File.separator + "email-templates" + File.separator + templateName + "resources" + File.separator + "email-templates" + File.separator + templateName
+ ".vm"); + ".vm");
if (template.exists()) { if (template.exists()) {
return templateName; return templateName;
} else { } else {

Loading…
Cancel
Save