use of org.jivesoftware.openfire.muc.ConflictException 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.ConflictException in project Openfire by igniterealtime.
the class LocalMUCRoom method addNone.
@Override
public List<Presence> addNone(JID jid, MUCRole senderRole) throws ForbiddenException, ConflictException {
final JID bareJID = jid.asBareJID();
MUCRole.Affiliation oldAffiliation = MUCRole.Affiliation.none;
boolean jidWasAffiliated = false;
lock.writeLock().lock();
try {
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();
}
// Remove the jid from ALL the affiliation lists
if (removeOwner(bareJID)) {
oldAffiliation = MUCRole.Affiliation.owner;
jidWasAffiliated = true;
} else if (removeAdmin(bareJID)) {
oldAffiliation = MUCRole.Affiliation.admin;
jidWasAffiliated = true;
} else if (removeMember(bareJID)) {
oldAffiliation = MUCRole.Affiliation.member;
jidWasAffiliated = true;
} else if (removeOutcast(bareJID)) {
oldAffiliation = MUCRole.Affiliation.outcast;
}
// Remove the affiliation of this user from the DB if the room is persistent
MUCPersistenceManager.removeAffiliationFromDB(this, bareJID, oldAffiliation);
} finally {
lock.writeLock().unlock();
}
// Update other cluster nodes with new affiliation
CacheFactory.doClusterTask(new AddAffiliation(this, jid.toBareJID(), MUCRole.Affiliation.none));
if (jidWasAffiliated) {
// based on the group(s) of the affected user(s)
return applyAffiliationChange(senderRole, bareJID, null);
} else {
// no presence updates needed
return Collections.emptyList();
}
}
use of org.jivesoftware.openfire.muc.ConflictException 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);
}
}
Aggregations