Search in sources :

Example 6 with ForbiddenException

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);
    }
}
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)

Example 7 with ForbiddenException

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();
    }
}
Also used : CannotBeInvitedException(org.jivesoftware.openfire.muc.CannotBeInvitedException) ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) Message(org.xmpp.packet.Message) Element(org.dom4j.Element)

Example 8 with 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);
}
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 9 with ForbiddenException

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();
    }
}
Also used : ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) RoomUpdatedEvent(org.jivesoftware.openfire.muc.cluster.RoomUpdatedEvent)

Example 10 with 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);
        }
    }
}
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)

Aggregations

ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)14 ConflictException (org.jivesoftware.openfire.muc.ConflictException)10 MUCRole (org.jivesoftware.openfire.muc.MUCRole)8 JID (org.xmpp.packet.JID)8 GroupJID (org.jivesoftware.openfire.group.GroupJID)7 Element (org.dom4j.Element)5 CannotBeInvitedException (org.jivesoftware.openfire.muc.CannotBeInvitedException)4 AddAffiliation (org.jivesoftware.openfire.muc.cluster.AddAffiliation)4 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 NotAcceptableException (org.jivesoftware.openfire.muc.NotAcceptableException)3 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)3 RegistrationRequiredException (org.jivesoftware.openfire.muc.RegistrationRequiredException)3 RoomLockedException (org.jivesoftware.openfire.muc.RoomLockedException)3 ServiceUnavailableException (org.jivesoftware.openfire.muc.ServiceUnavailableException)3 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)3 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)3 NotFoundException (org.jivesoftware.util.NotFoundException)3 Message (org.xmpp.packet.Message)3 Presence (org.xmpp.packet.Presence)3 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)2