*/
private void updateUser( HttpServletRequest request, HttpServletResponse response, Command command )
{
ArrayList<String> errors = new ArrayList<String>();
HashMap<String, String> fieldMessages = new HashMap<String, String>();
UserManager userManager = new UserManager();
User user = new User();
populateVBOFromRequest(user, request, fieldMessages, true);
Logger.debug("\n\n xxxxx" + fieldMessages.size() + "\n\n");
int userId = user.getUserId();
String pwd = user.getPwd();
String oldPwd = request.getParameter("oldPwd");
boolean isErrors = false;
User oldUser = null;
Project project = null;
boolean isUser = false;
// encrypt password if user is attempting to change password and no
// errors exist,
if ((!oldPwd.equals(pwd)) && (fieldMessages.size() == 0))
{
try
{
// encrypt and set new password
user.setPwd(Encrypt.encrypt(Configuration.getString("keyfile"), pwd));
if (pwd.length() > 40)
{
errors.add("Password length after encryption is greater than 40...");
isErrors = true;
}
}
catch( Exception ex )
{
isErrors = true;
Logger.error("\n Could not ENCRYPT password \n", ex);
errors.add("Security errors occurred while processing password");
}
}
// get user original record from database
try
{
oldUser = new UserManager().getUserById(userId, command);
if (oldUser == null)
{
isErrors = true;
errors.add("User ID was not found");
}
}
catch( NoSuchUserException nsue )
{
isErrors = true;
Logger.error("\n Attempting to updateUser but could not retrieve user by user_id " + userId + "\n", nsue);
errors.add("User ID was not found");
// request.setAttribute("errorMessage", "Could not find user - " +
// userId);
}
catch( NoSuchRoleException nsrex )
{
Logger.debug("Could not retrieve roles", nsrex);
request.setAttribute("errorMessage", "Could not retrieve roles...");
}
if (errors.size() == 0)
{
String oldContent = oldUser.toString();
// detect whether user data changed
Logger.debug("\n\n oldContent = " + oldContent.toString() + "\n\n");
Logger.debug("\n\n user content = " + user.toString() + "\n\n");
if (oldContent.equals(user.toString()))
{
errors.add("No changes detected.");
isErrors = true;
}
// if user is attempting to change userName,
// the system must validate user name doesn't exist
if (!oldUser.getUserName().equalsIgnoreCase(user.getUserName()))
{
// if user name exist add to errors messaging
isUser = userManager.isUserExist(user.getUserName().toLowerCase());
if (isUser)
{
errors.add("User Name: " + user.getUserName() + " already exist. Please enter another user name.");
isErrors = true;
}
}
// if no errors occurred update user record
if ((!isErrors) && (fieldMessages.size() == 0) && (errors.size() == 0))
{
try
{
User sessionUser = (User) request.getSession().getAttribute("user");
userManager.updateUser(new ProjectManager().getProject(command.getProject()), sessionUser, user, oldContent);
request.setAttribute("successMessage", "User successfully updated <span class=\"tinyformtext\">("
+ Calendar.getInstance().getTime().toString() + ")</span>");
}
catch( RoleUpdateAddException roleEx )