Commit 2bb16451 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Removed UnauthorizedException as a thrown exception in methods that was being used for ACL.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@485 b35dd754-fafc-0310-a699-88a17e54d16e
parent 3233d830
...@@ -14,7 +14,6 @@ package org.jivesoftware.messenger.muc; ...@@ -14,7 +14,6 @@ package org.jivesoftware.messenger.muc;
import org.jivesoftware.messenger.IQ; import org.jivesoftware.messenger.IQ;
import org.jivesoftware.messenger.Message; import org.jivesoftware.messenger.Message;
import org.jivesoftware.messenger.Presence; import org.jivesoftware.messenger.Presence;
import org.jivesoftware.messenger.auth.UnauthorizedException;
/** /**
* Interface for any object that can accept chat messages and presence * Interface for any object that can accept chat messages and presence
...@@ -27,23 +26,20 @@ public interface ChatDeliverer { ...@@ -27,23 +26,20 @@ public interface ChatDeliverer {
* Sends a packet to the user. * Sends a packet to the user.
* *
* @param packet The packet to send * @param packet The packet to send
* @throws UnauthorizedException Thrown if unauthorized
*/ */
void send(Message packet) throws UnauthorizedException; void send(Message packet);
/** /**
* Sends a packet to the user. * Sends a packet to the user.
* *
* @param packet The packet to send * @param packet The packet to send
* @throws UnauthorizedException Thrown if unauthorized
*/ */
void send(Presence packet) throws UnauthorizedException; void send(Presence packet);
/** /**
* Sends a packet to the user. * Sends a packet to the user.
* *
* @param packet The packet to send * @param packet The packet to send
* @throws UnauthorizedException Thrown if unauthorized
*/ */
void send(IQ packet) throws UnauthorizedException; void send(IQ packet);
} }
...@@ -24,9 +24,6 @@ import org.jivesoftware.messenger.muc.spi.MUCRoleImpl; ...@@ -24,9 +24,6 @@ import org.jivesoftware.messenger.muc.spi.MUCRoleImpl;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.Message; import org.jivesoftware.messenger.Message;
import org.jivesoftware.messenger.MetaDataFragment; import org.jivesoftware.messenger.MetaDataFragment;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.muc.MUCRoomHistory;
/** /**
* Represents the amount of history requested by an occupant while joining a room. There are * Represents the amount of history requested by an occupant while joining a room. There are
...@@ -174,77 +171,72 @@ public class HistoryRequest { ...@@ -174,77 +171,72 @@ public class HistoryRequest {
* @param roomHistory the history of the room. * @param roomHistory the history of the room.
*/ */
public void sendHistory(MUCRoleImpl joinRole, MUCRoomHistory roomHistory) { public void sendHistory(MUCRoleImpl joinRole, MUCRoomHistory roomHistory) {
try { if (!isConfigured()) {
if (!isConfigured()) { Iterator history = roomHistory.getMessageHistory();
Iterator history = roomHistory.getMessageHistory(); while (history.hasNext()) {
while (history.hasNext()) { joinRole.send((Message) history.next());
joinRole.send((Message) history.next());
}
} }
else { }
if (getMaxChars() == 0) { else {
// The user requested to receive no history if (getMaxChars() == 0) {
return; // The user requested to receive no history
return;
}
Message message;
int accumulatedChars = 0;
int accumulatedStanzas = 0;
MetaDataFragment delayInformation;
LinkedList historyToSend = new LinkedList();
ListIterator iterator = roomHistory.getReverseMessageHistory();
while (iterator.hasPrevious()) {
message = (Message)iterator.previous();
// Update number of characters to send
accumulatedChars += message.getBody().length();
if (getMaxChars() > -1 && accumulatedChars > getMaxChars()) {
// Stop collecting history since we have exceded a limit
break;
} }
Message message; // Update number of messages to send
int accumulatedChars = 0; accumulatedStanzas ++;
int accumulatedStanzas = 0; if (getMaxStanzas() > -1 && accumulatedStanzas > getMaxStanzas()) {
MetaDataFragment delayInformation; // Stop collecting history since we have exceded a limit
LinkedList historyToSend = new LinkedList(); break;
ListIterator iterator = roomHistory.getReverseMessageHistory(); }
while (iterator.hasPrevious()) {
message = (Message)iterator.previous(); if (getSeconds() > -1 || getSince() != null) {
// Update number of characters to send delayInformation = (MetaDataFragment) message.getFragment(
accumulatedChars += message.getBody().length(); "x",
if (getMaxChars() > -1 && accumulatedChars > getMaxChars()) { "jabber:x:delay");
// Stop collecting history since we have exceded a limit try {
break; // Get the date when the historic message was sent
} Date delayedDate = delayedFormatter.parse(delayInformation
// Update number of messages to send .getProperty("x:stamp"));
accumulatedStanzas ++; if (getSince() != null && delayedDate.before(getSince())) {
if (getMaxStanzas() > -1 && accumulatedStanzas > getMaxStanzas()) { // Stop collecting history since we have exceded a limit
// Stop collecting history since we have exceded a limit break;
break; }
} if (getSeconds() > -1) {
Date current = new Date();
if (getSeconds() > -1 || getSince() != null) { long diff = (current.getTime() - delayedDate.getTime()) / 1000;
delayInformation = (MetaDataFragment) message.getFragment( if (getSeconds() <= diff) {
"x",
"jabber:x:delay");
try {
// Get the date when the historic message was sent
Date delayedDate = delayedFormatter.parse(delayInformation
.getProperty("x:stamp"));
if (getSince() != null && delayedDate.before(getSince())) {
// Stop collecting history since we have exceded a limit // Stop collecting history since we have exceded a limit
break; break;
} }
if (getSeconds() > -1) {
Date current = new Date();
long diff = (current.getTime() - delayedDate.getTime()) / 1000;
if (getSeconds() <= diff) {
// Stop collecting history since we have exceded a limit
break;
}
}
}
catch (ParseException e) {
Log.error("Error parsing date from historic message", e);
} }
} }
catch (ParseException e) {
historyToSend.addFirst(message); Log.error("Error parsing date from historic message", e);
} }
// Send the smallest amount of traffic to the user
Iterator history = historyToSend.iterator();
while (history.hasNext()) {
joinRole.send((Message) history.next());
} }
historyToSend.addFirst(message);
}
// Send the smallest amount of traffic to the user
Iterator history = historyToSend.iterator();
while (history.hasNext()) {
joinRole.send((Message) history.next());
} }
}
catch (UnauthorizedException e) {
// Do nothing
} }
} }
} }
...@@ -94,9 +94,8 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -94,9 +94,8 @@ public interface MUCRoom extends ChatDeliverer {
* Obtain the role of the chat server (mainly for addressing messages and presence). * Obtain the role of the chat server (mainly for addressing messages and presence).
* *
* @return The role for the chat room itself * @return The role for the chat room itself
* @throws UnauthorizedException If you don't have permission
*/ */
MUCRole getRole() throws UnauthorizedException; MUCRole getRole();
/** /**
* Obtain the role of a given user by nickname. * Obtain the role of a given user by nickname.
...@@ -130,9 +129,8 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -130,9 +129,8 @@ public interface MUCRoom extends ChatDeliverer {
* Obtain the roles of all users in the chatroom. * Obtain the roles of all users in the chatroom.
* *
* @return Iterator over all users in the chatroom * @return Iterator over all users in the chatroom
* @throws UnauthorizedException If you don't have permission to access the user
*/ */
Iterator<MUCRole> getOccupants() throws UnauthorizedException; Iterator<MUCRole> getOccupants();
/** /**
* Returns the number of occupants in the chatroom at the moment. * Returns the number of occupants in the chatroom at the moment.
...@@ -146,9 +144,8 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -146,9 +144,8 @@ public interface MUCRoom extends ChatDeliverer {
* *
* @param nickname The nickname of the user you'd like to obtain * @param nickname The nickname of the user you'd like to obtain
* @return True if a nickname is taken * @return True if a nickname is taken
* @throws UnauthorizedException If you don't have permission to access the user
*/ */
boolean hasOccupant(String nickname) throws UnauthorizedException; boolean hasOccupant(String nickname);
/** /**
* Returns the reserved room nickname for the bare JID or null if none. * Returns the reserved room nickname for the bare JID or null if none.
...@@ -195,11 +192,9 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -195,11 +192,9 @@ public interface MUCRoom extends ChatDeliverer {
* Remove a member from the chat room. * Remove a member from the chat room.
* *
* @param nickname The user to remove * @param nickname The user to remove
* @throws UnauthorizedException If the user doesn't have permission to leave the room.
* @throws UserNotFoundException If the nickname is not found. * @throws UserNotFoundException If the nickname is not found.
*/ */
void leaveRoom(String nickname) void leaveRoom(String nickname) throws UserNotFoundException;
throws UnauthorizedException, UserNotFoundException;
/** /**
* Destroys the room. Each occupant will be removed and will receive a presence stanza of type * Destroys the room. Each occupant will be removed and will receive a presence stanza of type
...@@ -208,9 +203,8 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -208,9 +203,8 @@ public interface MUCRoom extends ChatDeliverer {
* *
* @param alternateJID the alternate JID. Commonly used to provide a replacement room. * @param alternateJID the alternate JID. Commonly used to provide a replacement room.
* @param reason the reason why the room was destroyed. * @param reason the reason why the room was destroyed.
* @throws UnauthorizedException If the user doesn't have permission to destroy the room.
*/ */
void destroyRoom(String alternateJID, String reason) throws UnauthorizedException; void destroyRoom(String alternateJID, String reason);
/** /**
* Create a new presence in this room for the given role. * Create a new presence in this room for the given role.
...@@ -226,7 +220,7 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -226,7 +220,7 @@ public interface MUCRoom extends ChatDeliverer {
* *
* @param msg The message to broadcast * @param msg The message to broadcast
*/ */
void serverBroadcast(String msg) throws UnauthorizedException; void serverBroadcast(String msg);
/** /**
* Returns the total length of the chat session. * Returns the total length of the chat session.
......
...@@ -14,7 +14,6 @@ package org.jivesoftware.messenger.muc; ...@@ -14,7 +14,6 @@ package org.jivesoftware.messenger.muc;
import org.jivesoftware.util.NotFoundException; import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.messenger.XMPPAddress; import org.jivesoftware.messenger.XMPPAddress;
import org.jivesoftware.messenger.ChannelHandler; import org.jivesoftware.messenger.ChannelHandler;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import java.util.Iterator; import java.util.Iterator;
...@@ -37,9 +36,8 @@ public interface MUCUser extends ChannelHandler { ...@@ -37,9 +36,8 @@ public interface MUCUser extends ChannelHandler {
* Obtain a user ID (useful for database indexing). * Obtain a user ID (useful for database indexing).
* *
* @return The user's id number if any (-1 indicates the implementation doesn't support ids) * @return The user's id number if any (-1 indicates the implementation doesn't support ids)
* @throws UnauthorizedException If the caller doesn't have appropriate permissions
*/ */
long getID() throws UnauthorizedException; long getID();
/** /**
* Obtain the address of the user. The address is used by services like the core * Obtain the address of the user. The address is used by services like the core
...@@ -56,19 +54,16 @@ public interface MUCUser extends ChannelHandler { ...@@ -56,19 +54,16 @@ public interface MUCUser extends ChannelHandler {
* *
* @param roomName The name of the room we're interested in * @param roomName The name of the room we're interested in
* @return The role the user plays in that room * @return The role the user plays in that room
* @throws UnauthorizedException If the caller doesn't have appropriate permissions
* @throws NotFoundException if the user does not have a role in the given room * @throws NotFoundException if the user does not have a role in the given room
*/ */
MUCRole getRole(String roomName) MUCRole getRole(String roomName) throws NotFoundException;
throws UnauthorizedException, NotFoundException;
/** /**
* Get all roles for this user. * Get all roles for this user.
* *
* @return Iterator over all roles for this user * @return Iterator over all roles for this user
* @throws UnauthorizedException If the caller doesn't have permission
*/ */
Iterator<MUCRole> getRoles() throws UnauthorizedException; Iterator<MUCRole> getRoles();
/** /**
* Removes the role of the use in a particular room.<p> * Removes the role of the use in a particular room.<p>
......
...@@ -118,7 +118,7 @@ public interface MultiUserChatServer { ...@@ -118,7 +118,7 @@ public interface MultiUserChatServer {
* @param roomName Name of the room to get. * @param roomName Name of the room to get.
* @param userjid The user's normal jid, not the chat nickname jid. * @param userjid The user's normal jid, not the chat nickname jid.
* @return The chatroom for the given name. * @return The chatroom for the given name.
* @throws UnauthorizedException If the caller doesn't have permission to access this room. * @throws UnauthorizedException If the caller doesn't have permission to create a new room.
*/ */
MUCRoom getChatRoom(String roomName, XMPPAddress userjid) throws UnauthorizedException; MUCRoom getChatRoom(String roomName, XMPPAddress userjid) throws UnauthorizedException;
...@@ -150,27 +150,24 @@ public interface MultiUserChatServer { ...@@ -150,27 +150,24 @@ public interface MultiUserChatServer {
* Removes the room associated with the given name. * Removes the room associated with the given name.
* *
* @param roomName The room to remove. * @param roomName The room to remove.
* @throws UnauthorizedException If the caller doesn't have permission.
*/ */
void removeChatRoom(String roomName) throws UnauthorizedException; void removeChatRoom(String roomName);
/** /**
* Removes a user from all chat rooms. * Removes a user from all chat rooms.
* *
* @param jabberID The user's normal jid, not the chat nickname jid. * @param jabberID The user's normal jid, not the chat nickname jid.
* @throws UnauthorizedException If the caller doesn't have permission.
*/ */
void removeUser(XMPPAddress jabberID) throws UnauthorizedException; void removeUser(XMPPAddress jabberID);
/** /**
* Obtain a chat user by XMPPAddress. * Obtain a chat user by XMPPAddress.
* *
* @param userjid The XMPPAddress of the user. * @param userjid The XMPPAddress of the user.
* @return The chatuser corresponding to that XMPPAddress. * @return The chatuser corresponding to that XMPPAddress.
* @throws UnauthorizedException If the caller doesn't have permission.
* @throws UserNotFoundException If the user is not found and can't be auto-created. * @throws UserNotFoundException If the user is not found and can't be auto-created.
*/ */
MUCUser getChatUser(XMPPAddress userjid) throws UnauthorizedException, UserNotFoundException; MUCUser getChatUser(XMPPAddress userjid) throws UserNotFoundException;
/** /**
* Broadcast a given message to all members of this chat room. The sender is always set to be * Broadcast a given message to all members of this chat room. The sender is always set to be
......
...@@ -189,13 +189,8 @@ public class IQMUCRegisterHandler extends IQHandler { ...@@ -189,13 +189,8 @@ public class IQMUCRegisterHandler extends IQHandler {
} }
} }
// Send the updated presences to the room occupants // Send the updated presences to the room occupants
try { for (Presence presence : presences) {
for (Presence presence : presences) { room.send(presence);
room.send(presence);
}
}
catch (UnauthorizedException e) {
// Do nothing
} }
} }
......
...@@ -223,17 +223,17 @@ public class MUCRoleImpl implements MUCRole { ...@@ -223,17 +223,17 @@ public class MUCRoleImpl implements MUCRole {
return rJID; return rJID;
} }
public void send(Presence packet) throws UnauthorizedException { public void send(Presence packet) {
packet.setRecipient(user.getAddress()); packet.setRecipient(user.getAddress());
router.route(packet); router.route(packet);
} }
public void send(Message packet) throws UnauthorizedException { public void send(Message packet) {
packet.setRecipient(user.getAddress()); packet.setRecipient(user.getAddress());
router.route(packet); router.route(packet);
} }
public void send(IQ packet) throws UnauthorizedException { public void send(IQ packet) {
packet.setRecipient(user.getAddress()); packet.setRecipient(user.getAddress());
router.route(packet); router.route(packet);
} }
...@@ -242,7 +242,7 @@ public class MUCRoleImpl implements MUCRole { ...@@ -242,7 +242,7 @@ public class MUCRoleImpl implements MUCRole {
* Calculates and sets the extended presence information to add to the presence. The information * Calculates and sets the extended presence information to add to the presence. The information
* to add contains the user's jid, affiliation and role. * to add contains the user's jid, affiliation and role.
*/ */
private void calculateExtendedInformation() throws UnauthorizedException { private void calculateExtendedInformation() {
extendedInformation.setProperty("x.item:jid", user.getAddress().toString()); extendedInformation.setProperty("x.item:jid", user.getAddress().toString());
extendedInformation.setProperty("x.item:affiliation", getAffiliationAsString()); extendedInformation.setProperty("x.item:affiliation", getAffiliationAsString());
extendedInformation.setProperty("x.item:role", getRoleAsString()); extendedInformation.setProperty("x.item:role", getRoleAsString());
......
...@@ -195,9 +195,6 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -195,9 +195,6 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
catch (NotAllowedException e) { catch (NotAllowedException e) {
// Do nothing since we cannot kick owners or admins // Do nothing since we cannot kick owners or admins
} }
catch (UnauthorizedException e) {
// Do nothing
}
} }
} }
} }
...@@ -293,7 +290,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -293,7 +290,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return getChatRoom(roomName) != null; return getChatRoom(roomName) != null;
} }
public void removeChatRoom(String roomName) throws UnauthorizedException { public void removeChatRoom(String roomName) {
final MUCRoom room = rooms.remove(roomName.toLowerCase()); final MUCRoom room = rooms.remove(roomName.toLowerCase());
if (room != null) { if (room != null) {
final long chatLength = room.getChatLength(); final long chatLength = room.getChatLength();
...@@ -309,7 +306,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -309,7 +306,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return historyStrategy; return historyStrategy;
} }
public void removeUser(XMPPAddress jabberID) throws UnauthorizedException { public void removeUser(XMPPAddress jabberID) {
MUCUser user = users.remove(jabberID); MUCUser user = users.remove(jabberID);
if (user != null) { if (user != null) {
Iterator<MUCRole> roles = user.getRoles(); Iterator<MUCRole> roles = user.getRoles();
...@@ -325,8 +322,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha ...@@ -325,8 +322,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
} }
} }
public MUCUser getChatUser(XMPPAddress userjid) throws UnauthorizedException, public MUCUser getChatUser(XMPPAddress userjid) throws UserNotFoundException {
UserNotFoundException {
if (router == null) { if (router == null) {
throw new IllegalStateException("Not initialized"); throw new IllegalStateException("Not initialized");
} }
......
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