Beispiel #1
0
  // Experimental - to be debugged and tested
  public Presence getForeignUserPresence(String sender, String jid) throws UserNotFoundException {

    log.debug("getPresence : sender = " + sender + " jid = " + jid);

    if (jid == null) {
      throw new UserNotFoundException("Target JID not found in request");
    }

    JID targetJID = new JID(jid);
    // Check that the sender is not requesting information of a remote server entity
    if (targetJID.getDomain() == null || XMPPServer.getInstance().isRemote(targetJID)) {
      throw new UserNotFoundException("Domain does not matches local server domain");
    }
    if (!hostname.equals(targetJID.getDomain())) {
      // Sender is requesting information about component presence, so we send a
      // presence probe to the component.
      presenceManager.probePresence(componentJID, targetJID);

      // Wait 30 seconds until we get the probe presence result
      int count = 0;
      Presence presence = probedPresence.get(jid);
      while (presence == null) {
        if (count > 300) {
          // After 30 seconds, timeout
          throw new UserNotFoundException("Request for component presence has timed-out.");
        }
        try {
          Thread.sleep(100);
        } catch (InterruptedException e) {
          // don't care!
        }
        presence = probedPresence.get(jid);

        count++;
      }
      // Clean-up probe presence result
      probedPresence.remove(jid);
      // Return component presence
      return presence;
    }
    if (targetJID.getNode() == null
        || !UserManager.getInstance().isRegisteredUser(targetJID.getNode())) {
      // Sender is requesting presence information of an anonymous user
      throw new UserNotFoundException("Username is null");
    }
    User user = userManager.getUser(targetJID.getNode());
    log.debug("user = "******"isNameVisible " + user.isNameVisible());
    return ((PresenceManagerImpl) presenceManager).getPresence(user);
  }
  /**
   * Change name.
   *
   * @param currentUserName the current user name
   * @param newUserName the new user name
   * @param deleteOldUser the delete old user
   * @param newEmail the new email
   * @param newRealName the new real name
   * @return true, if successful
   * @throws ServiceException the service exception
   */
  public static boolean changeName(
      String currentUserName,
      String newUserName,
      boolean deleteOldUser,
      String newEmail,
      String newRealName)
      throws ServiceException {
    UserManager userManager = UserManager.getInstance();

    try {
      User currentUser = userManager.getUser(currentUserName);
      // Old user found, create new one
      String password = AuthFactory.getPassword(currentUserName);
      String newName =
          (newRealName == null || newRealName.length() == 0) ? currentUser.getName() : newRealName;
      String newMail =
          (newEmail == null || newEmail.length() == 0) ? currentUser.getEmail() : newEmail;
      User newUser = userManager.createUser(newUserName, password, currentUser.getName(), newMail);
      newUser.setName(newName);
      newUser.setNameVisible(currentUser.isNameVisible());
      newUser.setEmailVisible(currentUser.isEmailVisible());
      newUser.setCreationDate(currentUser.getCreationDate());

      copyRoster(currentUser, newUser, currentUserName);
      copyProperties(currentUser, newUser);
      copyToGroups(currentUserName, newUserName);
      copyVCard(currentUserName, newUserName);
      if (deleteOldUser) {
        deleteUser(currentUser);
      }

    } catch (UserNotFoundException e) {
      throw new ServiceException(
          "Could not find user",
          currentUserName,
          ExceptionType.USER_NOT_FOUND_EXCEPTION,
          Response.Status.NOT_FOUND,
          e);
    } catch (UserAlreadyExistsException e) {
      throw new ServiceException(
          "Could not create new user",
          newUserName,
          ExceptionType.USER_ALREADY_EXISTS_EXCEPTION,
          Response.Status.CONFLICT,
          e);
    }
    return true;
  }