Search in sources :

Example 66 with Group

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

the class BookmarkInterceptor method isBookmarkForJID.

/**
     * True if the specified bookmark should be appended to the users list of
     * bookmarks.
     *
     * @param jid      the jid of the user.
     * @param bookmark the bookmark.
     * @return true if bookmark should be appended.
     */
private static boolean isBookmarkForJID(JID jid, Bookmark bookmark) {
    String username = jid.getNode();
    if (bookmark.getUsers().contains(username)) {
        return true;
    }
    Collection<String> groups = bookmark.getGroups();
    if (groups != null && !groups.isEmpty()) {
        GroupManager groupManager = GroupManager.getInstance();
        for (String groupName : groups) {
            try {
                Group group = groupManager.getGroup(groupName);
                if (group.isUser(jid.getNode())) {
                    return true;
                }
            } catch (GroupNotFoundException e) {
                Log.debug(e.getMessage(), e);
            }
        }
    }
    return false;
}
Also used : Group(org.jivesoftware.openfire.group.Group) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) GroupManager(org.jivesoftware.openfire.group.GroupManager)

Example 67 with Group

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

the class WorkgroupManager method addGroupManagerListener.

/**
     * Listens for changes in the Group model to update respective agents.
     */
private void addGroupManagerListener() {
    groupEventListener = new GroupEventListener() {

        public void groupCreated(Group group, Map params) {
        }

        public void groupDeleting(Group group, Map params) {
        }

        public void groupModified(Group group, Map params) {
        }

        public void memberAdded(Group group, Map params) {
            String userJID = (String) params.get("member");
            JID jid = new JID(userJID);
            if (!agentManager.hasAgent(jid)) {
                for (Workgroup workgroup : workgroups.values()) {
                    for (RequestQueue queue : workgroup.getRequestQueues()) {
                        if (queue.hasGroup(group)) {
                            agentManager.getAgents(group);
                        }
                    }
                }
            }
        }

        public void memberRemoved(Group group, Map params) {
        }

        public void adminAdded(Group group, Map params) {
        }

        public void adminRemoved(Group group, Map params) {
        }
    };
    GroupEventDispatcher.addListener(groupEventListener);
}
Also used : GroupEventListener(org.jivesoftware.openfire.event.GroupEventListener) Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) CreateWorkgroup(org.jivesoftware.openfire.fastpath.commands.CreateWorkgroup) DeleteWorkgroup(org.jivesoftware.openfire.fastpath.commands.DeleteWorkgroup) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 68 with Group

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

the class JustMarriedPlugin method copyRoster.

private static void copyRoster(User currentUser, User newUser, String currentUserName) {
    Roster newRoster = newUser.getRoster();
    Roster currentRoster = currentUser.getRoster();
    for (RosterItem item : currentRoster.getRosterItems()) {
        try {
            List<String> groups = item.getGroups();
            RosterItem justCreated = newRoster.createRosterItem(item.getJid(), item.getNickname(), groups, true, true);
            justCreated.setAskStatus(item.getAskStatus());
            justCreated.setRecvStatus(item.getRecvStatus());
            justCreated.setSubStatus(item.getSubStatus());
            for (Group gr : item.getSharedGroups()) {
                justCreated.addSharedGroup(gr);
            }
            for (Group gr : item.getInvisibleSharedGroups()) {
                justCreated.addInvisibleSharedGroup(gr);
            }
            newRoster.updateRosterItem(justCreated);
            addNewUserToOthersRoster(newUser, item, currentUserName);
        } catch (UserAlreadyExistsException e) {
            Log.error("Could not create roster item for user " + item.getJid(), e);
        } catch (SharedGroupException e) {
            Log.error("Could not create roster item for user " + item.getJid() + " because it is a contact from a shared group", e);
        } catch (UserNotFoundException e) {
            Log.error("Could not update Roster item for user " + newUser.getName() + " because it was not properly created.", e);
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Group(org.jivesoftware.openfire.group.Group) Roster(org.jivesoftware.openfire.roster.Roster) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException)

Example 69 with Group

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

the class SearchGroupServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String param = req.getParameter("search");
    Element root = new DefaultElement("result");
    if (param != null && param.length() > 0) {
        GroupManager manager = GroupManager.getInstance();
        Collection<Group> groups = manager.getGroups();
        for (Group gr : groups) {
            if (gr.getName().startsWith(param)) {
                root.addElement("item").addText(gr.getName());
            }
        }
    }
    resp.getOutputStream().write(root.asXML().getBytes());
    resp.getOutputStream().close();
}
Also used : Group(org.jivesoftware.openfire.group.Group) DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) GroupManager(org.jivesoftware.openfire.group.GroupManager)

Example 70 with Group

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

the class PermissionManager method isUserInAllowedGroup.

/**
     * Checks if a user is in a group that has access to the transport.
     *
     * @param jid JID of the user who may or may not have access.
     * @return True or false of the user is in a group that has access.
     */
public boolean isUserInAllowedGroup(JID jid) {
    ArrayList<String> allowedGroups = new ArrayList<String>();
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(GROUPS_LISTED);
        pstmt.setString(1, transportType.toString());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            allowedGroups.add(rs.getString(1));
        }
    } catch (SQLException sqle) {
        Log.error(sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    Collection<Group> userGroups = GroupManager.getInstance().getGroups(jid);
    for (Group g : userGroups) {
        if (allowedGroups.contains(g.getName())) {
            return true;
        }
    }
    return false;
}
Also used : Group(org.jivesoftware.openfire.group.Group) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

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