示例#1
0
  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;
      }
    }
  }
示例#2
0
 public void setMucRoomAttributes(String domain, String roomName, Map newAttributes)
     throws NotFoundException {
   MultiUserChatService mucService = this.multiUserChatManager.getMultiUserChatService(domain);
   MUCRoom mucRoom = mucService.getChatRoom(roomName);
   if (mucRoom == null) {
     throw new NotFoundException("Room not found " + domain + " roomName " + roomName);
   }
   Map<String, String> attribs = (Map<String, String>) newAttributes;
   boolean isModerated = Boolean.parseBoolean(attribs.get("isModerated"));
   mucRoom.setModerated(isModerated);
   boolean isLogEnabled = Boolean.parseBoolean(attribs.get("isLogEnabled"));
   mucRoom.setLogEnabled(isLogEnabled);
   boolean isMembersOnly = Boolean.parseBoolean(attribs.get("isMembersOnly"));
   mucRoom.setMembersOnly(isMembersOnly);
   boolean isPublicRoom = Boolean.parseBoolean(attribs.get("isPublicRoom"));
   mucRoom.setPublicRoom(isPublicRoom);
   boolean isLoginRestrictedToNickName =
       Boolean.parseBoolean(attribs.get("isLoginRestrictedToNickName"));
   mucRoom.setLoginRestrictedToNickname(isLoginRestrictedToNickName);
   boolean isRegistrationEnabled = Boolean.parseBoolean(attribs.get("isRegistrationEnabled"));
   mucRoom.setRegistrationEnabled(isRegistrationEnabled);
   boolean canAnyoneDiscoverJID = Boolean.parseBoolean(attribs.get("canAnyoneDiscoverJID"));
   mucRoom.setCanAnyoneDiscoverJID(canAnyoneDiscoverJID);
   boolean canChangeNickName = Boolean.parseBoolean(attribs.get("canChangeNickName"));
   mucRoom.setChangeNickname(canChangeNickName);
   boolean canOccupantsInvite = Boolean.parseBoolean(attribs.get("canOccupantsInvite"));
   mucRoom.setCanOccupantsInvite(canOccupantsInvite);
   boolean canOccupantsChangeSubject =
       Boolean.parseBoolean(attribs.get("canOccupantsChangeSubject"));
   mucRoom.setCanOccupantsChangeSubject(canOccupantsChangeSubject);
 }
示例#3
0
 public Collection<MUCRoom> getMUCRooms() {
   HashSet<MUCRoom> retval = new HashSet<MUCRoom>();
   for (MultiUserChatService mucService : this.multiUserChatManager.getMultiUserChatServices()) {
     List<MUCRoom> chatRooms = mucService.getChatRooms();
     retval.addAll(chatRooms);
   }
   return retval;
 }
示例#4
0
 public String getConferenceExtension(String domain, String roomName) throws NotFoundException {
   MultiUserChatService mucService = this.multiUserChatManager.getMultiUserChatService(domain);
   MUCRoom mucRoom = mucService.getChatRoom(roomName);
   if (mucRoom == null) {
     throw new NotFoundException("Room not found " + domain + " roomName " + roomName);
   }
   return this.roomNameToConferenceExtensionMap.get(domain + "." + roomName);
 }
示例#5
0
 /**
  * Get all the members of a chat room.
  *
  * @param domain
  * @param roomName
  * @return
  */
 public Collection<String> getMembers(String domain, String roomName) throws NotFoundException {
   MultiUserChatService mucService = this.multiUserChatManager.getMultiUserChatService(domain);
   if (mucService == null) {
     throw new NotFoundException("Service not found for domain " + domain);
   }
   MUCRoom mucRoom = mucService.getChatRoom(roomName);
   if (mucRoom == null) {
     throw new NotFoundException("Room not found " + domain + " roomName " + roomName);
   }
   return mucRoom.getMembers();
 }
示例#6
0
  public void pruneChatServices(Collection<String> subdomains) throws Exception {

    HashSet<MultiUserChatService> pruneSet = new HashSet<MultiUserChatService>();
    pruneSet.addAll(this.multiUserChatManager.getMultiUserChatServices());

    for (MultiUserChatService service : pruneSet) {
      String subdomain = service.getServiceDomain().split("\\.")[0];
      if (!subdomains.contains(subdomain)) {
        this.multiUserChatManager.removeMultiUserChatService(subdomain);
      }
    }
  }
示例#7
0
 public LocalMUCRoom getRoom() {
   MultiUserChatService mucService =
       XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(subdomain);
   if (mucService == null) {
     throw new IllegalArgumentException("MUC service not found for subdomain: " + subdomain);
   }
   LocalMUCRoom room = (LocalMUCRoom) mucService.getChatRoom(roomName);
   if (room == null) {
     throw new IllegalArgumentException("Room not found: " + roomName);
   }
   return room;
 }
