Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid self role revoke in conferences. #1751

Open
wants to merge 2 commits into
base: 4.6
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.jivesoftware.openfire.muc.spi;

import java.util.ArrayList;
Expand All @@ -40,15 +39,16 @@
import org.xmpp.packet.Presence;

/**
* A handler for the IQ packet with namespace http://jabber.org/protocol/muc#admin. This kind of
* packets are usually sent by room admins. So this handler provides the necessary functionality
* to support administrator requirements such as: managing room members/outcasts/etc., kicking
* occupants and banning users.
* A handler for the IQ packet with namespace
* http://jabber.org/protocol/muc#admin. This kind of packets are usually sent
* by room admins. So this handler provides the necessary functionality to
* support administrator requirements such as: managing room
* members/outcasts/etc., kicking occupants and banning users.
*
* @author Gaston Dombiak
*/
public class IQAdminHandler {

private static final Logger logger = LoggerFactory.getLogger(IQAdminHandler.class);

private final LocalMUCRoom room;
Expand All @@ -64,7 +64,8 @@ public IQAdminHandler(LocalMUCRoom chatroom, PacketRouter packetRouter) {
}

/**
* Handles the IQ packet sent by an owner or admin of the room. Possible actions are:
* Handles the IQ packet sent by an owner or admin of the room. Possible
* actions are:
* <ul>
* <li>Return the list of participants</li>
* <li>Return the list of moderators</li>
Expand All @@ -81,11 +82,14 @@ public IQAdminHandler(LocalMUCRoom chatroom, PacketRouter packetRouter) {
*
* @param packet the IQ packet sent by an owner or admin of the room.
* @param role the role of the user that sent the request packet.
* @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
* @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
*/
public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, ConflictException,
NotAllowedException, CannotBeInvitedException {
Expand All @@ -95,11 +99,12 @@ public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, Conflic
// Analyze the action to perform based on the included element
@SuppressWarnings("unchecked")
List<Element> itemsList = element.elements("item");
if (!itemsList.isEmpty()) {

if (!itemsList.isEmpty() && packet.getFrom() == null) {
handleItemsElement(role, itemsList, reply);
}
else {
} else if (!itemsList.isEmpty() && !itemsList.toString().contains(packet.getFrom().toBareJID())) {
handleItemsElement(role, itemsList, reply);
} else {
// An unknown and possibly incorrect element was included in the query
// element so answer a BAD_REQUEST error
reply.setChildElement(packet.getChildElement().createCopy());
Expand All @@ -113,20 +118,25 @@ public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, Conflic
}

/**
* 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
* 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
* @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 {
Expand Down Expand Up @@ -257,8 +267,7 @@ private void handleItemsElement(MUCRole senderRole, List<Element> itemsList, IQ
reply.setError(PacketError.Condition.bad_request);
}
}
}
else {
} else {
// The client is modifying the list of moderators/members/participants/outcasts
String nick;
String target;
Expand Down Expand Up @@ -350,8 +359,7 @@ private void handleItemsElement(MUCRole senderRole, List<Element> itemsList, IQ
reply.setError(PacketError.Condition.bad_request);
}
}
}
catch (UserNotFoundException e) {
} catch (UserNotFoundException e) {
// Do nothing
}
}
Expand All @@ -372,8 +380,7 @@ private Element addAffiliationToResult(String affiliation, Element parent, JID j
MUCRole role = roles.get(0);
result.addAttribute("role", role.getRole().toString());
result.addAttribute("nick", role.getNickname());
}
catch (UserNotFoundException e) {
} catch (UserNotFoundException e) {
// the JID is not currently an occupant
}
return result;
Expand Down