|
|
@ -134,14 +134,14 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
public Response updateUser(@PathParam("username") String username, UserInfo userInfo) {
|
|
|
|
public Response updateUser(@PathParam("username") String username, UserInfo userInfo) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager();
|
|
|
|
if (!userStoreManager.isExistingUser(userInfo.getUsername())) {
|
|
|
|
if (!userStoreManager.isExistingUser(username)) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("User by username: " + userInfo.getUsername() +
|
|
|
|
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: " +
|
|
|
|
userInfo.getUsername() + " doesn't exist.").build()).build();
|
|
|
|
username + " doesn't exist.").build()).build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, String> defaultUserClaims =
|
|
|
|
Map<String, String> defaultUserClaims =
|
|
|
@ -149,11 +149,11 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
userInfo.getEmailAddress());
|
|
|
|
userInfo.getEmailAddress());
|
|
|
|
if (StringUtils.isNotEmpty(userInfo.getPassword())) {
|
|
|
|
if (StringUtils.isNotEmpty(userInfo.getPassword())) {
|
|
|
|
// Decoding Base64 encoded password
|
|
|
|
// Decoding Base64 encoded password
|
|
|
|
userStoreManager.updateCredentialByAdmin(userInfo.getUsername(),
|
|
|
|
userStoreManager.updateCredentialByAdmin(username,
|
|
|
|
userInfo.getPassword());
|
|
|
|
userInfo.getPassword());
|
|
|
|
log.debug("User credential of username: " + userInfo.getUsername() + " has been changed");
|
|
|
|
log.debug("User credential of username: " + username + " has been changed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<String> currentRoles = this.getFilteredRoles(userStoreManager, userInfo.getUsername());
|
|
|
|
List<String> currentRoles = this.getFilteredRoles(userStoreManager, username);
|
|
|
|
List<String> newRoles = Arrays.asList(userInfo.getRoles());
|
|
|
|
List<String> newRoles = Arrays.asList(userInfo.getRoles());
|
|
|
|
|
|
|
|
|
|
|
|
List<String> rolesToAdd = new ArrayList<>(newRoles);
|
|
|
|
List<String> rolesToAdd = new ArrayList<>(newRoles);
|
|
|
@ -167,19 +167,19 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rolesToDelete.remove(ROLE_EVERYONE);
|
|
|
|
rolesToDelete.remove(ROLE_EVERYONE);
|
|
|
|
userStoreManager.updateRoleListOfUser(userInfo.getUsername(),
|
|
|
|
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(userInfo.getUsername(), 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()) {
|
|
|
|
log.debug("User by username: " + userInfo.getUsername() + " was successfully updated.");
|
|
|
|
log.debug("User by username: " + username + " was successfully updated.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BasicUserInfo updatedUserInfo = this.getBasicUserInfo(username);
|
|
|
|
BasicUserInfo updatedUserInfo = this.getBasicUserInfo(username);
|
|
|
|
return Response.ok().entity(updatedUserInfo).build();
|
|
|
|
return Response.ok().entity(updatedUserInfo).build();
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
String msg = "Error occurred while trying to update user '" + userInfo.getUsername() + "'";
|
|
|
|
String msg = "Error occurred while trying to update user '" + username + "'";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
return Response.serverError().entity(
|
|
|
|
return Response.serverError().entity(
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
|
|
|