Commit cb0f7b56 authored by guus's avatar guus

OF-523: Apply defensive coding to the MUC implementation (mainly: use JIDs,...

OF-523: Apply defensive coding to the MUC implementation (mainly: use JIDs, not Strings - but includes some other fixes as well).

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@12978 b35dd754-fafc-0310-a699-88a17e54d16e
parent 4b8cb088
......@@ -108,8 +108,8 @@ public class ClearspaceMUCEventDelegate extends MUCEventDelegate {
public boolean joiningRoom(MUCRoom room, JID userjid) {
// Always allow an owner to join the room (especially since they need to join to configure the
// room on initial creation).
Collection<String> owners = room.getOwners();
if (owners != null && owners.contains(userjid.toBareJID())) {
Collection<JID> owners = room.getOwners();
if (owners != null && owners.contains(new JID(userjid.toBareJID()))) {
return true;
}
......@@ -186,9 +186,11 @@ public class ClearspaceMUCEventDelegate extends MUCEventDelegate {
Log.warn(GET_ROOM_CONFIG_WARNING + " Room: " + roomJid.toBareJID());
return null;
}
Iterator fields = xElement.elementIterator("field");
@SuppressWarnings("unchecked")
Iterator<Element> fields = xElement.elementIterator("field");
while (fields.hasNext()) {
Element field = (Element) fields.next();
Element field = fields.next();
Attribute varAttribute = field.attribute("var");
if (varAttribute != null) {
Element value = field.element("value");
......
......@@ -186,7 +186,7 @@ public class ClearspaceMUCTranscriptManager implements MUCEventListener {
MUCRoom room = mucService.getChatRoom(jid.getNode());
// Not count room owners as occupants
int totalOccupants = room.getOccupantsCount();
for (String owner : room.getOwners()) {
for (JID owner : room.getOwners()) {
try {
if (!room.getOccupantsByBareJID(owner).isEmpty()) {
totalOccupants--;
......
......@@ -149,9 +149,9 @@ public class HistoryRequest {
*/
public void sendHistory(LocalMUCRole joinRole, MUCRoomHistory roomHistory) {
if (!isConfigured()) {
Iterator history = roomHistory.getMessageHistory();
Iterator<Message> history = roomHistory.getMessageHistory();
while (history.hasNext()) {
joinRole.send((Message) history.next());
joinRole.send(history.next());
}
}
else {
......@@ -164,14 +164,13 @@ public class HistoryRequest {
}
return;
}
Message message;
int accumulatedChars = 0;
int accumulatedStanzas = 0;
Element delayInformation;
LinkedList<Message> historyToSend = new LinkedList<Message>();
ListIterator iterator = roomHistory.getReverseMessageHistory();
ListIterator<Message> iterator = roomHistory.getReverseMessageHistory();
while (iterator.hasPrevious()) {
message = (Message)iterator.previous();
Message message = iterator.previous();
// Update number of characters to send
String text = message.getBody() == null ? message.getSubject() : message.getBody();
if (text == null) {
......
......@@ -205,7 +205,7 @@ public class HistoryStrategy {
// last room subject
// message because we want to preserve the room subject if
// possible.
Iterator historyIter = history.iterator();
Iterator<Message> historyIter = history.iterator();
while (historyIter.hasNext() && history.size() > strategyMaxNumber) {
if (historyIter.next() != roomSubject) {
historyIter.remove();
......
......@@ -111,9 +111,15 @@ public abstract class MUCEventDelegate {
room.setChangeNickname("1".equals(roomConfig.get("x-muc#roomconfig_canchangenick")));
room.setRegistrationEnabled("1".equals(roomConfig.get("x-muc#roomconfig_registration")));
room.setPersistent("1".equals(roomConfig.get("muc#roomconfig_persistentroom")));
room.addFirstOwner(roomConfig.get("muc#roomconfig_roomowners"));
final String property = roomConfig.get("muc#roomconfig_roomowners");
if (property != null) {
String jids[] = property.split(",");
for (String jid : jids) {
room.addFirstOwner(new JID(new JID(jid.trim().toLowerCase()).toBareJID()));
}
}
try {
room.unlock(room.getRole());
} catch (ForbiddenException e) {
......
......@@ -170,7 +170,7 @@ public interface MUCRoom extends Externalizable, Result {
* @return The user's roles in the room
* @throws UserNotFoundException If there is no user with the given nickname
*/
List<MUCRole> getOccupantsByBareJID(String jid) throws UserNotFoundException;
List<MUCRole> getOccupantsByBareJID(JID jid) throws UserNotFoundException;
/**
* Returns the role of a given user in the room by his full JID or <tt>null</tt>
......@@ -209,7 +209,7 @@ public interface MUCRoom extends Externalizable, Result {
* @param bareJID The bare jid of the user of which you'd like to obtain his reserved nickname.
* @return the reserved room nickname for the bare JID or null if none.
*/
String getReservedNickname(String bareJID);
String getReservedNickname(JID jid);
/**
* Returns the affiliation state of the user in the room. Possible affiliations are
......@@ -220,7 +220,7 @@ public interface MUCRoom extends Externalizable, Result {
* @param bareJID The bare jid of the user of which you'd like to obtain his affiliation.
* @return the affiliation state of the user in the room.
*/
MUCRole.Affiliation getAffiliation(String bareJID);
MUCRole.Affiliation getAffiliation(JID bareJID);
/**
* Joins the room using the given nickname.
......@@ -263,7 +263,7 @@ public interface MUCRoom extends Externalizable, Result {
* @param alternateJID the alternate JID. Commonly used to provide a replacement room.
* @param reason the reason why the room was destroyed.
*/
void destroyRoom(String alternateJID, String reason);
void destroyRoom(JID alternateJID, String reason);
/**
* Create a new presence in this room for the given role.
......@@ -296,20 +296,7 @@ public interface MUCRoom extends Externalizable, Result {
*
* @param bareJID The bare JID of the user to add as owner.
*/
public void addFirstOwner(String bareJID);
/**
* Adds a new user to the list of owners.
*
* @param bareJID The bare JID of the user to add as owner.
* @param senderRole the role of the user that is trying to modify the owners list.
* @return the list of updated presences of all the client resources that the client used to
* join the room.
* @throws ForbiddenException If the user is not allowed to modify the owner list.
* @deprecated Replaced by {@link #addOwner(JID, MUCRole)}
*/
@Deprecated
public List<Presence> addOwner(String bareJID, MUCRole senderRole) throws ForbiddenException;
public void addFirstOwner(JID bareJID);
/**
* Adds a new user to the list of owners.
......@@ -331,7 +318,7 @@ public interface MUCRoom extends Externalizable, Result {
* join the room.
* @throws ForbiddenException If the user is not allowed to modify the owner list.
*/
public List<Presence> addOwners(List<String> newOwners, MUCRole senderRole)
public List<Presence> addOwners(List<JID> newOwners, MUCRole senderRole)
throws ForbiddenException;
/**
......@@ -344,24 +331,9 @@ public interface MUCRoom extends Externalizable, Result {
* @throws ForbiddenException If the user is not allowed to modify the admin list.
* @throws ConflictException If the room was going to lose all its owners.
*/
public List<Presence> addAdmins(List<String> newAdmins, MUCRole senderRole)
public List<Presence> addAdmins(List<JID> newAdmins, MUCRole senderRole)
throws ForbiddenException, ConflictException;
/**
* Adds a new user to the list of admins.
*
* @param bareJID The bare JID of the user to add as admin.
* @param senderRole The role of the user that is trying to modify the admins list.
* @return the list of updated presences of all the client resources that the client used to
* join the room.
* @throws ForbiddenException If the user is not allowed to modify the admin list.
* @throws ConflictException If the room was going to lose all its owners.
* @deprecated Replaced by {@link #addAdmin(JID, MUCRole)}
*/
@Deprecated
public List<Presence> addAdmin(String bareJID, MUCRole senderRole) throws ForbiddenException,
ConflictException;
/**
* Adds a new user to the list of admins.
*
......@@ -375,23 +347,6 @@ public interface MUCRoom extends Externalizable, Result {
public List<Presence> addAdmin(JID jid, MUCRole senderRole) throws ForbiddenException,
ConflictException;
/**
* Adds a new user to the list of members.
*
* @param bareJID The bare JID of the user to add as a member.
* @param nickname The reserved nickname of the member for the room or null if none.
* @param senderRole the role of the user that is trying to modify the members list.
* @return the list of updated presences of all the client resources that the client used to
* join the room.
* @throws ForbiddenException If the user is not allowed to modify the members list.
* @throws ConflictException If the desired room nickname is already reserved for the room or if
* the room was going to lose all its owners.
* @deprecated Replaced by {@link #addMember(JID, String, MUCRole)}
*/
@Deprecated
public List<Presence> addMember(String bareJID, String nickname, MUCRole senderRole)
throws ForbiddenException, ConflictException;
/**
* Adds a new user to the list of members.
*
......@@ -407,23 +362,6 @@ public interface MUCRoom extends Externalizable, Result {
public List<Presence> addMember(JID jid, String nickname, MUCRole senderRole)
throws ForbiddenException, ConflictException;
/**
* Adds a new user to the list of outcast users.
*
* @param bareJID The bare JID of the user to add as an outcast.
* @param reason The reason why the user was banned.
* @param senderRole The role of the user that initiated the ban.
* @return the list of updated presences of all the client resources that the client used to
* join the room.
* @throws NotAllowedException Thrown if trying to ban an owner or an administrator.
* @throws ForbiddenException If the user is not allowed to modify the outcast list.
* @throws ConflictException If the room was going to lose all its owners.
* @deprecated Replaced by {@link #addOutcast(JID, String, MUCRole)}
*/
@Deprecated
public List<Presence> addOutcast(String bareJID, String reason, MUCRole senderRole)
throws NotAllowedException, ForbiddenException, ConflictException;
/**
* Adds a new user to the list of outcast users.
*
......@@ -439,21 +377,6 @@ public interface MUCRoom extends Externalizable, Result {
public List<Presence> addOutcast(JID jid, String reason, MUCRole senderRole)
throws NotAllowedException, ForbiddenException, ConflictException;
/**
* Removes the user from all the other affiliation list thus giving the user a NONE affiliation.
*
* @param bareJID The bare JID of the user to keep with a NONE affiliation.
* @param senderRole The role of the user that set the affiliation to none.
* @return the list of updated presences of all the client resources that the client used to
* join the room or null if none was updated.
* @throws ForbiddenException If the user is not allowed to modify the none list.
* @throws ConflictException If the room was going to lose all its owners.
* @deprecated Replaced by {@link #addNone(JID, MUCRole)}
*/
@Deprecated
public List<Presence> addNone(String bareJID, MUCRole senderRole) throws ForbiddenException,
ConflictException;
/**
* Removes the user from all the other affiliation list thus giving the user a NONE affiliation.
*
......@@ -627,7 +550,7 @@ public interface MUCRoom extends Externalizable, Result {
*
* @return a collection with the current list of owners.
*/
public Collection<String> getOwners();
public Collection<JID> getOwners();
/**
* Returns a collection with the current list of admins. The collection contains the bareJID of
......@@ -635,7 +558,7 @@ public interface MUCRoom extends Externalizable, Result {
*
* @return a collection with the current list of admins.
*/
public Collection<String> getAdmins();
public Collection<JID> getAdmins();
/**
* Returns a collection with the current list of room members. The collection contains the
......@@ -645,7 +568,7 @@ public interface MUCRoom extends Externalizable, Result {
*
* @return a collection with the current list of members.
*/
public Collection<String> getMembers();
public Collection<JID> getMembers();
/**
* Returns a collection with the current list of outcast users. An outcast user is not allowed
......@@ -654,7 +577,7 @@ public interface MUCRoom extends Externalizable, Result {
*
* @return a collection with the current list of outcast users.
*/
public Collection<String> getOutcasts();
public Collection<JID> getOutcasts();
/**
* Returns a collection with the current list of room moderators. The collection contains the
......
......@@ -84,12 +84,10 @@ public final class MUCRoomHistory {
if (isNonAnonymousRoom != room.canAnyoneDiscoverJID()) {
isNonAnonymousRoom = room.canAnyoneDiscoverJID();
// Update the "from" attribute of the delay information in the history
Message message;
Element delayElement;
// TODO Make this update in a separate thread
for (Iterator it = getMessageHistory(); it.hasNext();) {
message = (Message) it.next();
delayElement = message.getChildElement("x", "jabber:x:delay");
for (Iterator<Message> it = getMessageHistory(); it.hasNext();) {
Message message = it.next();
Element delayElement = message.getChildElement("x", "jabber:x:delay");
if (room.canAnyoneDiscoverJID()) {
// Set the Full JID as the "from" attribute
try {
......@@ -133,7 +131,7 @@ public final class MUCRoomHistory {
historyStrategy.addMessage(packetToAdd);
}
public Iterator getMessageHistory() {
public Iterator<Message> getMessageHistory() {
return historyStrategy.getMessageHistory();
}
......@@ -144,7 +142,7 @@ public final class MUCRoomHistory {
*
* @return A list iterator of Message objects positioned at the end of the list.
*/
public ListIterator getReverseMessageHistory() {
public ListIterator<Message> getReverseMessageHistory() {
return historyStrategy.getReverseMessageHistory();
}
......
......@@ -22,6 +22,7 @@ package org.jivesoftware.openfire.muc;
import org.jivesoftware.openfire.ChannelHandler;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
/**
* The chat user is a separate user abstraction for interacting with
......@@ -36,7 +37,7 @@ import org.xmpp.packet.JID;
*
* @author Gaston Dombiak
*/
public interface MUCUser extends ChannelHandler {
public interface MUCUser extends ChannelHandler<Packet> {
/**
* Obtain the address of the user. The address is used by services like the core
......
......@@ -62,7 +62,7 @@ public interface MultiUserChatService extends Component {
*
* @return a list of bare JIDs.
*/
Collection<String> getSysadmins();
Collection<JID> getSysadmins();
/**
* Adds a new system administrator of the MUC service. A sysadmin has the same permissions as
......@@ -70,14 +70,14 @@ public interface MultiUserChatService extends Component {
*
* @param userJID the bare JID of the new user to add as a system administrator.
*/
void addSysadmin(String userJID);
void addSysadmin(JID userJID);
/**
* Removes a system administrator of the MUC service.
*
* @param userJID the bare JID of the user to remove from the list.
*/
void removeSysadmin(String userJID);
void removeSysadmin(JID userJID);
/**
* Returns false if anyone can create rooms or true if only the returned JIDs in
......@@ -101,21 +101,21 @@ public interface MultiUserChatService extends Component {
*
* @return a list of bare JIDs.
*/
Collection<String> getUsersAllowedToCreate();
Collection<JID> getUsersAllowedToCreate();
/**
* Adds a new user to the list of JIDs that are allowed to create MUC rooms.
*
* @param userJID the bare JID of the new user to add to list.
*/
void addUserAllowedToCreate(String userJID);
void addUserAllowedToCreate(JID userJID);
/**
* Removes a user from list of JIDs that are allowed to create MUC rooms.
*
* @param userJID the bare JID of the user to remove from the list.
*/
void removeUserAllowedToCreate(String userJID);
void removeUserAllowedToCreate(JID userJID);
/**
* Sets the time to elapse between clearing of idle chat users. A <code>TimerTask</code> will be
......
......@@ -20,33 +20,40 @@
package org.jivesoftware.openfire.muc.cluster;
import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
import org.jivesoftware.util.cache.ExternalizableUtil;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
import org.jivesoftware.util.cache.ExternalizableUtil;
import org.xmpp.packet.JID;
/**
* Task that adds a new member to the room in the other cluster nodes.
*
* @author Gaston Dombiak
*/
public class AddMember extends MUCRoomTask {
private String bareJID;
private JID bareJID;
private String nickname;
public AddMember() {
super();
}
public AddMember(LocalMUCRoom room, JID bareJID, String nickname) {
super(room);
this.bareJID = new JID(bareJID.toBareJID());
this.nickname = nickname;
}
public AddMember(LocalMUCRoom room, String bareJID, String nickname) {
super(room);
this.bareJID = bareJID;
this.bareJID = new JID(new JID(bareJID).toBareJID());
this.nickname = nickname;
}
public String getBareJID() {
public JID getBareJID() {
return bareJID;
}
......@@ -70,14 +77,14 @@ public class AddMember extends MUCRoomTask {
@Override
public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal(out);
ExternalizableUtil.getInstance().writeSafeUTF(out, bareJID);
ExternalizableUtil.getInstance().writeSafeUTF(out, bareJID.toFullJID());
ExternalizableUtil.getInstance().writeSafeUTF(out, nickname);
}
@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in);
bareJID = ExternalizableUtil.getInstance().readSafeUTF(in);
bareJID = new JID(ExternalizableUtil.getInstance().readSafeUTF(in));
nickname = ExternalizableUtil.getInstance().readSafeUTF(in);
}
}
......@@ -20,13 +20,14 @@
package org.jivesoftware.openfire.muc.cluster;
import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
import org.jivesoftware.util.cache.ExternalizableUtil;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
import org.jivesoftware.util.cache.ExternalizableUtil;
import org.xmpp.packet.JID;
/**
* Task that destroys the local room in the cluster node. Local room occupants
* hosted in the cluster node will get the notification of the room being
......@@ -35,18 +36,24 @@ import java.io.ObjectOutput;
* @author Gaston Dombiak
*/
public class DestroyRoomRequest extends MUCRoomTask {
private String alternateJID;
private JID alternateJID;
private String reason;
public DestroyRoomRequest() {
}
public DestroyRoomRequest(LocalMUCRoom room, String alternateJID, String reason) {
public DestroyRoomRequest(LocalMUCRoom room, JID alternateJID, String reason) {
super(room);
this.alternateJID = alternateJID;
this.reason = reason;
}
public DestroyRoomRequest(LocalMUCRoom room, String alternateJID, String reason) {
super(room);
this.alternateJID = new JID(alternateJID);
this.reason = reason;
}
public Object getResult() {
return null;
}
......@@ -60,7 +67,7 @@ public class DestroyRoomRequest extends MUCRoomTask {
});
}
public String getAlternateJID() {
public JID getAlternateJID() {
return alternateJID;
}
......@@ -73,7 +80,7 @@ public class DestroyRoomRequest extends MUCRoomTask {
super.writeExternal(out);
ExternalizableUtil.getInstance().writeBoolean(out, alternateJID != null);
if (alternateJID != null) {
ExternalizableUtil.getInstance().writeSafeUTF(out, alternateJID);
ExternalizableUtil.getInstance().writeSafeUTF(out, alternateJID.toFullJID());
}
ExternalizableUtil.getInstance().writeBoolean(out, reason != null);
if (reason != null) {
......@@ -85,7 +92,7 @@ public class DestroyRoomRequest extends MUCRoomTask {
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in);
if (ExternalizableUtil.getInstance().readBoolean(in)) {
alternateJID = ExternalizableUtil.getInstance().readSafeUTF(in);
alternateJID = new JID(ExternalizableUtil.getInstance().readSafeUTF(in));
}
if (ExternalizableUtil.getInstance().readBoolean(in)) {
reason = ExternalizableUtil.getInstance().readSafeUTF(in);
......
......@@ -30,21 +30,23 @@ import org.xmpp.packet.JID;
* Represents an entry in the conversation log of a room. An entry basically obtains the necessary
* information to log from the message adding a timestamp of when the message was sent to the room.
*
* Instances of this class are immutable, and therefor thread safe.
*
* @author Gaston Dombiak
*/
class ConversationLogEntry {
private Date date;
private final Date date;
private String subject;
private final String subject;
private String body;
private final String body;
private JID sender;
private final JID sender;
private String nickname;
private final String nickname;
private long roomID;
private final long roomID;
/**
* Creates a new ConversationLogEntry that registers that a given message was sent to a given
......
......@@ -47,11 +47,11 @@ import org.xmpp.packet.Presence;
*/
public class IQAdminHandler {
private LocalMUCRoom room;
private final LocalMUCRoom room;
private PacketRouter router;
private final PacketRouter router;
private boolean skipInvite;
private final boolean skipInvite;
public IQAdminHandler(LocalMUCRoom chatroom, PacketRouter packetRouter) {
this.room = chatroom;
......@@ -89,7 +89,9 @@ public class IQAdminHandler {
Element element = packet.getChildElement();
// Analyze the action to perform based on the included element
List itemsList = element.elements("item");
@SuppressWarnings("unchecked")
List<Element> itemsList = element.elements("item");
if (!itemsList.isEmpty()) {
handleItemsElement(role, itemsList, reply);
}
......@@ -122,13 +124,13 @@ public class IQAdminHandler {
* @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 itemsList, IQ reply)
private void handleItemsElement(MUCRole senderRole, List<Element> itemsList, IQ reply)
throws ForbiddenException, ConflictException, NotAllowedException, CannotBeInvitedException {
Element item;
String affiliation;
String roleAttribute;
boolean hasJID = ((Element)itemsList.get(0)).attributeValue("jid") != null;
boolean hasNick = ((Element)itemsList.get(0)).attributeValue("nick") != null;
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
......@@ -147,10 +149,10 @@ public class IQAdminHandler {
&& MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
for (String jid : room.getOutcasts()) {
for (JID jid : room.getOutcasts()) {
metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin");
metaData.addAttribute("affiliation", "outcast");
metaData.addAttribute("jid", jid);
metaData.addAttribute("jid", jid.toString());
}
} else if ("member".equals(affiliation)) {
......@@ -161,10 +163,10 @@ public class IQAdminHandler {
&& MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
for (String jid : room.getMembers()) {
for (JID jid : room.getMembers()) {
metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin");
metaData.addAttribute("affiliation", "member");
metaData.addAttribute("jid", jid);
metaData.addAttribute("jid", jid.toString());
try {
List<MUCRole> roles = room.getOccupantsByBareJID(jid);
MUCRole role = roles.get(0);
......@@ -210,7 +212,7 @@ public class IQAdminHandler {
JID jid;
String nick;
String target;
boolean hasAffiliation = ((Element) itemsList.get(0)).attributeValue("affiliation") !=
boolean hasAffiliation = itemsList.get(0).attributeValue("affiliation") !=
null;
// Keep a registry of the updated presences
......@@ -246,7 +248,7 @@ public class IQAdminHandler {
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.toBareJID()) != MUCRole.Affiliation.none;
boolean hadAffiliation = room.getAffiliation(jid) != MUCRole.Affiliation.none;
presences.addAll(room.addMember(jid, nick, senderRole));
// If the user had an affiliation don't send an invitation. Otherwise
// send an invitation if the room is members-only and skipping invites
......
......@@ -52,65 +52,63 @@ class IQMUCRegisterHandler {
private static final Logger Log = LoggerFactory.getLogger(IQMUCRegisterHandler.class);
private static Element probeResult;
private MultiUserChatService mucService;
private static final Element probeResult;
static {
// Create the registration form of the room which contains information
// such as: first name, last name and nickname.
final DataForm registrationForm = new DataForm(DataForm.Type.form);
registrationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.reg.title"));
registrationForm.addInstruction(LocaleUtils
.getLocalizedString("muc.form.reg.instruction"));
final FormField fieldForm = registrationForm.addField();
fieldForm.setVariable("FORM_TYPE");
fieldForm.setType(FormField.Type.hidden);
fieldForm.addValue("http://jabber.org/protocol/muc#register");
final FormField fieldReg = registrationForm.addField();
fieldReg.setVariable("muc#register_first");
fieldReg.setType(FormField.Type.text_single);
fieldReg.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.first-name"));
fieldReg.setRequired(true);
final FormField fieldLast = registrationForm.addField();
fieldLast.setVariable("muc#register_last");
fieldLast.setType(FormField.Type.text_single);
fieldLast.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.last-name"));
fieldLast.setRequired(true);
final FormField fieldNick = registrationForm.addField();
fieldNick.setVariable("muc#register_roomnick");
fieldNick.setType(FormField.Type.text_single);
fieldNick.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.nickname"));
fieldNick.setRequired(true);
final FormField fieldUrl = registrationForm.addField();
fieldUrl.setVariable("muc#register_url");
fieldUrl.setType(FormField.Type.text_single);
fieldUrl.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.url"));
final FormField fieldMail = registrationForm.addField();
fieldMail.setVariable("muc#register_email");
fieldMail.setType(FormField.Type.text_single);
fieldMail.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.email"));
final FormField fieldFaq = registrationForm.addField();
fieldFaq.setVariable("muc#register_faqentry");
fieldFaq.setType(FormField.Type.text_single);
fieldFaq.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.faqentry"));
// Create the probeResult and add the registration form
probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register"));
probeResult.add(registrationForm.getElement());
}
private final MultiUserChatService mucService;
public IQMUCRegisterHandler(MultiUserChatService mucService) {
this.mucService = mucService;
initialize();
}
public void initialize() {
if (probeResult == null) {
// Create the registration form of the room which contains information
// such as: first name, last name and nickname.
final DataForm registrationForm = new DataForm(DataForm.Type.form);
registrationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.reg.title"));
registrationForm.addInstruction(LocaleUtils
.getLocalizedString("muc.form.reg.instruction"));
final FormField fieldForm = registrationForm.addField();
fieldForm.setVariable("FORM_TYPE");
fieldForm.setType(FormField.Type.hidden);
fieldForm.addValue("http://jabber.org/protocol/muc#register");
final FormField fieldReg = registrationForm.addField();
fieldReg.setVariable("muc#register_first");
fieldReg.setType(FormField.Type.text_single);
fieldReg.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.first-name"));
fieldReg.setRequired(true);
final FormField fieldLast = registrationForm.addField();
fieldLast.setVariable("muc#register_last");
fieldLast.setType(FormField.Type.text_single);
fieldLast.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.last-name"));
fieldLast.setRequired(true);
final FormField fieldNick = registrationForm.addField();
fieldNick.setVariable("muc#register_roomnick");
fieldNick.setType(FormField.Type.text_single);
fieldNick.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.nickname"));
fieldNick.setRequired(true);
final FormField fieldUrl = registrationForm.addField();
fieldUrl.setVariable("muc#register_url");
fieldUrl.setType(FormField.Type.text_single);
fieldUrl.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.url"));
final FormField fieldMail = registrationForm.addField();
fieldMail.setVariable("muc#register_email");
fieldMail.setType(FormField.Type.text_single);
fieldMail.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.email"));
final FormField fieldFaq = registrationForm.addField();
fieldFaq.setVariable("muc#register_faqentry");
fieldFaq.setType(FormField.Type.text_single);
fieldFaq.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.faqentry"));
// Create the probeResult and add the registration form
probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register"));
probeResult.add(registrationForm.getElement());
}
}
public IQ handleIQ(IQ packet) {
......@@ -138,16 +136,19 @@ class IQMUCRegisterHandler {
if (IQ.Type.get == packet.getType()) {
reply = IQ.createResultIQ(packet);
String nickname = room.getReservedNickname(packet.getFrom().toBareJID());
String nickname = room.getReservedNickname(packet.getFrom());
Element currentRegistration = probeResult.createCopy();
if (nickname != null) {
// The user is already registered with the room so answer a completed form
ElementUtil.setProperty(currentRegistration, "query.registered", null);
Element form = currentRegistration.element(QName.get("x", "jabber:x:data"));
Iterator fields = form.elementIterator("field");
@SuppressWarnings("unchecked")
Iterator<Element> fields = form.elementIterator("field");
Element field;
while (fields.hasNext()) {
field = (Element) fields.next();
field = fields.next();
if ("muc#register_roomnick".equals(field.attributeValue("var"))) {
field.addElement("value").addText(nickname);
}
......
......@@ -60,15 +60,15 @@ public class IQOwnerHandler {
private static final Logger Log = LoggerFactory.getLogger(IQOwnerHandler.class);
private LocalMUCRoom room;
private final LocalMUCRoom room;
private PacketRouter router;
private final PacketRouter router;
private DataForm configurationForm;
private Element probeResult;
private boolean skipInvite;
private final boolean skipInvite;
public IQOwnerHandler(LocalMUCRoom chatroom, PacketRouter packetRouter) {
this.room = chatroom;
......@@ -122,8 +122,8 @@ public class IQOwnerHandler {
}
}
room.destroyRoom(destroyElement.attributeValue("jid"), destroyElement
.elementTextTrim("reason"));
room.destroyRoom(new JID(destroyElement.attributeValue("jid")),
destroyElement.elementTextTrim("reason"));
}
else {
List<Element> itemsList = element.elements("item");
......@@ -183,10 +183,10 @@ public class IQOwnerHandler {
// The client is requesting the list of owners
Element ownerMetaData;
MUCRole role;
for (String jid : room.getOwners()) {
for (JID jid : room.getOwners()) {
ownerMetaData = result.addElement("item", "http://jabber.org/protocol/muc#owner");
ownerMetaData.addAttribute("affiliation", "owner");
ownerMetaData.addAttribute("jid", jid);
ownerMetaData.addAttribute("jid", jid.toString());
// Add role and nick to the metadata if the user is in the room
try {
List<MUCRole> roles = room.getOccupantsByBareJID(jid);
......@@ -202,10 +202,10 @@ public class IQOwnerHandler {
// The client is requesting the list of admins
Element adminMetaData;
MUCRole role;
for (String jid : room.getAdmins()) {
for (JID jid : room.getAdmins()) {
adminMetaData = result.addElement("item", "http://jabber.org/protocol/muc#owner");
adminMetaData.addAttribute("affiliation", "admin");
adminMetaData.addAttribute("jid", jid);
adminMetaData.addAttribute("jid", jid.toString());
// Add role and nick to the metadata if the user is in the room
try {
List<MUCRole> roles = room.getOccupantsByBareJID(jid);
......@@ -270,7 +270,7 @@ public class IQOwnerHandler {
presences.addAll(room.addAdmin(jid, senderRole));
} else if ("member".equals(targetAffiliation)) {
// Add the new user as a member of the room
boolean hadAffiliation = room.getAffiliation(jid.toBareJID()) != MUCRole.Affiliation.none;
boolean hadAffiliation = room.getAffiliation(jid) != MUCRole.Affiliation.none;
presences.addAll(room.addMember(jid, null, senderRole));
// If the user had an affiliation don't send an invitation. Otherwise
// send an invitation if the room is members-only and skipping invites
......@@ -365,17 +365,25 @@ public class IQOwnerHandler {
// Get the new list of admins
field = completedForm.getField("muc#roomconfig_roomadmins");
boolean adminsSent = field != null;
List<String> admins = new ArrayList<String>();
List<JID> admins = new ArrayList<JID>();
if (field != null) {
admins.addAll(field.getValues());
for (String value : field.getValues()) {
// XEP-0045: "Affiliations are granted, revoked, and
// maintained based on the user's bare JID, (...)"
admins.add(new JID(new JID(value).toBareJID()));
}
}
// Get the new list of owners
field = completedForm.getField("muc#roomconfig_roomowners");
boolean ownersSent = field != null;
List<String> owners = new ArrayList<String>();
List<JID> owners = new ArrayList<JID>();
if (field != null) {
owners.addAll(field.getValues());
for(String value : field.getValues()) {
// XEP-0045: "Affiliations are granted, revoked, and
// maintained based on the user's bare JID, (...)"
owners.add(new JID(new JID(value).toBareJID()));
}
}
// Answer a conflic error if all the current owners will be removed
......@@ -526,22 +534,22 @@ public class IQOwnerHandler {
if (ownersSent) {
// Change the affiliation to "member" for the current owners that won't be neither
// owner nor admin (if the form included the owners field)
List<String> ownersToRemove = new ArrayList<String>(room.owners);
List<JID> ownersToRemove = new ArrayList<JID>(room.owners);
ownersToRemove.removeAll(admins);
ownersToRemove.removeAll(owners);
for (String jid : ownersToRemove) {
presences.addAll(room.addMember(new JID(jid), null, senderRole));
for (JID jid : ownersToRemove) {
presences.addAll(room.addMember(jid, null, senderRole));
}
}
if (adminsSent) {
// Change the affiliation to "member" for the current admins that won't be neither
// owner nor admin (if the form included the admins field)
List<String> adminsToRemove = new ArrayList<String>(room.admins);
List<JID> adminsToRemove = new ArrayList<JID>(room.admins);
adminsToRemove.removeAll(admins);
adminsToRemove.removeAll(owners);
for (String jid : adminsToRemove) {
presences.addAll(room.addMember(new JID(jid), null, senderRole));
for (JID jid : adminsToRemove) {
presences.addAll(room.addMember(jid, null, senderRole));
}
}
......@@ -632,14 +640,14 @@ public class IQOwnerHandler {
field = configurationForm.getField("muc#roomconfig_roomadmins");
field.clearValues();
for (String jid : room.getAdmins()) {
field.addValue(jid);
for (JID jid : room.getAdmins()) {
field.addValue(jid.toString());
}
field = configurationForm.getField("muc#roomconfig_roomowners");
field.clearValues();
for (String jid : room.getOwners()) {
field.addValue(jid);
for (JID jid : room.getOwners()) {
field.addValue(jid.toString());
}
// Remove the old element
......
......@@ -312,9 +312,12 @@ public class LocalMUCUser implements MUCUser {
List<Element> extensions = new ArrayList<Element>(packet
.getElement().elements());
extensions.remove(userInfo);
// Send invitations to invitees
for (Iterator it=userInfo.elementIterator("invite");it.hasNext();) {
Element info = (Element) it.next();
@SuppressWarnings("unchecked")
Iterator<Element> it = userInfo.elementIterator("invite");
while(it.hasNext()) {
Element info = it.next();
JID jid = new JID(info.attributeValue("to"));
// Add the user as a member of the room if the room is
......
......@@ -557,16 +557,8 @@ public class MUCPersistenceManager {
} catch (IllegalArgumentException ex) {
Log.warn("An illegal JID ({}) was found in the database, "
+ "while trying to load all affiliations for room "
+ "{} on the MUC service {}. An attempt is made to"
+ " delete the associated affiliation. The JID is"
+ " otherwise ignored.", new Object[] { jidValue,
roomID, chatserver.getName() });
try {
removeAffiliationFromDB(room, jidValue, affiliation);
Log.warn("Affiliation removed.");
} catch (RuntimeException e) {
Log.warn("Unable to remove affiliation.", e);
}
+ "{} on the MUC service {}. The JID is ignored."
, new Object[] { jidValue, roomID, chatserver.getName() });
continue;
}
try {
......@@ -727,9 +719,10 @@ public class MUCPersistenceManager {
* @param newAffiliation the new affiliation of the user in the room.
* @param oldAffiliation the previous affiliation of the user in the room.
*/
public static void saveAffiliationToDB(MUCRoom room, String bareJID, String nickname,
public static void saveAffiliationToDB(MUCRoom room, JID jid, String nickname,
MUCRole.Affiliation newAffiliation, MUCRole.Affiliation oldAffiliation)
{
final String bareJID = jid.toBareJID();
if (!room.isPersistent() || !room.wasSavedToDB()) {
return;
}
......@@ -880,9 +873,10 @@ public class MUCPersistenceManager {
* @param bareJID The bareJID of the user to remove his affiliation.
* @param oldAffiliation the previous affiliation of the user in the room.
*/
public static void removeAffiliationFromDB(MUCRoom room, String bareJID,
public static void removeAffiliationFromDB(MUCRoom room, JID jid,
MUCRole.Affiliation oldAffiliation)
{
final String bareJID = jid.toBareJID();
if (room.isPersistent() && room.wasSavedToDB()) {
if (MUCRole.Affiliation.member == oldAffiliation) {
// Remove the user from the members table
......@@ -1004,13 +998,14 @@ public class MUCPersistenceManager {
* @param name the name of the property to return.
* @return the property value specified by name.
*/
public static String getProperty(String subdomain, String name) {
MUCServiceProperties properties = propertyMaps.get(subdomain);
if (properties == null) {
properties = new MUCServiceProperties(subdomain);
propertyMaps.put(subdomain, properties);
}
return properties.get(name);
public static String getProperty(String subdomain, String name) {
final MUCServiceProperties newProps = new MUCServiceProperties(subdomain);
final MUCServiceProperties oldProps = propertyMaps.putIfAbsent(subdomain, newProps);
if (oldProps != null) {
return oldProps.get(name);
} else {
return newProps.get(name);
}
}
/**
......@@ -1023,18 +1018,12 @@ public class MUCPersistenceManager {
* @return the property value specified by name.
*/
public static String getProperty(String subdomain, String name, String defaultValue) {
MUCServiceProperties properties = propertyMaps.get(subdomain);
if (properties == null) {
properties = new MUCServiceProperties(subdomain);
propertyMaps.put(subdomain, properties);
}
String value = properties.get(name);
if (value != null) {
return value;
}
else {
return defaultValue;
}
final String value = getProperty(subdomain, name);
if (value != null) {
return value;
} else {
return defaultValue;
}
}
/**
......@@ -1130,11 +1119,11 @@ public class MUCPersistenceManager {
* @return a List of all immediate children property names (Strings).
*/
public static List<String> getPropertyNames(String subdomain, String parent) {
MUCServiceProperties properties = propertyMaps.get(subdomain);
if (properties == null) {
properties = new MUCServiceProperties(subdomain);
propertyMaps.put(subdomain, properties);
}
MUCServiceProperties properties = new MUCServiceProperties(subdomain);
final MUCServiceProperties oldProps = propertyMaps.putIfAbsent(subdomain, properties);
if (oldProps != null) {
properties = oldProps;
}
return new ArrayList<String>(properties.getChildrenNames(parent));
}
......@@ -1150,11 +1139,11 @@ public class MUCPersistenceManager {
* @return all child property values for the given parent.
*/
public static List<String> getProperties(String subdomain, String parent) {
MUCServiceProperties properties = propertyMaps.get(subdomain);
if (properties == null) {
properties = new MUCServiceProperties(subdomain);
propertyMaps.put(subdomain, properties);
}
MUCServiceProperties properties = new MUCServiceProperties(subdomain);
final MUCServiceProperties oldProps = propertyMaps.putIfAbsent(subdomain, properties);
if (oldProps != null) {
properties = oldProps;
}
Collection<String> propertyNames = properties.getChildrenNames(parent);
List<String> values = new ArrayList<String>();
......@@ -1175,11 +1164,11 @@ public class MUCPersistenceManager {
* @return a List of all property names (Strings).
*/
public static List<String> getPropertyNames(String subdomain) {
MUCServiceProperties properties = propertyMaps.get(subdomain);
if (properties == null) {
properties = new MUCServiceProperties(subdomain);
propertyMaps.put(subdomain, properties);
}
MUCServiceProperties properties = new MUCServiceProperties(subdomain);
final MUCServiceProperties oldProps = propertyMaps.putIfAbsent(subdomain, properties);
if (oldProps != null) {
properties = oldProps;
}
return new ArrayList<String>(properties.getPropertyNames());
}
......
......@@ -198,13 +198,13 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
* Bare jids of users that are allowed to create MUC rooms. An empty list means that anyone can
* create a room.
*/
private List<String> allowedToCreate = new CopyOnWriteArrayList<String>();
private List<JID> allowedToCreate = new CopyOnWriteArrayList<JID>();
/**
* Bare jids of users that are system administrators of the MUC service. A sysadmin has the same
* permissions as a room owner.
*/
private List<String> sysadmins = new CopyOnWriteArrayList<String>();
private List<JID> sysadmins = new CopyOnWriteArrayList<JID>();
/**
* Queue that holds the messages to log for the rooms that need to log their conversations.
......@@ -547,15 +547,16 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
else {
// The room does not exist so check for creation permissions
// Room creation is always allowed for sysadmin
if (isRoomCreationRestricted() && !sysadmins.contains(userjid.toBareJID())) {
final JID bareJID = new JID(userjid.toBareJID());
if (isRoomCreationRestricted() && !sysadmins.contains(bareJID)) {
// The room creation is only allowed for certain JIDs
if (!allowedToCreate.contains(userjid.toBareJID())) {
if (!allowedToCreate.contains(bareJID)) {
// The user is not in the list of allowed JIDs to create a room so raise
// an exception
throw new NotAllowedException();
}
}
room.addFirstOwner(userjid.toBareJID());
room.addFirstOwner(userjid);
created = true;
}
}
......@@ -806,31 +807,42 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
return log_batch_size;
}
public Collection<String> getUsersAllowedToCreate() {
return allowedToCreate;
public Collection<JID> getUsersAllowedToCreate() {
return Collections.unmodifiableCollection(allowedToCreate);
}
public Collection<String> getSysadmins() {
return sysadmins;
public Collection<JID> getSysadmins() {
return Collections.unmodifiableCollection(sysadmins);
}
public void addSysadmin(String userJID) {
sysadmins.add(userJID.trim().toLowerCase());
public void addSysadmin(JID userJID) {
final JID bareJID = new JID(userJID.toBareJID());
sysadmins.add(bareJID);
// CopyOnWriteArray does not allow sorting, so do sorting in temp list.
ArrayList<String> tempList = new ArrayList<String>(sysadmins);
ArrayList<JID> tempList = new ArrayList<JID>(sysadmins);
Collections.sort(tempList);
sysadmins = new CopyOnWriteArrayList<String>(tempList);
sysadmins = new CopyOnWriteArrayList<JID>(tempList);
// Update the config.
String[] jids = new String[sysadmins.size()];
jids = sysadmins.toArray(jids);
for (int i = 0; i < jids.length; i++) {
jids[i] = sysadmins.get(i).toBareJID();
}
MUCPersistenceManager.setProperty(chatServiceName, "sysadmin.jid", fromArray(jids));
}
public void removeSysadmin(String userJID) {
sysadmins.remove(userJID.trim().toLowerCase());
public void removeSysadmin(JID userJID) {
final JID bareJID = new JID(userJID.toBareJID());
sysadmins.remove(bareJID);
// Update the config.
String[] jids = new String[sysadmins.size()];
jids = sysadmins.toArray(jids);
for (int i = 0; i < jids.length; i++) {
jids[i] = sysadmins.get(i).toBareJID();
}
MUCPersistenceManager.setProperty(chatServiceName, "sysadmin.jid", fromArray(jids));
}
......@@ -868,27 +880,39 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
MUCPersistenceManager.setProperty(chatServiceName, "create.anyone", Boolean.toString(roomCreationRestricted));
}
public void addUserAllowedToCreate(String userJID) {
public void addUserAllowedToCreate(JID userJID) {
final JID bareJID = new JID(userJID.toBareJID());
// Update the list of allowed JIDs to create MUC rooms. Since we are updating the instance
// variable there is no need to restart the service
allowedToCreate.add(userJID.trim().toLowerCase());
allowedToCreate.add(bareJID);
// CopyOnWriteArray does not allow sorting, so do sorting in temp list.
ArrayList<String> tempList = new ArrayList<String>(allowedToCreate);
ArrayList<JID> tempList = new ArrayList<JID>(allowedToCreate);
Collections.sort(tempList);
allowedToCreate = new CopyOnWriteArrayList<String>(tempList);
allowedToCreate = new CopyOnWriteArrayList<JID>(tempList);
// Update the config.
String[] jids = new String[allowedToCreate.size()];
jids = allowedToCreate.toArray(jids);
for (int i = 0; i < jids.length; i++) {
jids[i] = allowedToCreate.get(i).toBareJID();
}
MUCPersistenceManager.setProperty(chatServiceName, "create.jid", fromArray(jids));
}
public void removeUserAllowedToCreate(String userJID) {
public void removeUserAllowedToCreate(JID userJID) {
final JID bareJID = new JID(userJID.toBareJID());
// Update the list of allowed JIDs to create MUC rooms. Since we are updating the instance
// variable there is no need to restart the service
allowedToCreate.remove(userJID.trim().toLowerCase());
allowedToCreate.remove(bareJID);
// Update the config.
String[] jids = new String[allowedToCreate.size()];
jids = allowedToCreate.toArray(jids);
for (int i = 0; i < jids.length; i++) {
jids[i] = allowedToCreate.get(i).toBareJID();
}
MUCPersistenceManager.setProperty(chatServiceName, "create.jid", fromArray(jids));
}
......@@ -915,7 +939,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
if (property != null) {
jids = property.split(",");
for (String jid : jids) {
sysadmins.add(jid.trim().toLowerCase());
sysadmins.add(new JID(new JID(jid.trim().toLowerCase()).toBareJID()));
}
}
allowToDiscoverLockedRooms =
......@@ -928,7 +952,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
if (property != null) {
jids = property.split(",");
for (String jid : jids) {
allowedToCreate.add(jid.trim().toLowerCase());
allowedToCreate.add(new JID(new JID(jid.trim().toLowerCase()).toBareJID()));
}
}
String value = MUCPersistenceManager.getProperty(chatServiceName, "tasks.user.timeout");
......@@ -1201,7 +1225,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
// Answer reserved nickname for the sender of the disco request in the requested room
MUCRoom room = getChatRoom(name);
if (room != null) {
String reservedNick = room.getReservedNickname(senderJID.toBareJID());
String reservedNick = room.getReservedNickname(senderJID);
if (reservedNick != null) {
Element identity = DocumentHelper.createElement("identity");
identity.addAttribute("category", "conference");
......@@ -1346,12 +1370,14 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
* @param name Name of identity to remove.
*/
public void removeExtraIdentity(String name) {
for (Element elem : extraDiscoIdentities) {
final Iterator<Element> iter = extraDiscoIdentities.iterator();
while (iter.hasNext()) {
Element elem = iter.next();
if (name.equals(elem.attribute("name").getStringValue())) {
extraDiscoFeatures.remove(elem);
iter.remove();
break;
}
}
}
}
/**
......
......@@ -145,7 +145,6 @@ public class WebDAVLiteServlet extends HttpServlet {
private Boolean isAuthorized(HttpServletRequest request, HttpServletResponse response,
String service, String room) throws ServletException, IOException {
String auth = request.getHeader("Authorization");
JID jid;
try {
if (auth == null || !request.getAuthType().equals(HttpServletRequest.BASIC_AUTH)) {
throw new Exception("No authorization or improper authorization provided.");
......@@ -157,8 +156,8 @@ public class WebDAVLiteServlet extends HttpServlet {
if (!username.contains("@")) {
throw new Exception("Not a valid JID.");
}
jid = new JID(username);
XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(service).getChatRoom(room).getOccupantsByBareJID(jid.toBareJID());
final JID bareJID = new JID(new JID(username).toBareJID());
XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(service).getChatRoom(room).getOccupantsByBareJID(bareJID);
return true;
}
catch (Exception e) {
......
......@@ -74,7 +74,7 @@ public class DummyExternalizableUtil implements ExternalizableUtilStrategy {
* @return a Map of Long key/Integer value pairs.
* @throws IOException if an error occurs.
*/
public Map readLongIntMap(DataInput in) throws IOException {
public Map<Long, Integer> readLongIntMap(DataInput in) throws IOException {
// Do nothing
return Collections.emptyMap();
}
......@@ -87,7 +87,7 @@ public class DummyExternalizableUtil implements ExternalizableUtilStrategy {
* @param stringList the List of Strings.
* @throws IOException if an error occurs.
*/
public void writeStringList(DataOutput out, List stringList) throws IOException {
public void writeStringList(DataOutput out, List<String> stringList) throws IOException {
// Do nothing
}
......@@ -206,11 +206,11 @@ public class DummyExternalizableUtil implements ExternalizableUtilStrategy {
return 0;
}
public void writeSerializableMap(DataOutput out, Map<String, ? extends Serializable> map) throws IOException {
public void writeSerializableMap(DataOutput out, Map<? extends Serializable, ? extends Serializable> map) throws IOException {
// Do nothing
}
public int readSerializableMap(DataInput in, Map<String, ? extends Serializable> map, ClassLoader loader)
public int readSerializableMap(DataInput in, Map<? extends Serializable, ? extends Serializable> map, ClassLoader loader)
throws IOException {
// Do nothing
return 0;
......
......@@ -124,7 +124,7 @@ public class ExternalizableUtil {
* @return a Map of Long key/Integer value pairs.
* @throws IOException if an error occurs.
*/
public Map readLongIntMap(DataInput in) throws IOException {
public Map<Long, Integer> readLongIntMap(DataInput in) throws IOException {
return strategy.readLongIntMap(in);
}
......@@ -136,7 +136,7 @@ public class ExternalizableUtil {
* @param stringList the List of Strings.
* @throws IOException if an error occurs.
*/
public void writeStringList(DataOutput out, List stringList) throws IOException {
public void writeStringList(DataOutput out, List<String> stringList) throws IOException {
strategy.writeStringList(out, stringList);
}
......@@ -291,14 +291,14 @@ public class ExternalizableUtil {
}
/**
* Writes a Map of String key and value pairs. This method handles the
* Writes a Map of Serializable key and value pairs. This method handles the
* case when the Map is <tt>null</tt>.
*
* @param out the output stream.
* @param map the Map of String key and Externalizable value pairs.
* @param map the Map of Serializable key and value pairs.
* @throws java.io.IOException if an error occurs.
*/
public void writeSerializableMap(DataOutput out, Map<String, ? extends Serializable> map) throws IOException {
public void writeSerializableMap(DataOutput out, Map<? extends Serializable, ? extends Serializable> map) throws IOException {
strategy.writeSerializableMap(out, map);
}
......@@ -317,16 +317,16 @@ public class ExternalizableUtil {
}
/**
* Reads a Map of String key and value pairs. This method will return
* Reads a Map of Serializable key and value pairs. This method will return
* <tt>null</tt> if the Map written to the stream was <tt>null</tt>.
*
* @param in the input stream.
* @param map a Map of String key and Serializable value pairs.
* @param map a Map of Serializable key and value pairs.
* @param loader class loader to use to build elements inside of the serialized collection.
* @throws IOException if an error occurs.
* @return the number of elements added to the collection.
*/
public int readSerializableMap(DataInput in, Map<String, ? extends Serializable> map, ClassLoader loader) throws IOException {
public int readSerializableMap(DataInput in, Map<? extends Serializable, ? extends Serializable> map, ClassLoader loader) throws IOException {
return strategy.readSerializableMap(in, map, loader);
}
......
......@@ -72,7 +72,7 @@ public interface ExternalizableUtilStrategy {
* @return a Map of Long key/Integer value pairs.
* @throws IOException if an error occurs.
*/
Map readLongIntMap(DataInput in) throws IOException;
Map<Long, Integer> readLongIntMap(DataInput in) throws IOException;
/**
* Writes a List of Strings. This method handles the case when the List is
......@@ -82,7 +82,7 @@ public interface ExternalizableUtilStrategy {
* @param stringList the List of Strings.
* @throws IOException if an error occurs.
*/
void writeStringList(DataOutput out, List stringList) throws IOException;
void writeStringList(DataOutput out, List<String> stringList) throws IOException;
/**
* Reads a List of Strings. This method will return <tt>null</tt> if the List
......@@ -148,9 +148,9 @@ public interface ExternalizableUtilStrategy {
int readExternalizableMap(DataInput in, Map<String, ? extends Externalizable> map, ClassLoader loader) throws IOException;
void writeSerializableMap(DataOutput out, Map<String, ? extends Serializable> map) throws IOException;
void writeSerializableMap(DataOutput out, Map<? extends Serializable, ? extends Serializable> map) throws IOException;
int readSerializableMap(DataInput in, Map<String, ? extends Serializable> map, ClassLoader loader) throws IOException;
int readSerializableMap(DataInput in, Map<? extends Serializable, ? extends Serializable> map, ClassLoader loader) throws IOException;
void writeStringsMap(DataOutput out, Map<String, Set<String>> map) throws IOException;
......
......@@ -320,7 +320,7 @@ public class CoherenceExternalizableUtil implements ExternalizableUtilStrategy {
ExternalizableHelper.writeMap(out, map);
}
public void writeSerializableMap(DataOutput out, Map<String, ? extends Serializable> map) throws IOException {
public void writeSerializableMap(DataOutput out, Map<? extends Serializable, ? extends Serializable> map) throws IOException {
ExternalizableHelper.writeMap(out, map);
}
......@@ -328,7 +328,7 @@ public class CoherenceExternalizableUtil implements ExternalizableUtilStrategy {
return ExternalizableHelper.readMap(in, map, loader);
}
public int readSerializableMap(DataInput in, Map<String, ? extends Serializable> map, ClassLoader loader) throws IOException {
public int readSerializableMap(DataInput in, Map<? extends Serializable, ? extends Serializable> map, ClassLoader loader) throws IOException {
return ExternalizableHelper.readMap(in, map, loader);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment