예제 #1
0
  /** {@inheritDoc} */
  @Override
  public User saveExistingUser(final User user) {
    // Existing user, check password in DB
    UserDetails existingUser = null;

    try {
      existingUser = dao.loadUserByUsername(user.getUsername());
    } catch (final UsernameNotFoundException e) {
      // username could not be found
    }

    String currentPassword = "";
    if (existingUser == null) {
      // lowercase userId
      ((UserImpl) user).setUsername(user.getUsername().toLowerCase());
    } else {
      currentPassword = existingUser.getPassword();
    }

    // if new user or changed password, encrypt the password
    if (StringUtils.isBlank(currentPassword) || !currentPassword.equals(user.getPassword())) {
      ((UserImpl) user).setPassword(passwordEncoder.encodePassword(user.getPassword(), null));
    }

    return dao.save(user);
  }
예제 #2
0
  /** {@inheritDoc} */
  @Override
  public User save(final User user) {
    ((UserImpl) user).setPassword(passwordEncoder.encodePassword(user.getPassword(), null));

    return dao.save(user);
  }