use of org.jivesoftware.openfire.muc.cluster.AddAffiliation in project Openfire by igniterealtime.
the class LocalMUCRoom method addOwner.
@Override
public List<Presence> addOwner(JID jid, MUCRole sendRole) throws ForbiddenException {
final JID bareJID = jid.asBareJID();
lock.writeLock().lock();
try {
MUCRole.Affiliation oldAffiliation = MUCRole.Affiliation.none;
if (MUCRole.Affiliation.owner != sendRole.getAffiliation()) {
throw new ForbiddenException();
}
// Check if user is already an owner (explicitly)
if (owners.contains(bareJID)) {
// Do nothing
return Collections.emptyList();
}
owners.add(bareJID);
// Remove the user from other affiliation lists
if (removeAdmin(bareJID)) {
oldAffiliation = MUCRole.Affiliation.admin;
} else if (removeMember(bareJID)) {
oldAffiliation = MUCRole.Affiliation.member;
} else if (removeOutcast(bareJID)) {
oldAffiliation = MUCRole.Affiliation.outcast;
}
// Update the DB if the room is persistent
MUCPersistenceManager.saveAffiliationToDB(this, bareJID, null, MUCRole.Affiliation.owner, oldAffiliation);
} finally {
lock.writeLock().unlock();
}
// Update other cluster nodes with new affiliation
CacheFactory.doClusterTask(new AddAffiliation(this, jid.toBareJID(), MUCRole.Affiliation.owner));
// based on the group(s) of the affected user(s)
return applyAffiliationChange(getRole(), bareJID, null);
}
use of org.jivesoftware.openfire.muc.cluster.AddAffiliation in project Openfire by igniterealtime.
the class LocalMUCRoom method addAdmin.
@Override
public List<Presence> addAdmin(JID jid, MUCRole sendRole) throws ForbiddenException, ConflictException {
final JID bareJID = jid.asBareJID();
lock.writeLock().lock();
try {
MUCRole.Affiliation oldAffiliation = MUCRole.Affiliation.none;
if (MUCRole.Affiliation.owner != sendRole.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 admin
if (admins.contains(bareJID)) {
// Do nothing
return Collections.emptyList();
}
admins.add(bareJID);
// Remove the user from other affiliation lists
if (removeOwner(bareJID)) {
oldAffiliation = MUCRole.Affiliation.owner;
} else if (removeMember(bareJID)) {
oldAffiliation = MUCRole.Affiliation.member;
} else if (removeOutcast(bareJID)) {
oldAffiliation = MUCRole.Affiliation.outcast;
}
// Update the DB if the room is persistent
MUCPersistenceManager.saveAffiliationToDB(this, bareJID, null, MUCRole.Affiliation.admin, oldAffiliation);
} finally {
lock.writeLock().unlock();
}
// Update other cluster nodes with new affiliation
CacheFactory.doClusterTask(new AddAffiliation(this, jid.toBareJID(), MUCRole.Affiliation.admin));
// based on the group(s) of the affected user(s)
return applyAffiliationChange(getRole(), bareJID, null);
}
use of org.jivesoftware.openfire.muc.cluster.AddAffiliation 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.cluster.AddAffiliation 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();
}
}
Aggregations