@Override public void updatePassword(User newUser) { log.debug("Changing password for user {}", newUser); User user = userRepository.getByForgotPasswordHash(newUser.getForgotPasswordHash()); if (user == null) { throw new IllegalArgumentException("Could not find user for forgotPasswordHash " + newUser.getForgotPasswordHash()); } String saltedHashedPassword = passwordEncoder.encode(newUser.getPassword()); user.setPassword(saltedHashedPassword); // reset password hash and time user.setForgotPasswordHash(null); user.setForgotPasswordTime(null); userRepository.save(user); }
private void createRaveUserFromLdapInfo(DirContextOperations ctx, String username) { User newUser = new UserImpl(); newUser.setUsername(username); if (!ctx.attributeExists(mailAttributeName) || StringUtils.isBlank(ctx.getStringAttribute(mailAttributeName))) { throw new RuntimeException("Missing LDAP attribute for email for user " + username); } newUser.setEmail(ctx.getStringAttribute(mailAttributeName)); if (ctx.attributeExists(displayNameAttributeName)) { newUser.setDisplayName(ctx.getStringAttribute(displayNameAttributeName)); } newUser.setPassword(RandomStringUtils.random(16)); newUser.setDefaultPageLayoutCode(pageLayoutCode); try { newAccountService.createNewAccount(newUser); } catch (Exception e) { throw new RuntimeException("Could not bind LDAP username '{" + username + "}' to a user", e); } }
public static User convert(UserForm form) { User newUser = new UserImpl(form.getId(), form.getUsername()); newUser.setAuthorities(CollectionUtils.<Authority>toBaseTypedCollection(form.getAuthorities())); newUser.setPassword(form.getPassword()); newUser.setConfirmPassword(form.getConfirmPassword()); newUser.setForgotPasswordHash(form.getForgotPasswordHash()); newUser.setDefaultPageLayoutCode(form.getDefaultPageLayoutCode()); newUser.setStatus(form.getStatus()); newUser.setAboutMe(form.getAboutMe()); newUser.setGivenName(form.getGivenName()); newUser.setFamilyName(form.getFamilyName()); newUser.setDisplayName(form.getDisplayName()); newUser.setEmail(form.getEmail()); newUser.setOpenId(form.getOpenId()); newUser.setEnabled(form.isEnabled()); newUser.setExpired(form.isExpired()); newUser.setLocked(form.isLocked()); return newUser; } }
user.setEmail(email); String hashedPassword = passwordEncoder.encode(password); user.setPassword(hashedPassword);