Commit f0985778 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@490 b35dd754-fafc-0310-a699-88a17e54d16e
parent 6f510e51
......@@ -14,7 +14,6 @@ package org.jivesoftware.messenger.muc;
import org.jivesoftware.messenger.MetaDataFragment;
import org.jivesoftware.messenger.Presence;
import org.jivesoftware.messenger.XMPPAddress;
import org.jivesoftware.messenger.auth.UnauthorizedException;
/**
* Defines the permissions and actions that a MUCUser may use in
......@@ -73,10 +72,8 @@ public interface MUCRole extends ChatDeliverer {
* Obtain the current presence status of a user in a chatroom.
*
* @return The presence of the user in the room.
* @throws UnauthorizedException Thrown if the caller doesn't have permission to know this
* user's presence.
*/
Presence getPresence() throws UnauthorizedException;
Presence getPresence();
/**
* Returns the extended presence information that includes information about roles,
......@@ -84,19 +81,15 @@ public interface MUCRole extends ChatDeliverer {
*
* @return the extended presence information that includes information about roles,
* affiliations.
* @throws UnauthorizedException Thrown if the caller doesn't have permission to know this
* user's presence.
*/
MetaDataFragment getExtendedPresenceInformation() throws UnauthorizedException;
MetaDataFragment getExtendedPresenceInformation();
/**
* Set the current presence status of a user in a chatroom.
*
* @param presence The presence of the user in the room.
* @throws UnauthorizedException Thrown if the caller doesn't have permission to know this
* user's presence.
*/
void setPresence(Presence presence) throws UnauthorizedException;
void setPresence(Presence presence);
/**
* Call this method to promote or demote a user's role in a chatroom.
......@@ -107,12 +100,10 @@ public interface MUCRole extends ChatDeliverer {
* Owning ChatUsers should have their membership roles updated.
*
* @param newRole The new role that the user will play.
* @throws UnauthorizedException Thrown if the caller doesn't have permission to know this
* user's presence.
* @throws NotAllowedException Thrown if trying to change the moderator role to an owner or
* administrator.
*/
void setRole(int newRole) throws UnauthorizedException, NotAllowedException;
void setRole(int newRole) throws NotAllowedException;
/**
* Obtain the role state of the user.
......@@ -133,12 +124,9 @@ public interface MUCRole extends ChatDeliverer {
* Call this method to promote or demote a user's affiliation in a chatroom.
*
* @param newAffiliation The new affiliation that the user will play.
* @throws UnauthorizedException Thrown if the caller doesn't have permission to set the
* user's affiliation.
* @throws NotAllowedException Thrown if trying to ban an owner or an administrator.
*/
public void setAffiliation(int newAffiliation) throws UnauthorizedException,
NotAllowedException;
public void setAffiliation(int newAffiliation) throws NotAllowedException;
/**
* Obtain the affiliation state of the user.
......@@ -166,11 +154,8 @@ public interface MUCRole extends ChatDeliverer {
* An event callback for kicks (being removed from a room). This provides the user an
* opportunity to react to the kick (although the chat user has already been kicked when this
* method is called). Remove users from a chatroom by calling ChatRoom.leaveRoom().
*
* @throws UnauthorizedException Thrown if the caller doesn't have permission to know this
* user's presence.
*/
void kick() throws UnauthorizedException;
void kick();
/**
* Changes the nickname of the occupant within the room to the new nickname.
......
......@@ -19,6 +19,8 @@ import org.jivesoftware.messenger.PacketRouter;
import org.jivesoftware.messenger.Presence;
import org.jivesoftware.messenger.XMPPAddress;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.LocaleUtils;
/**
* Simple in-memory implementation of a role in a chatroom
......@@ -111,22 +113,22 @@ public class MUCRoleImpl implements MUCRole {
setPresence(room.createPresence(Presence.STATUS_ONLINE));
}
public Presence getPresence() throws UnauthorizedException {
public Presence getPresence() {
return presence;
}
public MetaDataFragment getExtendedPresenceInformation() throws UnauthorizedException {
public MetaDataFragment getExtendedPresenceInformation() {
return extendedInformation;
}
public void setPresence(Presence newPresence) throws UnauthorizedException {
public void setPresence(Presence newPresence) {
this.presence = newPresence;
if (extendedInformation != null) {
presence.addFragment(extendedInformation);
}
}
public void setRole(int newRole) throws UnauthorizedException, NotAllowedException {
public void setRole(int newRole) throws NotAllowedException {
// Don't allow to change the role to an owner or admin unless the new role is moderator
if (MUCRole.OWNER == affiliation || MUCRole.ADMINISTRATOR == affiliation) {
if (MUCRole.MODERATOR != newRole) {
......@@ -142,8 +144,13 @@ public class MUCRoleImpl implements MUCRole {
role = newRole;
if (MUCRole.NONE_ROLE == role) {
presence.setAvailable(false);
presence.setVisible(false);
try {
presence.setAvailable(false);
presence.setVisible(false);
}
catch (UnauthorizedException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
calculateExtendedInformation();
}
......@@ -165,8 +172,7 @@ public class MUCRoleImpl implements MUCRole {
return "none";
}
public void setAffiliation(int newAffiliation) throws UnauthorizedException,
NotAllowedException {
public void setAffiliation(int newAffiliation) throws NotAllowedException {
// Don't allow to ban an owner or an admin
if (MUCRole.OWNER == affiliation || MUCRole.ADMINISTRATOR == affiliation) {
if (MUCRole.OUTCAST == newAffiliation) {
......@@ -202,7 +208,7 @@ public class MUCRoleImpl implements MUCRole {
return nick;
}
public void kick() throws UnauthorizedException {
public void kick() {
getChatUser().removeRole(room.getName());
}
......
......@@ -831,18 +831,18 @@ public class MUCRoomImpl implements MUCRoom {
this.room = room;
}
public Presence getPresence() throws UnauthorizedException {
public Presence getPresence() {
return null;
}
public MetaDataFragment getExtendedPresenceInformation() throws UnauthorizedException {
public MetaDataFragment getExtendedPresenceInformation() {
return null;
}
public void setPresence(Presence presence) throws UnauthorizedException {
public void setPresence(Presence presence) {
}
public void setRole(int newRole) throws UnauthorizedException {
public void setRole(int newRole) {
}
public int getRole() {
......@@ -853,7 +853,7 @@ public class MUCRoomImpl implements MUCRoom {
return "moderator";
}
public void setAffiliation(int newAffiliation) throws UnauthorizedException {
public void setAffiliation(int newAffiliation) {
}
public int getAffiliation() {
......@@ -868,7 +868,7 @@ public class MUCRoomImpl implements MUCRoom {
return null;
}
public void kick() throws UnauthorizedException {
public void kick() {
}
public MUCUser getChatUser() {
......@@ -932,19 +932,14 @@ public class MUCRoomImpl implements MUCRoom {
MUCRole role;
// Collect all the updated presences of these roles
for (Iterator it = roles.iterator(); it.hasNext();) {
try {
role = (MUCRole) it.next();
// Update the presence with the new affiliation and role
role.setAffiliation(newAffiliation);
role.setRole(newRole);
// Prepare a new presence to be sent to all the room occupants
Presence presence = (Presence) role.getPresence().createDeepCopy();
presence.setSender(role.getRoleAddress());
presences.add(presence);
}
catch (UnauthorizedException e) {
// Do nothing
}
role = (MUCRole) it.next();
// Update the presence with the new affiliation and role
role.setAffiliation(newAffiliation);
role.setRole(newRole);
// Prepare a new presence to be sent to all the room occupants
Presence presence = (Presence) role.getPresence().createDeepCopy();
presence.setSender(role.getRoleAddress());
presences.add(presence);
}
// Answer all the updated presences
return presences;
......@@ -963,17 +958,12 @@ public class MUCRoomImpl implements MUCRoom {
// Try looking the role in the bare JID list
MUCRole role = occupantsByFullJID.get(fullJID);
if (role != null) {
try {
// Update the presence with the new role
role.setRole(newRole);
// Prepare a new presence to be sent to all the room occupants
Presence presence = (Presence) role.getPresence().createDeepCopy();
presence.setSender(role.getRoleAddress());
return presence;
}
catch (UnauthorizedException e) {
// Do nothing
}
// Update the presence with the new role
role.setRole(newRole);
// Prepare a new presence to be sent to all the room occupants
Presence presence = (Presence) role.getPresence().createDeepCopy();
presence.setSender(role.getRoleAddress());
return presence;
}
return null;
}
......@@ -1516,12 +1506,7 @@ public class MUCRoomImpl implements MUCRoom {
kickedRole.send(kickPresence);
// Remove the occupant from the room's occupants lists
removeOccupantRole(kickedRole);
try {
kickedRole.kick();
}
catch (UnauthorizedException e) {
// Do nothing
}
kickedRole.kick();
}
}
......
......@@ -311,9 +311,6 @@ public class MUCUserImpl implements MUCUser {
sendErrorPacket(packet, XMPPError.Code.BAD_REQUEST);
}
}
catch (UnauthorizedException e) {
sendErrorPacket(packet, XMPPError.Code.UNAUTHORIZED);
}
catch (ForbiddenException e) {
sendErrorPacket(packet, XMPPError.Code.FORBIDDEN);
}
......
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