/** * Change name. * * @param currentUserName the current user name * @param newUserName the new user name * @param deleteOldUser the delete old user * @param newEmail the new email * @param newRealName the new real name * @return true, if successful * @throws ServiceException the service exception */ public static boolean changeName( String currentUserName, String newUserName, boolean deleteOldUser, String newEmail, String newRealName) throws ServiceException { UserManager userManager = UserManager.getInstance(); try { User currentUser = userManager.getUser(currentUserName); // Old user found, create new one String password = AuthFactory.getPassword(currentUserName); String newName = (newRealName == null || newRealName.length() == 0) ? currentUser.getName() : newRealName; String newMail = (newEmail == null || newEmail.length() == 0) ? currentUser.getEmail() : newEmail; User newUser = userManager.createUser(newUserName, password, currentUser.getName(), newMail); newUser.setName(newName); newUser.setNameVisible(currentUser.isNameVisible()); newUser.setEmailVisible(currentUser.isEmailVisible()); newUser.setCreationDate(currentUser.getCreationDate()); copyRoster(currentUser, newUser, currentUserName); copyProperties(currentUser, newUser); copyToGroups(currentUserName, newUserName); copyVCard(currentUserName, newUserName); if (deleteOldUser) { deleteUser(currentUser); } } catch (UserNotFoundException e) { throw new ServiceException( "Could not find user", currentUserName, ExceptionType.USER_NOT_FOUND_EXCEPTION, Response.Status.NOT_FOUND, e); } catch (UserAlreadyExistsException e) { throw new ServiceException( "Could not create new user", newUserName, ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.CONFLICT, e); } return true; }
public void createUserAccount( String userName, String password, String displayName, String email) { try { User user = userManager.getUser(userName); user.setPassword(password); user.setName(displayName); user.setEmail(email); } catch (UserNotFoundException e) { try { userManager.createUser(userName, password, displayName, email); } catch (UserAlreadyExistsException ex) { throw new SipXOpenfirePluginException(ex); } } }