Search in sources :

Example 61 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class RosterManager method userCreated.

/**
     * A new user has been created so members of public shared groups need to have
     * their rosters updated. Members of public shared groups need to have a roster
     * item with subscription FROM for the new user since the new user can see them.
     *
     * @param newUser the newly created user.
     * @param params event parameters.
     */
@Override
public void userCreated(User newUser, Map<String, Object> params) {
    JID newUserJID = server.createJID(newUser.getUsername(), null);
    // of type FROM for the new user
    for (Group group : getPublicSharedGroups()) {
        // Get group members of public group
        Collection<JID> users = new HashSet<>(group.getMembers());
        users.addAll(group.getAdmins());
        // Update the roster of each group member to include a subscription of type FROM
        for (JID userToUpdate : users) {
            // Get the roster to update
            Roster roster = null;
            if (server.isLocal(userToUpdate)) {
                // Check that the user exists, if not then continue with the next user
                try {
                    UserManager.getInstance().getUser(userToUpdate.getNode());
                } catch (UserNotFoundException e) {
                    continue;
                }
                roster = rosterCache.get(userToUpdate.getNode());
            }
            // Only update rosters in memory
            if (roster != null) {
                roster.addSharedUser(group, newUserJID);
            }
            if (!server.isLocal(userToUpdate)) {
                // Susbcribe to the presence of the remote user. This is only necessary for
                // remote users and may only work with remote users that **automatically**
                // accept presence subscription requests
                sendSubscribeRequest(newUserJID, userToUpdate, true);
            }
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID)

Example 62 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class RosterManager method hasMutualVisibility.

/**
     * Returns true if a group in the first collection may mutually see a group of the
     * second collection. More precisely, return true if both collections contain a public
     * group (i.e. anybody can see the group) or if both collection have a group that may see
     * each other and the users are members of those groups or if one group is public and the
     * other group allowed the public group to see it.
     *
     * @param user the name of the user associated to the first collection of groups. This is always a local user.
     * @param groups a collection of groups to check against the other collection of groups.
     * @param otherUser the JID of the user associated to the second collection of groups.
     * @param otherGroups the other collection of groups to check against the first collection.
     * @return true if a group in the first collection may mutually see a group of the
     *         second collection.
     */
boolean hasMutualVisibility(String user, Collection<Group> groups, JID otherUser, Collection<Group> otherGroups) {
    for (Group group : groups) {
        for (Group otherGroup : otherGroups) {
            // Skip this groups if the users are not group users of the groups
            if (!group.isUser(user) || !otherGroup.isUser(otherUser)) {
                continue;
            }
            if (group.equals(otherGroup)) {
                return true;
            }
            String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
            String otherShowInRoster = otherGroup.getProperties().get("sharedRoster.showInRoster");
            // Return true if both groups are public groups (i.e. anybody can see them)
            if ("everybody".equals(showInRoster) && "everybody".equals(otherShowInRoster)) {
                return true;
            } else if ("onlyGroup".equals(showInRoster) && "onlyGroup".equals(otherShowInRoster)) {
                String groupNames = group.getProperties().get("sharedRoster.groupList");
                String otherGroupNames = otherGroup.getProperties().get("sharedRoster.groupList");
                // Return true if each group may see the other group
                if (groupNames != null && otherGroupNames != null) {
                    if (groupNames.contains(otherGroup.getName()) && otherGroupNames.contains(group.getName())) {
                        return true;
                    }
                    // Check if each shared group can be seen by a group where each user belongs
                    Collection<Group> groupList = parseGroups(groupNames);
                    Collection<Group> otherGroupList = parseGroups(otherGroupNames);
                    for (Group groupName : groupList) {
                        if (groupName.isUser(otherUser)) {
                            for (Group otherGroupName : otherGroupList) {
                                if (otherGroupName.isUser(user)) {
                                    return true;
                                }
                            }
                        }
                    }
                }
            } else if ("everybody".equals(showInRoster) && "onlyGroup".equals(otherShowInRoster)) {
                // Return true if one group is public and the other group allowed the public
                // group to see him
                String otherGroupNames = otherGroup.getProperties().get("sharedRoster.groupList");
                if (otherGroupNames != null && otherGroupNames.contains(group.getName())) {
                    return true;
                }
            } else if ("onlyGroup".equals(showInRoster) && "everybody".equals(otherShowInRoster)) {
                // Return true if one group is public and the other group allowed the public
                // group to see him
                String groupNames = group.getProperties().get("sharedRoster.groupList");
                // Return true if each group may see the other group
                if (groupNames != null && groupNames.contains(otherGroup.getName())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Group(org.jivesoftware.openfire.group.Group)

Example 63 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class RosterManager method memberRemoved.

@Override
public void memberRemoved(Group group, Map params) {
    String member = (String) params.get("member");
    if (member == null) {
        return;
    }
    JID deletedUser = new JID(member);
    // Do nothing if the user is still an admin
    if (group.getAdmins().contains(deletedUser)) {
        return;
    }
    if (!isSharedGroup(group)) {
        for (Group visibleGroup : getVisibleGroups(group)) {
            // Get the list of affected users
            Collection<JID> users = new HashSet<>(visibleGroup.getMembers());
            users.addAll(visibleGroup.getAdmins());
            groupUserDeleted(visibleGroup, users, deletedUser);
        }
    } else {
        groupUserDeleted(group, deletedUser);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID)

Example 64 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class RosterManager method getAffectedUsers.

/**
     * This method is similar to {@link #getAffectedUsers(Group)} except that it receives
     * some group properties. The group properties are passed as parameters since the called of this
     * method may want to obtain the related users of the group based in some properties values.
     *
     * This is useful when the group is being edited and some properties has changed and we need to
     * obtain the related users of the group based on the previous group state.
     */
private Collection<JID> getAffectedUsers(Group group, String showInRoster, String groupNames) {
    // Answer an empty collection if the group is not being shown in users' rosters
    if (!"onlyGroup".equals(showInRoster) && !"everybody".equals(showInRoster)) {
        return new ArrayList<>();
    }
    // Add the users of the group
    Collection<JID> users = new HashSet<>(group.getMembers());
    users.addAll(group.getAdmins());
    // Check if anyone can see this shared group
    if ("everybody".equals(showInRoster)) {
        // Add all users in the system
        for (String username : UserManager.getInstance().getUsernames()) {
            users.add(server.createJID(username, null, true));
        }
    // Add all logged users. We don't need to add all users in the system since only the
    // logged ones will be affected.
    //users.addAll(SessionManager.getInstance().getSessionUsers());
    } else {
        // Add the users that may see the group
        Collection<Group> groupList = parseGroups(groupNames);
        for (Group groupInList : groupList) {
            users.addAll(groupInList.getMembers());
            users.addAll(groupInList.getAdmins());
        }
    }
    return users;
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID)

Example 65 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class RosterManager method adminAdded.

@Override
public void adminAdded(Group group, Map params) {
    JID addedUser = new JID((String) params.get("admin"));
    // Do nothing if the user was a member that became an admin
    if (group.getMembers().contains(addedUser)) {
        return;
    }
    if (!isSharedGroup(group)) {
        for (Group visibleGroup : getVisibleGroups(group)) {
            // Get the list of affected users
            Collection<JID> users = new HashSet<>(visibleGroup.getMembers());
            users.addAll(visibleGroup.getAdmins());
            groupUserAdded(visibleGroup, users, addedUser);
        }
    } else {
        groupUserAdded(group, addedUser);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID)

Aggregations

Group (org.jivesoftware.openfire.group.Group)83 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)41 JID (org.xmpp.packet.JID)30 ArrayList (java.util.ArrayList)22 Element (org.dom4j.Element)20 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)10 List (java.util.List)9 User (org.jivesoftware.openfire.user.User)9 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)7 StringTokenizer (java.util.StringTokenizer)6 HashMap (java.util.HashMap)5 GroupManager (org.jivesoftware.openfire.group.GroupManager)5 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)4 GroupEntity (org.jivesoftware.openfire.plugin.rest.entity.GroupEntity)4 DataForm (org.xmpp.forms.DataForm)4 IQ (org.xmpp.packet.IQ)4 HashSet (java.util.HashSet)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2