code: public void changePassword(final String oldPassword,
              final String newPassword) {
  
          final Authentication currentUser =
                  SecurityContextHolder.getContext().getAuthentication();
          final String username = currentUser.getName();
  
          if (authenticationManager == null) {
              logger.debug(
                      "No authentication manager set. can't change Password!");
  
              return;
          } else {
              logger.debug("Re-authenticating user '" + username
                      + "' for password change request.");
  
              authenticationManager.authenticate(
                      new UsernamePasswordAuthenticationToken(username,
                              oldPassword));
          }
  
          logger.debug("Changing password for user '" + username + "'");
  
          final SecurityUser user = (SecurityUser) loadUserByUsername(username);
  
          user.setPassword(passwordEncoder.encode(newPassword));
          users.add(user);
      }
docs: Change password of current user.
  
  @param oldPassword old password
  @param newPassword new password