Search in sources :

Example 21 with MUCRole

use of org.jivesoftware.openfire.muc.MUCRole 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 22 with MUCRole

use of org.jivesoftware.openfire.muc.MUCRole 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);
        }
    }
}
Also used : ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) MUCRole(org.jivesoftware.openfire.muc.MUCRole) Message(org.xmpp.packet.Message) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 23 with MUCRole

use of org.jivesoftware.openfire.muc.MUCRole in project Openfire by igniterealtime.

the class LocalMUCRoom method destroyRoom.

public void destroyRoom(DestroyRoomRequest destroyRequest) {
    JID alternateJID = destroyRequest.getAlternateJID();
    String reason = destroyRequest.getReason();
    Collection<MUCRole> removedRoles = new ArrayList<>();
    lock.writeLock().lock();
    try {
        boolean hasRemoteOccupants = false;
        // Remove each occupant
        for (MUCRole leaveRole : occupantsByFullJID.values()) {
            if (leaveRole != null) {
                // list of removed occupants to process later outside of the lock.
                if (leaveRole.isLocal()) {
                    removedRoles.add(leaveRole);
                } else {
                    hasRemoteOccupants = true;
                }
                removeOccupantRole(leaveRole, destroyRequest.isOriginator());
            }
        }
        endTime = System.currentTimeMillis();
        // Set that the room has been destroyed
        isDestroyed = true;
        if (destroyRequest.isOriginator()) {
            if (hasRemoteOccupants) {
                // Ask other cluster nodes to remove occupants since room is being destroyed
                CacheFactory.doClusterTask(new DestroyRoomRequest(this, alternateJID, reason));
            }
            // Removes the room from the list of rooms hosted in the service
            mucService.removeChatRoom(name);
        }
    } finally {
        lock.writeLock().unlock();
    }
    // Send an unavailable presence to each removed occupant
    for (MUCRole removedRole : removedRoles) {
        try {
            // Send a presence stanza of type "unavailable" to the occupant
            Presence presence = createPresence(Presence.Type.unavailable);
            presence.setFrom(removedRole.getRoleAddress());
            // A fragment containing the x-extension for room destruction.
            Element fragment = presence.addChildElement("x", "http://jabber.org/protocol/muc#user");
            Element item = fragment.addElement("item");
            item.addAttribute("affiliation", "none");
            item.addAttribute("role", "none");
            if (alternateJID != null) {
                fragment.addElement("destroy").addAttribute("jid", alternateJID.toString());
            }
            if (reason != null && reason.length() > 0) {
                Element destroy = fragment.element("destroy");
                if (destroy == null) {
                    destroy = fragment.addElement("destroy");
                }
                destroy.addElement("reason").setText(reason);
            }
            removedRole.send(presence);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
    if (destroyRequest.isOriginator()) {
        // Remove the room from the DB if the room was persistent
        MUCPersistenceManager.deleteFromDB(this);
        // Fire event that the room has been destroyed
        MUCEventDispatcher.roomDestroyed(getRole().getRoleAddress());
    }
}
Also used : MUCRole(org.jivesoftware.openfire.muc.MUCRole) GroupJID(org.jivesoftware.openfire.group.GroupJID) JID(org.xmpp.packet.JID) DestroyRoomRequest(org.jivesoftware.openfire.muc.cluster.DestroyRoomRequest) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Presence(org.xmpp.packet.Presence) UpdatePresence(org.jivesoftware.openfire.muc.cluster.UpdatePresence) ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) RoomLockedException(org.jivesoftware.openfire.muc.RoomLockedException) CannotBeInvitedException(org.jivesoftware.openfire.muc.CannotBeInvitedException) NotAllowedException(org.jivesoftware.openfire.muc.NotAllowedException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) NotFoundException(org.jivesoftware.util.NotFoundException) ConflictException(org.jivesoftware.openfire.muc.ConflictException) RegistrationRequiredException(org.jivesoftware.openfire.muc.RegistrationRequiredException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) IOException(java.io.IOException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) NotAcceptableException(org.jivesoftware.openfire.muc.NotAcceptableException) ServiceUnavailableException(org.jivesoftware.openfire.muc.ServiceUnavailableException)

Example 24 with MUCRole

use of org.jivesoftware.openfire.muc.MUCRole in project Openfire by igniterealtime.

the class LocalMUCRoom method nicknameChanged.

public void nicknameChanged(ChangeNickname changeNickname) {
    List<MUCRole> occupants = occupantsByNickname.get(changeNickname.getOldNick().toLowerCase());
    if (occupants != null && occupants.size() > 0) {
        for (MUCRole occupant : occupants) {
            // Update the role with the new info
            occupant.setPresence(changeNickname.getPresence());
            occupant.changeNickname(changeNickname.getNewNick());
        }
        if (changeNickname.isOriginator()) {
            // Fire event that user changed his nickname
            MUCEventDispatcher.nicknameChanged(getRole().getRoleAddress(), occupants.get(0).getUserAddress(), changeNickname.getOldNick(), changeNickname.getNewNick());
        }
        // Associate the existing MUCRole with the new nickname
        occupantsByNickname.put(changeNickname.getNewNick().toLowerCase(), occupants);
        // Remove the old nickname
        occupantsByNickname.remove(changeNickname.getOldNick().toLowerCase());
    }
}
Also used : MUCRole(org.jivesoftware.openfire.muc.MUCRole)

Example 25 with MUCRole

use of org.jivesoftware.openfire.muc.MUCRole 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)

Aggregations

MUCRole (org.jivesoftware.openfire.muc.MUCRole)31 GroupJID (org.jivesoftware.openfire.group.GroupJID)15 JID (org.xmpp.packet.JID)14 ArrayList (java.util.ArrayList)10 Presence (org.xmpp.packet.Presence)10 Element (org.dom4j.Element)9 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)9 UpdatePresence (org.jivesoftware.openfire.muc.cluster.UpdatePresence)9 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)8 ConflictException (org.jivesoftware.openfire.muc.ConflictException)6 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)6 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)5 AddAffiliation (org.jivesoftware.openfire.muc.cluster.AddAffiliation)4 UpdateOccupant (org.jivesoftware.openfire.muc.cluster.UpdateOccupant)3 NotFoundException (org.jivesoftware.util.NotFoundException)3 Message (org.xmpp.packet.Message)3 IOException (java.io.IOException)2 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)2 Group (org.jivesoftware.openfire.group.Group)2 CannotBeInvitedException (org.jivesoftware.openfire.muc.CannotBeInvitedException)2