use of org.jivesoftware.openfire.muc.ForbiddenException in project Openfire by igniterealtime.
the class MUCRoomController method deleteAffiliation.
/**
* Delete affiliation.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws ServiceException
* the service exception
*/
public void deleteAffiliation(String serviceName, String roomName, String jid) throws ServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(roomName.toLowerCase());
try {
JID userJid = UserUtils.checkAndGetJID(jid);
// Send a presence to other room members
List<Presence> addNonePresence = room.addNone(userJid, room.getRole());
for (Presence presence : addNonePresence) {
room.send(presence);
}
} catch (ForbiddenException e) {
throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
}
}
use of org.jivesoftware.openfire.muc.ForbiddenException in project Openfire by igniterealtime.
the class LocalMUCRoom method sendInvitation.
@Override
public void sendInvitation(JID to, String reason, MUCRole senderRole, List<Element> extensions) throws ForbiddenException, CannotBeInvitedException {
if (!isMembersOnly() || canOccupantsInvite() || MUCRole.Affiliation.admin == senderRole.getAffiliation() || MUCRole.Affiliation.owner == senderRole.getAffiliation()) {
// If the room is not members-only OR if the room is members-only and anyone can send
// invitations or the sender is an admin or an owner, then send the invitation
Message message = new Message();
message.setFrom(role.getRoleAddress());
message.setTo(to);
if (((MultiUserChatServiceImpl) mucService).getMUCDelegate() != null) {
switch(((MultiUserChatServiceImpl) mucService).getMUCDelegate().sendingInvitation(this, to, senderRole.getUserAddress(), reason)) {
case HANDLED_BY_DELEGATE:
//if the delegate is taking care of it, there's nothing for us to do
return;
case HANDLED_BY_OPENFIRE:
//continue as normal if we're asked to handle it
break;
case REJECTED:
//we can't invite that person
throw new CannotBeInvitedException();
}
}
// Add a list of extensions sent with the original message invitation (if any)
if (extensions != null) {
for (Element element : extensions) {
element.setParent(null);
message.getElement().add(element);
}
}
Element frag = message.addChildElement("x", "http://jabber.org/protocol/muc#user");
// ChatUser will be null if the room itself (ie. via admin console) made the request
if (senderRole.getUserAddress() != null) {
frag.addElement("invite").addAttribute("from", senderRole.getUserAddress().toBareJID());
}
if (reason != null && reason.length() > 0) {
Element invite = frag.element("invite");
if (invite == null) {
invite = frag.addElement("invite");
}
invite.addElement("reason").setText(reason);
}
if (isPasswordProtected()) {
frag.addElement("password").setText(getPassword());
}
// Include the jabber:x:conference information for backward compatibility
frag = message.addChildElement("x", "jabber:x:conference");
frag.addAttribute("jid", role.getRoleAddress().toBareJID());
// Send the message with the invitation
router.route(message);
} else {
throw new ForbiddenException();
}
}
use of org.jivesoftware.openfire.muc.ForbiddenException in project Openfire by igniterealtime.
the class LocalMUCRoom method addOutcast.
@Override
public List<Presence> addOutcast(JID jid, String reason, MUCRole senderRole) throws NotAllowedException, ForbiddenException, ConflictException {
final JID bareJID = jid.asBareJID();
lock.writeLock().lock();
try {
MUCRole.Affiliation oldAffiliation = MUCRole.Affiliation.none;
if (MUCRole.Affiliation.admin != senderRole.getAffiliation() && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
// Check that the room always has an owner
if (owners.contains(bareJID) && owners.size() == 1) {
throw new ConflictException();
}
// Check if user is already an outcast
if (outcasts.contains(bareJID)) {
// Do nothing
return Collections.emptyList();
}
// Update the affiliation lists
outcasts.add(bareJID);
// Remove the user from other affiliation lists
if (removeOwner(bareJID)) {
oldAffiliation = MUCRole.Affiliation.owner;
} else if (removeAdmin(bareJID)) {
oldAffiliation = MUCRole.Affiliation.admin;
} else if (removeMember(bareJID)) {
oldAffiliation = MUCRole.Affiliation.member;
}
// Update the DB if the room is persistent
MUCPersistenceManager.saveAffiliationToDB(this, bareJID, null, MUCRole.Affiliation.outcast, oldAffiliation);
} finally {
lock.writeLock().unlock();
}
// Update other cluster nodes with new affiliation
CacheFactory.doClusterTask(new AddAffiliation(this, jid.toBareJID(), MUCRole.Affiliation.outcast));
// based on the group(s) of the affected user(s)
return applyAffiliationChange(senderRole, bareJID, reason);
}
use of org.jivesoftware.openfire.muc.ForbiddenException in project Openfire by igniterealtime.
the class LocalMUCRoom method changeSubject.
@Override
public void changeSubject(Message packet, MUCRole role) throws ForbiddenException {
if ((canOccupantsChangeSubject() && role.getRole().compareTo(MUCRole.Role.visitor) < 0) || MUCRole.Role.moderator == role.getRole()) {
// Set the new subject to the room
subject = packet.getSubject();
MUCPersistenceManager.updateRoomSubject(this);
// Notify all the occupants that the subject has changed
packet.setFrom(role.getRoleAddress());
send(packet);
// Fire event signifying that the room's subject has changed.
MUCEventDispatcher.roomSubjectChanged(getJID(), role.getUserAddress(), subject);
// Let other cluster nodes that the room has been updated
CacheFactory.doClusterTask(new RoomUpdatedEvent(this));
} else {
throw new ForbiddenException();
}
}
use of org.jivesoftware.openfire.muc.ForbiddenException in project Openfire by igniterealtime.
the class LocalMUCRoom method sendPrivatePacket.
@Override
public void sendPrivatePacket(Packet packet, MUCRole senderRole) throws NotFoundException, ForbiddenException {
switch(// intended fall-through
senderRole.getRole()) {
case none:
throw new ForbiddenException();
default:
case visitor:
if (canSendPrivateMessage().equals("participants"))
throw new ForbiddenException();
case participant:
if (canSendPrivateMessage().equals("moderators"))
throw new ForbiddenException();
case moderator:
if (canSendPrivateMessage().equals("none"))
throw new ForbiddenException();
}
String resource = packet.getTo().getResource();
List<MUCRole> occupants = occupantsByNickname.get(resource.toLowerCase());
if (occupants == null || occupants.size() == 0) {
throw new NotFoundException();
}
for (MUCRole occupant : occupants) {
packet.setFrom(senderRole.getRoleAddress());
occupant.send(packet);
if (packet instanceof Message) {
Message message = (Message) packet;
MUCEventDispatcher.privateMessageRecieved(occupant.getUserAddress(), senderRole.getUserAddress(), message);
}
}
}
Aggregations