示例#8
0
  public void createChatRoom(
      String domain,
      String ownerJid,
      String roomName,
      boolean listRoomInDirectory,
      boolean makeRoomModerated,
      boolean makeRoomMembersOnly,
      boolean allowOccupantsToInviteOthers,
      boolean isPublicRoom,
      boolean logRoomConversations,
      boolean isPersistent,
      String password,
      String description,
      String conferenceExtension)
      throws Exception {
    MultiUserChatService mucService =
        XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(domain);
    if (mucService == null) {
      mucService =
          XMPPServer.getInstance()
              .getMultiUserChatManager()
              .createMultiUserChatService(domain, description, false);
      Collection<JID> admins = XMPPServer.getInstance().getAdmins();
      JID admin = admins.iterator().next();
      mucService.addUserAllowedToCreate(admin.toBareJID());
    }
    MUCRoom mucRoom = mucService.getChatRoom(roomName, new JID(ownerJid));

    mucRoom.setPersistent(isPersistent);
    mucRoom.setCanAnyoneDiscoverJID(true);
    mucRoom.setChangeNickname(true);
    mucRoom.setModerated(makeRoomModerated);
    mucRoom.setMembersOnly(makeRoomMembersOnly);
    mucRoom.setRegistrationEnabled(true);
    mucRoom.setPublicRoom(isPublicRoom);
    mucRoom.setCanAnyoneDiscoverJID(true);
    mucRoom.setCanOccupantsInvite(allowOccupantsToInviteOthers);
    mucRoom.setDescription(description);
    mucRoom.setPassword(password);
    mucRoom.setCanOccupantsChangeSubject(true);
    mucRoom.setChangeNickname(true);
    mucRoom.setLogEnabled(logRoomConversations);

    mucRoom.setDescription(description);

    mucRoom.setPassword(password);
    /* The conference extension is the voice conf bridge extension */
    this.roomNameToConferenceExtensionMap.put(domain + "." + roomName, conferenceExtension);
  }
  /**
   * Create a new role.
   *
   * @param chatserver the server hosting the role.
   * @param chatroom the room the role is valid in.
   * @param nickname the nickname of the user in the role.
   * @param role the role of the user in the room.
   * @param affiliation the affiliation of the user in the room.
   * @param chatuser the user on the chat server.
   * @param presence the presence sent by the user to join the room.
   * @param packetRouter the packet router for sending messages from this role.
   */
  public LocalMUCRole(
      MultiUserChatService chatserver,
      LocalMUCRoom chatroom,
      String nickname,
      MUCRole.Role role,
      MUCRole.Affiliation affiliation,
      LocalMUCUser chatuser,
      Presence presence,
      PacketRouter packetRouter) {
    this.room = chatroom;
    this.nick = nickname;
    this.user = chatuser;
    this.server = chatserver;
    this.router = packetRouter;
    this.role = role;
    this.affiliation = affiliation;
    // Cache the user's session (will only work for local users)
    this.session = XMPPServer.getInstance().getSessionManager().getSession(presence.getFrom());

    extendedInformation =
        DocumentHelper.createElement(QName.get("x", "http://jabber.org/protocol/muc#user"));
    calculateExtendedInformation();
    rJID = new JID(room.getName(), server.getServiceDomain(), nick);
    setPresence(presence);
    // Check if new occupant wants to be a deaf occupant
    Element element =
        presence.getElement().element(QName.get("x", "http://jivesoftware.org/protocol/muc"));
    if (element != null) {
      voiceOnly = element.element("deaf-occupant") != null;
    }
    // Add the new role to the list of roles
    user.addRole(room.getName(), this);
  }
示例#10
0
 public Map<String, String> getMucRoomAttributes(String domain, String roomName)
     throws NotFoundException {
   MultiUserChatService mucService = this.multiUserChatManager.getMultiUserChatService(domain);
   MUCRoom mucRoom = mucService.getChatRoom(roomName);
   if (mucRoom == null) {
     throw new NotFoundException("Room not found " + domain + " roomName " + roomName);
   }
   Map<String, String> retval = new HashMap<String, String>();
   retval.put("isModerated", "" + mucRoom.isModerated());
   retval.put("isLogEnabled", "" + mucRoom.isLogEnabled());
   retval.put("isMembersOnly", "" + mucRoom.isMembersOnly());
   retval.put("isPublicRoom", "" + mucRoom.isPublicRoom());
   retval.put("isLoginRestrictedToNickName", "" + mucRoom.isLoginRestrictedToNickname());
   retval.put("isLocked", "" + mucRoom.isLocked());
   retval.put("isRegistrationEnabled", "" + mucRoom.isRegistrationEnabled());
   retval.put("isPasswordProtected", "" + mucRoom.isPasswordProtected());
   retval.put("canAnyoneDiscoverJID", "" + mucRoom.canAnyoneDiscoverJID());
   retval.put("canChangeNickName", "" + mucRoom.canChangeNickname());
   retval.put("canOccupantsInvite", "" + mucRoom.canOccupantsInvite());
   retval.put("canOccupantsChangeSubject", "" + mucRoom.canOccupantsChangeSubject());
   return retval;
 }
 public void changeNickname(String nickname) {
   this.nick = nickname;
   setRoleAddress(new JID(room.getName(), server.getServiceDomain(), nick));
 }
示例#12
0
 /**
  * Delete a chat room from the domain.
  *
  * @param domain
  * @param roomName
  */
 public void removeChatRoom(String domain, String roomName) {
   MultiUserChatService mucService = this.multiUserChatManager.getMultiUserChatService(domain);
   log.debug("removeChatRoom domain = " + domain + " roomName = " + roomName);
   mucService.removeChatRoom(roomName);
   this.roomNameToConferenceExtensionMap.remove(domain + "." + roomName);
 }