Search in sources :

Example 11 with Group

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

the class BroadcastPlugin method processIQ.

private void processIQ(IQ iq, boolean targetAll, Group group, boolean canProceed) {
    IQ reply = IQ.createResultIQ(iq);
    Element childElement = iq.getChildElement();
    String namespace = childElement.getNamespaceURI();
    Element childElementCopy = iq.getChildElement().createCopy();
    reply.setChildElement(childElementCopy);
    if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
        if (iq.getTo().getNode() == null) {
            // Return service identity and features
            Element identity = childElementCopy.addElement("identity");
            identity.addAttribute("category", "component");
            identity.addAttribute("type", "generic");
            identity.addAttribute("name", "Broadcast service");
            childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#items");
        } else {
            if (targetAll) {
                // Return identity and features of the "all" group
                Element identity = childElementCopy.addElement("identity");
                identity.addAttribute("category", "component");
                identity.addAttribute("type", "generic");
                identity.addAttribute("name", "Broadcast all connected users");
                childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            } else if (group != null && canProceed) {
                // Return identity and features of the "all" group
                Element identity = childElementCopy.addElement("identity");
                identity.addAttribute("category", "component");
                identity.addAttribute("type", "generic");
                identity.addAttribute("name", "Broadcast " + group.getName());
                childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
            } else {
                // Group not found or not allowed to use that group so
                // answer item_not_found error
                reply.setError(PacketError.Condition.item_not_found);
            }
        }
    } else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
        if (iq.getTo().getNode() == null) {
            // Return the list of groups hosted by the service that can be used by the user
            Collection<Group> groups;
            JID address = new JID(iq.getFrom().toBareJID());
            if (allowedUsers.contains(address)) {
                groups = groupManager.getGroups();
            } else {
                groups = groupManager.getGroups(iq.getFrom());
            }
            for (Group userGroup : groups) {
                try {
                    JID groupJID = new JID(userGroup.getName() + "@" + serviceName + "." + componentManager.getServerName());
                    childElementCopy.addElement("item").addAttribute("jid", groupJID.toString());
                } catch (Exception e) {
                // Group name is not valid to be used as a JID
                }
            }
            if (allowedUsers.isEmpty() || allowedUsers.contains(address)) {
                // Add the "all" group to the list
                childElementCopy.addElement("item").addAttribute("jid", "all@" + serviceName + "." + componentManager.getServerName());
            }
        }
    } else {
        // Answer an error since the server can't handle the requested namespace
        reply.setError(PacketError.Condition.service_unavailable);
    }
    try {
        componentManager.sendPacket(this, reply);
    } catch (Exception e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Collection(java.util.Collection) ComponentException(org.xmpp.component.ComponentException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 12 with Group

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

the class BroadcastPlugin method processPacket.

public void processPacket(Packet packet) {
    boolean canProceed = false;
    Group group = null;
    String toNode = packet.getTo().getNode();
    // Check if user is allowed to send packet to this service[+group]
    boolean targetAll = "all".equals(toNode);
    if (targetAll) {
        // See if the user is allowed to send the packet.
        JID address = new JID(packet.getFrom().toBareJID());
        if (allowedUsers.isEmpty() || allowedUsers.contains(address)) {
            canProceed = true;
        }
    } else {
        try {
            if (toNode != null) {
                group = groupManager.getGroup(toNode);
                boolean isGroupUser = group.isUser(packet.getFrom()) || group.isUser(new JID(packet.getFrom().toBareJID()));
                if (disableGroupPermissions || (groupMembersAllowed && isGroupUser) || allowedUsers.contains(new JID(packet.getFrom().toBareJID()))) {
                    canProceed = true;
                }
            }
        } catch (GroupNotFoundException e) {
        // Ignore.
        }
    }
    if (packet instanceof Message) {
        // Respond to incoming messages
        Message message = (Message) packet;
        processMessage(message, targetAll, group, canProceed);
    } else if (packet instanceof Presence) {
        // Respond to presence subscription request or presence probe
        Presence presence = (Presence) packet;
        processPresence(canProceed, presence);
    } else if (packet instanceof IQ) {
        // Handle disco packets
        IQ iq = (IQ) packet;
        // Ignore IQs of type ERROR or RESULT
        if (IQ.Type.error == iq.getType() || IQ.Type.result == iq.getType()) {
            return;
        }
        processIQ(iq, targetAll, group, canProceed);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 13 with Group

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

the class AgentManager method removeAgentIfNecessary.

/**
     * Removes an agent from the system if they no longer belong to any Workgroups.
     *
     * @param agent the agent to remove.
     */
public void removeAgentIfNecessary(Agent agent) {
    // Go through all workgroups to see if this user is in RequestQueues
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    for (Workgroup workgroup : workgroupManager.getWorkgroups()) {
        for (RequestQueue queue : workgroup.getRequestQueues()) {
            if (queue.getMembers().contains(agent)) {
                return;
            }
            for (Group group : queue.getGroups()) {
                if (group.isUser(agent.getAgentJID())) {
                    return;
                }
            }
        }
    }
    try {
        // Send Presence to Workgroup that this user is no longer available.
        AgentSession session = agent.getAgentSession();
        if (session != null) {
            for (Workgroup workgroup : session.getWorkgroups()) {
                session.depart(workgroup);
            }
        }
        // If we get here, then remove from agent.
        deleteAgent(agent.getAgentJID());
    } catch (IllegalArgumentException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group)

Example 14 with Group

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

the class UserServicePlugin method updateUser.

public void updateUser(String username, String password, String name, String email, String groupNames) throws UserNotFoundException, GroupAlreadyExistsException {
    User user = getUser(username);
    if (password != null)
        user.setPassword(password);
    if (name != null)
        user.setName(name);
    if (email != null)
        user.setEmail(email);
    if (groupNames != null) {
        Collection<Group> newGroups = new ArrayList<Group>();
        StringTokenizer tkn = new StringTokenizer(groupNames, ",");
        while (tkn.hasMoreTokens()) {
            String groupName = tkn.nextToken();
            Group group = null;
            try {
                group = GroupManager.getInstance().getGroup(groupName);
            } catch (GroupNotFoundException e) {
                // Create this group ;
                group = GroupManager.getInstance().createGroup(groupName);
                group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
                group.getProperties().put("sharedRoster.displayName", groupName);
                group.getProperties().put("sharedRoster.groupList", "");
            }
            newGroups.add(group);
        }
        Collection<Group> existingGroups = GroupManager.getInstance().getGroups(user);
        // Get the list of groups to add to the user
        Collection<Group> groupsToAdd = new ArrayList<Group>(newGroups);
        groupsToAdd.removeAll(existingGroups);
        // Get the list of groups to remove from the user
        Collection<Group> groupsToDelete = new ArrayList<Group>(existingGroups);
        groupsToDelete.removeAll(newGroups);
        // Add the user to the new groups
        for (Group group : groupsToAdd) {
            group.getMembers().add(server.createJID(username, null));
        }
        // Remove the user from the old groups
        for (Group group : groupsToDelete) {
            group.getMembers().remove(server.createJID(username, null));
        }
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) StringTokenizer(java.util.StringTokenizer) User(org.jivesoftware.openfire.user.User) ArrayList(java.util.ArrayList) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 15 with Group

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

the class UserServicePluginNG method getUserGroups.

/**
	 * Gets the user groups.
	 *
	 * @param username
	 *            the username
	 * @return the user groups
	 * @throws ServiceException
	 *             the service exception
	 */
public List<String> getUserGroups(String username) throws ServiceException {
    User user = getAndCheckUser(username);
    Collection<Group> groups = GroupManager.getInstance().getGroups(user);
    List<String> groupNames = new ArrayList<String>();
    for (Group group : groups) {
        groupNames.add(group.getName());
    }
    return groupNames;
}
Also used : Group(org.jivesoftware.openfire.group.Group) User(org.jivesoftware.openfire.user.User) ArrayList(java.util.ArrayList)

Aggregations

Group (org.jivesoftware.openfire.group.Group)84 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)42 JID (org.xmpp.packet.JID)30 Element (org.dom4j.Element)20 ArrayList (java.util.ArrayList)19 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)11 User (org.jivesoftware.openfire.user.User)9 List (java.util.List)7 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)7 StringTokenizer (java.util.StringTokenizer)6 GroupManager (org.jivesoftware.openfire.group.GroupManager)5 HashMap (java.util.HashMap)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 XMPPServer (org.jivesoftware.openfire.XMPPServer)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2