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;
import org.jivesoftware.messenger.IQ;
import org.jivesoftware.messenger.Message;
import org.jivesoftware.messenger.Presence;
import org.jivesoftware.messenger.auth.UnauthorizedException;
/**
* Interface for any object that can accept chat messages and presence
......@@ -27,23 +26,20 @@ public interface ChatDeliverer {
* Sends a packet to the user.
*
* @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.
*
* @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.
*
* @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;
import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.Message;
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
......@@ -174,77 +171,72 @@ public class HistoryRequest {
* @param roomHistory the history of the room.
*/
public void sendHistory(MUCRoleImpl joinRole, MUCRoomHistory roomHistory) {
try {
if (!isConfigured()) {
Iterator history = roomHistory.getMessageHistory();
while (history.hasNext()) {
joinRole.send((Message) history.next());
}
if (!isConfigured()) {
Iterator history = roomHistory.getMessageHistory();
while (history.hasNext()) {
joinRole.send((Message) history.next());
}
else {
if (getMaxChars() == 0) {
// The user requested to receive no history
return;
}
else {
if (getMaxChars() == 0) {
// 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;
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;
}
// Update number of messages to send
accumulatedStanzas ++;
if (getMaxStanzas() > -1 && accumulatedStanzas > getMaxStanzas()) {
// Stop collecting history since we have exceded a limit
break;
}
if (getSeconds() > -1 || getSince() != null) {
delayInformation = (MetaDataFragment) message.getFragment(
"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())) {
// Update number of messages to send
accumulatedStanzas ++;
if (getMaxStanzas() > -1 && accumulatedStanzas > getMaxStanzas()) {
// Stop collecting history since we have exceded a limit
break;
}
if (getSeconds() > -1 || getSince() != null) {
delayInformation = (MetaDataFragment) message.getFragment(
"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
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;
}
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);
}
}
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 (ParseException e) {
Log.error("Error parsing date from historic message", e);
}
}
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 {
* Obtain the role of the chat server (mainly for addressing messages and presence).
*
* @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.
......@@ -130,9 +129,8 @@ public interface MUCRoom extends ChatDeliverer {
* Obtain the roles of 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.
......@@ -146,9 +144,8 @@ public interface MUCRoom extends ChatDeliverer {
*
* @param nickname The nickname of the user you'd like to obtain
* @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.
......@@ -195,11 +192,9 @@ public interface MUCRoom extends ChatDeliverer {
* Remove a member from the chat room.
*
* @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.
*/
void leaveRoom(String nickname)
throws UnauthorizedException, UserNotFoundException;
void leaveRoom(String nickname) throws UserNotFoundException;
/**
* 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 {
*
* @param alternateJID the alternate JID. Commonly used to provide a replacement room.
* @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.
......@@ -226,7 +220,7 @@ public interface MUCRoom extends ChatDeliverer {
*
* @param msg The message to broadcast
*/
void serverBroadcast(String msg) throws UnauthorizedException;
void serverBroadcast(String msg);
/**
* Returns the total length of the chat session.
......
......@@ -14,7 +14,6 @@ package org.jivesoftware.messenger.muc;
import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.messenger.XMPPAddress;
import org.jivesoftware.messenger.ChannelHandler;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import java.util.Iterator;
......@@ -37,9 +36,8 @@ public interface MUCUser extends ChannelHandler {
* Obtain a user ID (useful for database indexing).
*
* @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
......@@ -56,19 +54,16 @@ public interface MUCUser extends ChannelHandler {
*
* @param roomName The name of the room we're interested in
* @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
*/
MUCRole getRole(String roomName)
throws UnauthorizedException, NotFoundException;
MUCRole getRole(String roomName) throws NotFoundException;
/**
* Get 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>
......
......@@ -118,7 +118,7 @@ public interface MultiUserChatServer {
* @param roomName Name of the room to get.
* @param userjid The user's normal jid, not the chat nickname jid.
* @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;
......@@ -150,27 +150,24 @@ public interface MultiUserChatServer {
* Removes the room associated with the given name.
*
* @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.
*
* @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.
*
* @param userjid The XMPPAddress of the user.
* @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.
*/
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
......
......@@ -189,13 +189,8 @@ public class IQMUCRegisterHandler extends IQHandler {
}
}
// Send the updated presences to the room occupants
try {
for (Presence presence : presences) {
room.send(presence);
}
}
catch (UnauthorizedException e) {
// Do nothing
for (Presence presence : presences) {
room.send(presence);
}
}
......
......@@ -223,17 +223,17 @@ public class MUCRoleImpl implements MUCRole {
return rJID;
}
public void send(Presence packet) throws UnauthorizedException {
public void send(Presence packet) {
packet.setRecipient(user.getAddress());
router.route(packet);
}
public void send(Message packet) throws UnauthorizedException {
public void send(Message packet) {
packet.setRecipient(user.getAddress());
router.route(packet);
}
public void send(IQ packet) throws UnauthorizedException {
public void send(IQ packet) {
packet.setRecipient(user.getAddress());
router.route(packet);
}
......@@ -242,7 +242,7 @@ public class MUCRoleImpl implements MUCRole {
* Calculates and sets the extended presence information to add to the presence. The information
* 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:affiliation", getAffiliationAsString());
extendedInformation.setProperty("x.item:role", getRoleAsString());
......
......@@ -195,9 +195,6 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
catch (NotAllowedException e) {
// 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
return getChatRoom(roomName) != null;
}
public void removeChatRoom(String roomName) throws UnauthorizedException {
public void removeChatRoom(String roomName) {
final MUCRoom room = rooms.remove(roomName.toLowerCase());
if (room != null) {
final long chatLength = room.getChatLength();
......@@ -309,7 +306,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
return historyStrategy;
}
public void removeUser(XMPPAddress jabberID) throws UnauthorizedException {
public void removeUser(XMPPAddress jabberID) {
MUCUser user = users.remove(jabberID);
if (user != null) {
Iterator<MUCRole> roles = user.getRoles();
......@@ -325,8 +322,7 @@ public class MultiUserChatServerImpl extends BasicModule implements MultiUserCha
}
}
public MUCUser getChatUser(XMPPAddress userjid) throws UnauthorizedException,
UserNotFoundException {
public MUCUser getChatUser(XMPPAddress userjid) throws UserNotFoundException {
if (router == null) {
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