예제 #1
0
  private void removeSharedGroupFromRoster(Group group, String username) {
    // Get the group users to remove from the user's roster
    Collection<String> users = new HashSet<String>(group.getMembers());
    users.addAll(group.getAdmins());

    // Get the roster of the user from which we need to remove the shared group users
    Roster userRoster = (Roster) CacheManager.getCache("username2roster").get(username);

    // Iterate on all the group users and update their rosters
    for (String userToRemove : users) {
      // Get the roster to update
      Roster roster = (Roster) CacheManager.getCache("username2roster").get(userToRemove);
      // Only update rosters in memory
      if (roster != null) {
        roster.deleteSharedUser(group, username);
      }
      // Update the roster of the user
      if (userRoster != null) {
        try {
          User user = UserManager.getInstance().getUser(userToRemove);
          Collection<Group> groups = GroupManager.getInstance().getGroups(user);
          userRoster.deleteSharedUser(userToRemove, groups, group);
        } catch (UserNotFoundException e) {
        }
      }
    }
  }
예제 #2
0
  /**
   * Notification that a Group user has been added. Update the group users' roster accordingly.
   *
   * @param group the group where the user was added.
   * @param addedUser the username of the user that has been added to the group.
   */
  private void groupUserAdded(Group group, String addedUser) {
    // Get all the affected users
    Collection<String> users = getAffectedUsers(group);
    // Get the roster of the added user.
    Roster addedUserRoster = (Roster) CacheManager.getCache("username2roster").get(addedUser);

    // Iterate on all the affected users and update their rosters
    for (String userToUpdate : users) {
      if (!addedUser.equals(userToUpdate)) {
        // Get the roster to update
        Roster roster = (Roster) CacheManager.getCache("username2roster").get(userToUpdate);
        // Only update rosters in memory
        if (roster != null) {
          roster.addSharedUser(group, addedUser);
        }
        // Update the roster of the newly added group user.
        if (addedUserRoster != null) {
          try {
            User user = UserManager.getInstance().getUser(userToUpdate);
            Collection<Group> groups = GroupManager.getInstance().getGroups(user);
            addedUserRoster.addSharedUser(userToUpdate, groups, group);
          } catch (UserNotFoundException e) {
          }
        }
      }
    }
  }
예제 #3
0
 private GroupManager() {
   // Initialize caches.
   CacheManager.initializeCache("group", 128 * 1024);
   CacheManager.initializeCache("group member", 32 * 1024);
   groupCache = CacheManager.getCache("group");
   // Load a group provider.
   String className =
       JiveGlobals.getXMLProperty(
           "provider.group.className", "org.jivesoftware.wildfire.group.DefaultGroupProvider");
   try {
     Class c = ClassUtils.forName(className);
     provider = (GroupProvider) c.newInstance();
   } catch (Exception e) {
     Log.error("Error loading group provider: " + className, e);
     provider = new DefaultGroupProvider();
   }
 }
예제 #4
0
  /**
   * Removes the entire roster of a given user. This is necessary when a user account is being
   * deleted from the server.
   *
   * @param user the user.
   */
  public void deleteRoster(JID user) {
    try {
      String username = user.getNode();
      // Get the roster of the deleted user
      Roster roster = (Roster) CacheManager.getCache("username2roster").get(username);
      if (roster == null) {
        // Not in cache so load a new one:
        roster = new Roster(username);
      }
      // Remove each roster item from the user's roster
      for (RosterItem item : roster.getRosterItems()) {
        try {
          roster.deleteRosterItem(item.getJid(), false);
        } catch (SharedGroupException e) {
          // Do nothing. We shouldn't have this exception since we disabled the checkings
        }
      }
      // Remove the cached roster from memory
      CacheManager.getCache("username2roster").remove(username);

      // Get the rosters that have a reference to the deleted user
      RosterItemProvider rosteItemProvider = RosterItemProvider.getInstance();
      Iterator<String> usernames = rosteItemProvider.getUsernames(user.toBareJID());
      while (usernames.hasNext()) {
        username = usernames.next();
        // Get the roster that has a reference to the deleted user
        roster = (Roster) CacheManager.getCache("username2roster").get(username);
        if (roster == null) {
          // Not in cache so load a new one:
          roster = new Roster(username);
        }
        // Remove the deleted user reference from this roster
        try {
          roster.deleteRosterItem(user, false);
        } catch (SharedGroupException e) {
          // Do nothing. We shouldn't have this exception since we disabled the checkings
        }
      }
    } catch (UnsupportedOperationException e) {
      // Do nothing
    }
  }
