Search in sources :

Example 6 with ConflictException

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);
}
Also used : ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) MUCRole(org.jivesoftware.openfire.muc.MUCRole) GroupJID(org.jivesoftware.openfire.group.GroupJID) JID(org.xmpp.packet.JID) ConflictException(org.jivesoftware.openfire.muc.ConflictException) AddAffiliation(org.jivesoftware.openfire.muc.cluster.AddAffiliation)

Example 7 with ConflictException

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();
    }
}
Also used : ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) MUCRole(org.jivesoftware.openfire.muc.MUCRole) GroupJID(org.jivesoftware.openfire.group.GroupJID) JID(org.xmpp.packet.JID) ConflictException(org.jivesoftware.openfire.muc.ConflictException) AddAffiliation(org.jivesoftware.openfire.muc.cluster.AddAffiliation)

Example 8 with ConflictException

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);
    }
}
Also used : ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) JID(org.xmpp.packet.JID) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) ConflictException(org.jivesoftware.openfire.muc.ConflictException) Presence(org.xmpp.packet.Presence)

Aggregations

ConflictException (org.jivesoftware.openfire.muc.ConflictException)8 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)7 JID (org.xmpp.packet.JID)7 GroupJID (org.jivesoftware.openfire.group.GroupJID)6 MUCRole (org.jivesoftware.openfire.muc.MUCRole)5 Presence (org.xmpp.packet.Presence)4 AddAffiliation (org.jivesoftware.openfire.muc.cluster.AddAffiliation)3 ArrayList (java.util.ArrayList)2 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)2 IOException (java.io.IOException)1 Date (java.util.Date)1 List (java.util.List)1 Element (org.dom4j.Element)1 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)1 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)1 CannotBeInvitedException (org.jivesoftware.openfire.muc.CannotBeInvitedException)1 NotAcceptableException (org.jivesoftware.openfire.muc.NotAcceptableException)1 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)1 RegistrationRequiredException (org.jivesoftware.openfire.muc.RegistrationRequiredException)1 RoomLockedException (org.jivesoftware.openfire.muc.RoomLockedException)1