Search in sources :

Example 11 with GroupNotFoundException

use of org.jivesoftware.openfire.group.GroupNotFoundException 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 12 with GroupNotFoundException

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

the class IQAdminHandler method handleItemsElement.

/**
     * Handles packets that includes item elements. Depending on the item's attributes the
     * interpretation of the request may differ. For example, an item that only contains the
     * "affiliation" attribute is requesting the list of participants or members. Whilst if the item
     * contains the affiliation together with a jid means that the client is changing the
     * affiliation of the requested jid.
     *
     * @param senderRole the role of the user that sent the request packet.
     * @param itemsList  the list of items sent by the client.
     * @param reply      the iq packet that will be sent back as a reply to the client's request.
     * @throws ForbiddenException If the user is not allowed to perform his request.
     * @throws ConflictException If the desired room nickname is already reserved for the room or
     *                           if the room was going to lose all of its owners.
     * @throws NotAllowedException Thrown if trying to ban an owner or an administrator.
     * @throws CannotBeInvitedException If the user being invited as a result of being added to a members-only room still does not have permission
     */
private void handleItemsElement(MUCRole senderRole, List<Element> itemsList, IQ reply) throws ForbiddenException, ConflictException, NotAllowedException, CannotBeInvitedException {
    Element item;
    String affiliation;
    String roleAttribute;
    boolean hasJID = itemsList.get(0).attributeValue("jid") != null;
    boolean hasNick = itemsList.get(0).attributeValue("nick") != null;
    // Check if the client is requesting or changing the list of moderators/members/etc.
    if (!hasJID && !hasNick) {
        // The client is requesting the list of moderators/members/participants/outcasts
        // Create the result that will hold an item for each
        // moderator/member/participant/outcast
        Element result = reply.setChildElement("query", "http://jabber.org/protocol/muc#admin");
        for (Object anItem : itemsList) {
            item = (Element) anItem;
            affiliation = item.attributeValue("affiliation");
            roleAttribute = item.attributeValue("role");
            Element metaData;
            if ("outcast".equals(affiliation)) {
                // The client is requesting the list of outcasts
                if (MUCRole.Affiliation.admin != senderRole.getAffiliation() && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
                    throw new ForbiddenException();
                }
                for (JID jid : room.getOutcasts()) {
                    if (GroupJID.isGroup(jid)) {
                        try {
                            // add each group member to the result (clients don't understand groups)
                            Group group = GroupManager.getInstance().getGroup(jid);
                            for (JID groupMember : group.getAll()) {
                                metaData = addAffiliationToResult(affiliation, result, groupMember);
                            }
                        } catch (GroupNotFoundException gnfe) {
                            logger.warn("Invalid group JID in the outcast list: " + jid);
                        }
                    } else {
                        metaData = addAffiliationToResult(affiliation, result, jid);
                    }
                }
            } else if ("member".equals(affiliation)) {
                // In a members-only room members can get the list of members
                if (!room.isMembersOnly() && MUCRole.Affiliation.admin != senderRole.getAffiliation() && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
                    throw new ForbiddenException();
                }
                for (JID jid : room.getMembers()) {
                    if (GroupJID.isGroup(jid)) {
                        try {
                            // add each group member to the result (clients don't understand groups)
                            Group group = GroupManager.getInstance().getGroup(jid);
                            for (JID groupMember : group.getAll()) {
                                metaData = addAffiliationToResult(affiliation, result, groupMember);
                            }
                        } catch (GroupNotFoundException gnfe) {
                            logger.warn("Invalid group JID in the member list: " + jid);
                        }
                    } else {
                        metaData = addAffiliationToResult(affiliation, result, jid);
                    }
                }
            } else if ("moderator".equals(roleAttribute)) {
                // The client is requesting the list of moderators
                if (MUCRole.Affiliation.admin != senderRole.getAffiliation() && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
                    throw new ForbiddenException();
                }
                for (MUCRole role : room.getModerators()) {
                    metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin");
                    metaData.addAttribute("role", "moderator");
                    metaData.addAttribute("jid", role.getUserAddress().toString());
                    metaData.addAttribute("nick", role.getNickname());
                    metaData.addAttribute("affiliation", role.getAffiliation().toString());
                }
            } else if ("participant".equals(roleAttribute)) {
                // The client is requesting the list of participants
                if (MUCRole.Role.moderator != senderRole.getRole()) {
                    throw new ForbiddenException();
                }
                for (MUCRole role : room.getParticipants()) {
                    metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin");
                    metaData.addAttribute("role", "participant");
                    metaData.addAttribute("jid", role.getUserAddress().toString());
                    metaData.addAttribute("nick", role.getNickname());
                    metaData.addAttribute("affiliation", role.getAffiliation().toString());
                }
            } else if ("owner".equals(affiliation)) {
                // The client is requesting the list of owners
                for (JID jid : room.getOwners()) {
                    if (GroupJID.isGroup(jid)) {
                        try {
                            // add each group member to the result (clients don't understand groups)
                            Group group = GroupManager.getInstance().getGroup(jid);
                            for (JID groupMember : group.getAll()) {
                                metaData = addAffiliationToResult(affiliation, result, groupMember);
                            }
                        } catch (GroupNotFoundException gnfe) {
                            logger.warn("Invalid group JID in the owner list: " + jid);
                        }
                    } else {
                        metaData = addAffiliationToResult(affiliation, result, jid);
                    }
                }
            } else if ("admin".equals(affiliation)) {
                // The client is requesting the list of admins
                for (JID jid : room.getAdmins()) {
                    if (GroupJID.isGroup(jid)) {
                        try {
                            // add each group member to the result (clients don't understand groups)
                            Group group = GroupManager.getInstance().getGroup(jid);
                            for (JID groupMember : group.getAll()) {
                                metaData = addAffiliationToResult(affiliation, result, groupMember);
                            }
                        } catch (GroupNotFoundException gnfe) {
                            logger.warn("Invalid group JID in the admin list: " + jid);
                        }
                    } else {
                        metaData = addAffiliationToResult(affiliation, result, jid);
                    }
                }
            } else {
                reply.setError(PacketError.Condition.bad_request);
            }
        }
    } else {
        // The client is modifying the list of moderators/members/participants/outcasts
        String nick;
        String target;
        boolean hasAffiliation;
        // Keep a registry of the updated presences
        List<Presence> presences = new ArrayList<>(itemsList.size());
        // Collect the new affiliations or roles for the specified jids
        for (Object anItem : itemsList) {
            try {
                item = (Element) anItem;
                affiliation = item.attributeValue("affiliation");
                hasAffiliation = affiliation != null;
                target = (hasAffiliation ? affiliation : item.attributeValue("role"));
                List<JID> jids = new ArrayList<>();
                // jid could be of the form "full JID" or "bare JID" depending if we are
                // going to change a role or an affiliation
                nick = item.attributeValue("nick");
                if (hasJID) {
                    // could be a group JID
                    jids.add(GroupJID.fromString(item.attributeValue("jid")));
                } else {
                    // Get the JID based on the requested nick
                    for (MUCRole role : room.getOccupantsByNickname(nick)) {
                        if (!jids.contains(role.getUserAddress())) {
                            jids.add(role.getUserAddress());
                        }
                    }
                }
                for (JID jid : jids) {
                    if ("moderator".equals(target)) {
                        // Add the user as a moderator of the room based on the full JID
                        presences.add(room.addModerator(jid, senderRole));
                    } else if ("owner".equals(target)) {
                        presences.addAll(room.addOwner(jid, senderRole));
                    } else if ("admin".equals(target)) {
                        presences.addAll(room.addAdmin(jid, senderRole));
                    } else if ("participant".equals(target)) {
                        // Add the user as a participant of the room based on the full JID
                        presences.add(room.addParticipant(jid, item.elementTextTrim("reason"), senderRole));
                    } else if ("visitor".equals(target)) {
                        // Add the user as a visitor of the room based on the full JID
                        presences.add(room.addVisitor(jid, senderRole));
                    } else if ("member".equals(target)) {
                        // Add the user as a member of the room based on the bare JID
                        boolean hadAffiliation = room.getAffiliation(jid) != MUCRole.Affiliation.none;
                        presences.addAll(room.addMember(jid, nick, senderRole));
                        // are not disabled system-wide xmpp.muc.skipInvite
                        if (!skipInvite && !hadAffiliation && room.isMembersOnly()) {
                            List<JID> invitees = new ArrayList<>();
                            if (GroupJID.isGroup(jid)) {
                                try {
                                    Group group = GroupManager.getInstance().getGroup(jid);
                                    for (JID inGroup : group.getAll()) {
                                        invitees.add(inGroup);
                                    }
                                } catch (GroupNotFoundException gnfe) {
                                    logger.error("Failed to send invitations for group members", gnfe);
                                }
                            } else {
                                invitees.add(jid);
                            }
                            for (JID invitee : invitees) {
                                room.sendInvitation(invitee, null, senderRole, null);
                            }
                        }
                    } else if ("outcast".equals(target)) {
                        // Add the user as an outcast of the room based on the bare JID
                        presences.addAll(room.addOutcast(jid, item.elementTextTrim("reason"), senderRole));
                    } else if ("none".equals(target)) {
                        if (hasAffiliation) {
                            // Set that this jid has a NONE affiliation based on the bare JID
                            presences.addAll(room.addNone(jid, senderRole));
                        } else {
                            // Kick the user from the room
                            if (MUCRole.Role.moderator != senderRole.getRole()) {
                                throw new ForbiddenException();
                            }
                            presences.add(room.kickOccupant(jid, senderRole.getUserAddress(), senderRole.getNickname(), item.elementTextTrim("reason")));
                        }
                    } else {
                        reply.setError(PacketError.Condition.bad_request);
                    }
                }
            } catch (UserNotFoundException e) {
            // Do nothing
            }
        }
        // Send the updated presences to the room occupants
        for (Presence presence : presences) {
            room.send(presence);
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Group(org.jivesoftware.openfire.group.Group) ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) GroupJID(org.jivesoftware.openfire.group.GroupJID) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) MUCRole(org.jivesoftware.openfire.muc.MUCRole) Presence(org.xmpp.packet.Presence) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with GroupNotFoundException

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

the class IQOwnerHandler method refreshConfigurationFormValues.

private void refreshConfigurationFormValues() {
    room.lock.readLock().lock();
    try {
        FormField field = configurationForm.getField("muc#roomconfig_roomname");
        field.clearValues();
        field.addValue(room.getNaturalLanguageName());
        field = configurationForm.getField("muc#roomconfig_roomdesc");
        field.clearValues();
        field.addValue(room.getDescription());
        field = configurationForm.getField("muc#roomconfig_changesubject");
        field.clearValues();
        field.addValue((room.canOccupantsChangeSubject() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_maxusers");
        field.clearValues();
        field.addValue(Integer.toString(room.getMaxUsers()));
        field = configurationForm.getField("muc#roomconfig_presencebroadcast");
        field.clearValues();
        for (String roleToBroadcast : room.getRolesToBroadcastPresence()) {
            field.addValue(roleToBroadcast);
        }
        field = configurationForm.getField("muc#roomconfig_publicroom");
        field.clearValues();
        field.addValue((room.isPublicRoom() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_persistentroom");
        field.clearValues();
        field.addValue((room.isPersistent() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_moderatedroom");
        field.clearValues();
        field.addValue((room.isModerated() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_membersonly");
        field.clearValues();
        field.addValue((room.isMembersOnly() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_allowinvites");
        field.clearValues();
        field.addValue((room.canOccupantsInvite() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_passwordprotectedroom");
        field.clearValues();
        field.addValue((room.isPasswordProtected() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_roomsecret");
        field.clearValues();
        field.addValue(room.getPassword());
        field = configurationForm.getField("muc#roomconfig_whois");
        field.clearValues();
        field.addValue((room.canAnyoneDiscoverJID() ? "anyone" : "moderators"));
        field = configurationForm.getField("muc#roomconfig_allowpm");
        field.clearValues();
        field.addValue((room.canSendPrivateMessage()));
        field = configurationForm.getField("muc#roomconfig_enablelogging");
        field.clearValues();
        field.addValue((room.isLogEnabled() ? "1" : "0"));
        field = configurationForm.getField("x-muc#roomconfig_reservednick");
        field.clearValues();
        field.addValue((room.isLoginRestrictedToNickname() ? "1" : "0"));
        field = configurationForm.getField("x-muc#roomconfig_canchangenick");
        field.clearValues();
        field.addValue((room.canChangeNickname() ? "1" : "0"));
        field = configurationForm.getField("x-muc#roomconfig_registration");
        field.clearValues();
        field.addValue((room.isRegistrationEnabled() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_roomadmins");
        field.clearValues();
        for (JID jid : room.getAdmins()) {
            if (GroupJID.isGroup(jid)) {
                try {
                    // add each group member to the result (clients don't understand groups)
                    Group group = GroupManager.getInstance().getGroup(jid);
                    for (JID groupMember : group.getAll()) {
                        field.addValue(groupMember);
                    }
                } catch (GroupNotFoundException gnfe) {
                    Log.warn("Invalid group JID in the member list: " + jid);
                }
            } else {
                field.addValue(jid.toString());
            }
        }
        field = configurationForm.getField("muc#roomconfig_roomowners");
        field.clearValues();
        for (JID jid : room.getOwners()) {
            if (GroupJID.isGroup(jid)) {
                try {
                    // add each group member to the result (clients don't understand groups)
                    Group group = GroupManager.getInstance().getGroup(jid);
                    for (JID groupMember : group.getAll()) {
                        field.addValue(groupMember);
                    }
                } catch (GroupNotFoundException gnfe) {
                    Log.warn("Invalid group JID in the member list: " + jid);
                }
            } else {
                field.addValue(jid.toString());
            }
        }
        // Remove the old element
        probeResult.remove(probeResult.element(QName.get("x", "jabber:x:data")));
        // Add the new representation of configurationForm as an element 
        probeResult.add(configurationForm.getElement());
    } finally {
        room.lock.readLock().unlock();
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) GroupJID(org.jivesoftware.openfire.group.GroupJID) JID(org.xmpp.packet.JID) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) FormField(org.xmpp.forms.FormField)

Example 14 with GroupNotFoundException

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

the class RequestQueue method getGroupObjects.

private Collection<Group> getGroupObjects() {
    final GroupManager groupManager = GroupManager.getInstance();
    Set<Group> objects = new HashSet<Group>(groups.size());
    for (String group : groups) {
        try {
            objects.add(groupManager.getGroup(group));
        } catch (GroupNotFoundException e) {
            Log.error("Error retrieving group: " + group, e);
        }
    }
    return objects;
}
Also used : Group(org.jivesoftware.openfire.group.Group) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) GroupManager(org.jivesoftware.openfire.group.GroupManager) HashSet(java.util.HashSet)

Example 15 with GroupNotFoundException

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

the class UserServiceController method deleteUserFromGroups.

/**
	 * Delete user from groups.
	 *
	 * @param username
	 *            the username
	 * @param userGroupsEntity
	 *            the user groups entity
	 * @throws ServiceException
	 *             the service exception
	 */
public void deleteUserFromGroups(String username, UserGroupsEntity userGroupsEntity) throws ServiceException {
    if (userGroupsEntity != null) {
        for (String groupName : userGroupsEntity.getGroupNames()) {
            Group group = null;
            try {
                group = GroupManager.getInstance().getGroup(groupName);
            } catch (GroupNotFoundException e) {
                throw new ServiceException("Could not find group", groupName, ExceptionType.GROUP_NOT_FOUND, Response.Status.NOT_FOUND, e);
            }
            group.getMembers().remove(server.createJID(username, null));
        }
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Aggregations

GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)40 Group (org.jivesoftware.openfire.group.Group)38 Element (org.dom4j.Element)15 JID (org.xmpp.packet.JID)12 ArrayList (java.util.ArrayList)11 List (java.util.List)8 StringTokenizer (java.util.StringTokenizer)6 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)5 GroupManager (org.jivesoftware.openfire.group.GroupManager)4 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)4 GroupJID (org.jivesoftware.openfire.group.GroupJID)3 GroupEntity (org.jivesoftware.openfire.plugin.rest.entity.GroupEntity)3 User (org.jivesoftware.openfire.user.User)3 Presence (org.xmpp.packet.Presence)3 HashMap (java.util.HashMap)2 NamingException (javax.naming.NamingException)2 MUCRole (org.jivesoftware.openfire.muc.MUCRole)2 DataForm (org.xmpp.forms.DataForm)2 FormField (org.xmpp.forms.FormField)2 RemoteException (java.rmi.RemoteException)1