private boolean exists(User user) { if (user == null || user.getId() == null) { return false; } if (!userRepository.exists(user.getId())) { return false; } return true; }
private User saveUser(User user) { if (!exists(user)) { user.setCreated(new Date()); } if (isUserNameAlreadyTaken(user.getName())) { throw new UserNameIsTakenException("Name " + user.getName() + " has already been taken."); } User u = userRepository.save(user); return u; }
@Transactional @Override public User saveUserWithNewPassword(User user, Set<String> authorityNames, String rawPassword) { List<Authority> authorities = retrieveAuthoritiesByNames(authorityNames); // Surely whatever was in user authorities is discarded at this point user.setAuthorities(authorities); return saveUserWithNewPassword(user, rawPassword); }
@Transactional @Override public User saveUserWithNewPassword(User user, String rawPassword) { validate(user, rawPassword); user.setPassword(passwordEncoder.encode(rawPassword)); user = saveUser(user); return user; }