public UpdateOccupant(LocalMUCRoom room, MUCRole role) { super(room); this.presence = role.getPresence(); this.nickname = role.getNickname(); this.role = role.getRole().ordinal(); this.affiliation = role.getAffiliation().ordinal(); }
public void inviteOccupant( String subdomain, String roomName, String memberJid, String password, String reason) throws Exception { MultiUserChatService service = this.multiUserChatManager.getMultiUserChatService(subdomain); if (service == null) { throw new NotFoundException("MUC service not found for " + subdomain); } MUCRoom mucRoom = service.getChatRoom(roomName); if (mucRoom == null) { throw new NotFoundException("Room not found for " + subdomain + " roomName " + roomName); } String roomPassword = mucRoom.getPassword(); if (password == null && roomPassword != null) { throw new NotAllowedException("Password mismatch"); } if (mucRoom.getPassword() != null && !mucRoom.getPassword().equals(password)) { throw new NotAllowedException("Password mismatch"); } String ownerJid = mucRoom.getOwners().iterator().next(); if (!mucRoom.getOccupants().contains(new JID(ownerJid))) { throw new NotAllowedException("Owner is not in te room -- cannot invite"); } List<MUCRole> roles = mucRoom.getOccupantsByBareJID(ownerJid); JID memberJID = new JID(memberJid); for (MUCRole role : roles) { if (role.getAffiliation() == Affiliation.owner) { mucRoom.sendInvitation(memberJID, reason, role, null); break; } } }
/** * Handles the IQ packet sent by an owner of the room. Possible actions are: * * <ul> * <li>Return the list of owners * <li>Return the list of admins * <li>Change user's affiliation to owner * <li>Change user's affiliation to admin * <li>Change user's affiliation to member * <li>Change user's affiliation to none * <li>Destroy the room * <li>Return the room configuration within a dataform * <li>Update the room configuration based on the sent dataform * </ul> * * @param packet the IQ packet sent by an owner of the room. * @param role the role of the user that sent the packet. * @throws ForbiddenException if the user does not have enough permissions (ie. is not an owner). * @throws ConflictException If the room was going to lose all of its owners. */ @SuppressWarnings("unchecked") public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, ConflictException, CannotBeInvitedException { // Only owners can send packets with the namespace "http://jabber.org/protocol/muc#owner" if (MUCRole.Affiliation.owner != role.getAffiliation()) { throw new ForbiddenException(); } IQ reply = IQ.createResultIQ(packet); Element element = packet.getChildElement(); // Analyze the action to perform based on the included element Element formElement = element.element(QName.get("x", "jabber:x:data")); if (formElement != null) { handleDataFormElement(role, formElement); } else { Element destroyElement = element.element("destroy"); if (destroyElement != null) { if (((MultiUserChatServiceImpl) room.getMUCService()).getMUCDelegate() != null) { if (!((MultiUserChatServiceImpl) room.getMUCService()) .getMUCDelegate() .destroyingRoom(room.getName(), role.getUserAddress())) { // Delegate said no, reject destroy request. throw new ForbiddenException(); } } JID alternateJID = null; final String jid = destroyElement.attributeValue("jid"); if (jid != null) { alternateJID = new JID(jid); } room.destroyRoom(alternateJID, destroyElement.elementTextTrim("reason")); } else { // If no element was included in the query element then answer the // configuration form if (!element.elementIterator().hasNext()) { refreshConfigurationFormValues(); reply.setChildElement(probeResult.createCopy()); } // An unknown and possibly incorrect element was included in the query // element so answer a BAD_REQUEST error else { reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.bad_request); } } } if (reply.getTo() != null) { // Send a reply only if the sender of the original packet was from a real JID. (i.e. not // a packet generated locally) router.route(reply); } }