예제 #5
0
  /**
   * Notification that a Group user has been deleted. Update the group users' roster accordingly.
   *
   * @param group the group from where the user was deleted.
   * @param users the users to update their rosters
   * @param deletedUser the username of the user that has been deleted from the group.
   */
  private void groupUserDeleted(Group group, Collection<String> users, String deletedUser) {
    // Get the roster of the deleted user.
    Roster deletedUserRoster = (Roster) CacheManager.getCache("username2roster").get(deletedUser);

    // Iterate on all the affected users and update their rosters
    for (String userToUpdate : users) {
      // Get the roster to update
      Roster roster = (Roster) CacheManager.getCache("username2roster").get(userToUpdate);
      // Only update rosters in memory
      if (roster != null) {
        roster.deleteSharedUser(group, deletedUser);
      }
      // Update the roster of the newly deleted group user.
      if (deletedUserRoster != null) {
        try {
          User user = UserManager.getInstance().getUser(userToUpdate);
          Collection<Group> groups = GroupManager.getInstance().getGroups(user);
          deletedUserRoster.deleteSharedUser(userToUpdate, groups, group);
        } catch (UserNotFoundException e) {
        }
      }
    }
  }
예제 #6
0
 /**
  * Returns the roster for the given username.
  *
  * @param username the username to search for.
  * @return the roster associated with the ID.
  * @throws org.jivesoftware.messenger.user.UserNotFoundException if the ID does not correspond to
  *     a known entity on the server.
  */
 public Roster getRoster(String username) throws UserNotFoundException {
   if (rosterCache == null) {
     rosterCache = CacheManager.getCache("username2roster");
   }
   if (rosterCache == null) {
     throw new UserNotFoundException("Could not load caches");
   }
   Roster roster = (Roster) rosterCache.get(username);
   if (roster == null) {
     // Not in cache so load a new one:
     roster = new Roster(username);
     rosterCache.put(username, roster);
   }
   if (roster == null) {
     throw new UserNotFoundException(username);
   }
   return roster;
 }
예제 #7
0
  public void groupModified(Group group, Map params) {
    // Do nothing if no group property has been modified
    if (!"propertyModified".equals(params.get("type"))) {
      return;
    }
    String keyChanged = (String) params.get("propertyKey");
    String originalValue = (String) params.get("originalValue");

    if ("sharedRoster.showInRoster".equals(keyChanged)) {
      String currentValue = group.getProperties().get("sharedRoster.showInRoster");
      // Nothing has changed so do nothing.
      if (currentValue.equals(originalValue)) {
        return;
      }
      // Get the users of the group
      Collection<String> users = new HashSet<String>(group.getMembers());
      users.addAll(group.getAdmins());
      // Get the users whose roster will be affected
      Collection<String> affectedUsers =
          getAffectedUsers(
              group, originalValue, group.getProperties().get("sharedRoster.groupList"));
      // Remove the group members from the affected rosters
      for (String deletedUser : users) {
        groupUserDeleted(group, affectedUsers, deletedUser);
      }

      // Simulate that the group users has been added to the group. This will cause to push
      // roster items to the "affected" users for the group users
      // Collection<Group> visibleGroups = getVisibleGroups(group);
      for (String user : users) {
        groupUserAdded(group, user);
        /*for (Group visibleGroup : visibleGroups) {
            addSharedGroupToRoster(visibleGroup, user);
        }*/
      }
    } else if ("sharedRoster.groupList".equals(keyChanged)) {
      String currentValue = group.getProperties().get("sharedRoster.groupList");
      // Nothing has changed so do nothing.
      if (currentValue.equals(originalValue)) {
        return;
      }
      // Get the users of the group
      Collection<String> users = new HashSet<String>(group.getMembers());
      users.addAll(group.getAdmins());
      // Get the users whose roster will be affected
      Collection<String> affectedUsers =
          getAffectedUsers(
              group, group.getProperties().get("sharedRoster.showInRoster"), originalValue);
      // Remove the group members from the affected rosters
      for (String deletedUser : users) {
        groupUserDeleted(group, affectedUsers, deletedUser);
      }

      // Simulate that the group users has been added to the group. This will cause to push
      // roster items to the "affected" users for the group users
      // Collection<Group> visibleGroups = getVisibleGroups(group);
      for (String user : users) {
        groupUserAdded(group, user);
        /*for (Group visibleGroup : visibleGroups) {
            addSharedGroupToRoster(visibleGroup, user);
        }*/
      }
    } else if ("sharedRoster.displayName".equals(keyChanged)) {
      String currentValue = group.getProperties().get("sharedRoster.displayName");
      // Nothing has changed so do nothing.
      if (currentValue.equals(originalValue)) {
        return;
      }
      // Do nothing if the group is not being shown in users' rosters
      if (!isSharedGroup(group)) {
        return;
      }
      // Get all the affected users
      Collection<String> users = getAffectedUsers(group);
      // Iterate on all the affected users and update their rosters
      for (String updatedUser : users) {
        // Get the roster to update.
        Roster roster = (Roster) CacheManager.getCache("username2roster").get(updatedUser);
        if (roster != null) {
          // Update the roster with the new group display name
          roster.shareGroupRenamed(users);
        }
      }
    }
  }