Example #1
0
  /** {@inheritDoc} */
  @Override
  public User saveUser(final User user) throws UserExistsException {

    if (user.getVersion() == null) {
      // if new user, lowercase userId
      user.setUsername(user.getUsername().toLowerCase());
    }

    // Get and prepare password management-related artifacts
    boolean passwordChanged = false;
    if (passwordEncoder != null) {
      // Check whether we have to encrypt (or re-encrypt) the password
      if (user.getVersion() == null) {
        // New user, always encrypt
        passwordChanged = true;
      } else {
        // Existing user, check password in DB
        final String currentPassword = userDao.getUserPassword(user.getId());
        if (currentPassword == null) {
          passwordChanged = true;
        } else {
          if (!currentPassword.equals(user.getPassword())) {
            passwordChanged = true;
          }
        }
      }

      // If password was changed (or new user), encrypt it
      if (passwordChanged) {
        user.setPassword(passwordEncoder.encode(user.getPassword()));
      }
    } else {
      log.warn("PasswordEncoder not set, skipping password encryption...");
    }

    try {
      return userDao.saveUser(user);
    } catch (final Exception e) {
      e.printStackTrace();
      log.warn(e.getMessage());
      throw new UserExistsException("User '" + user.getUsername() + "' already exists!");
    }
  }
Example #2
0
 /** {@inheritDoc} */
 @Override
 public User getUser(final String userId) {
   return userDao.get(new Long(userId));
 }
Example #3
0
 /**
  * {@inheritDoc}
  *
  * @param username the login name of the human
  * @return User the populated user object
  * @throws org.springframework.security.core.userdetails.UsernameNotFoundException thrown when
  *     username not found
  */
 @Override
 public User getUserByUsername(final String username) throws UsernameNotFoundException {
   return (User) userDao.loadUserByUsername(username);
 }
Example #4
0
 /** {@inheritDoc} */
 @Override
 public void removeUser(final String userId) {
   log.debug("removing user: " + userId);
   userDao.remove(new Long(userId));
 }
Example #5
0
 /** {@inheritDoc} */
 @Override
 public void removeUser(final User user) {
   log.debug("removing user: " + user);
   userDao.remove(user);
 }
Example #6
0
 /** {@inheritDoc} */
 @Override
 public List<User> getUsers() {
   return userDao.getAllDistinct();
 }