Ejemplo n.º 1
0
 protected void createRoom(Map<String, Object> roomSpec, String serviceName) throws Exception {
   List<String> owners = (List) roomSpec.get("owners");
   JID owner = XMPPServer.getInstance().createJID("admin", null);
   if (owners != null && owners.size() > 0) {
     owner = new JID(owners.get(0));
   } else {
     owners = new ArrayList<String>();
     owners.add(owner.toBareJID());
     roomSpec.put("owners", owners);
   }
   String roomName = (String) roomSpec.get("roomName");
   Boolean isPersistent = (Boolean) roomSpec.get("persistent");
   MUCRoom room =
       XMPPServer.getInstance()
           .getMultiUserChatManager()
           .getMultiUserChatService(serviceName)
           .getChatRoom(roomName.toLowerCase(), owner);
   IntrospectionSupport.setProperties(room, roomSpec);
   room.setRolesToBroadcastPresence(new ArrayList<String>());
   setRoles(room, roomSpec);
   room.setCreationDate(new Date());
   room.setModificationDate(new Date());
   // Unlock the room, because the default configuration lock the room.
   room.unlock(room.getRole());
   System.out.println("isPersistent:" + isPersistent);
   if (isPersistent == null) {
     room.setPersistent(true);
   }
   if (room.isPersistent()) {
     room.saveToDB();
   }
 }
Ejemplo n.º 2
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();
 }
Ejemplo n.º 3
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;
      }
    }
  }
Ejemplo n.º 4
0
 public void kickOccupant(
     String subdomain, String roomName, String password, String memberJid, String reason)
     throws NotAllowedException {
   MUCRoom mucRoom =
       this.multiUserChatManager.getMultiUserChatService(subdomain).getChatRoom(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 actorJid = mucRoom.getOwners().iterator().next();
   JID memberJID = new JID(memberJid);
   JID actorJID = new JID(actorJid);
   mucRoom.kickOccupant(memberJID, actorJID, reason);
 }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
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);
  }
Ejemplo n.º 8
0
 private void setRoles(MUCRoom room, Map<String, Object> roomSpec) throws Exception {
   List<JID> roles = new ArrayList<JID>();
   Collection<JID> owners = new ArrayList<JID>();
   Collection<JID> existingOwners = new ArrayList<JID>();
   List<String> specOwners = (List) roomSpec.get("owners");
   List<String> specAdmins = (List) roomSpec.get("admins");
   List<String> specMembers = (List) roomSpec.get("members");
   List<String> specOutcasts = (List) roomSpec.get("outcasts");
   List<JID> mucRoomEntityOwners = convertStringsToJIDs(specOwners);
   owners.addAll(room.getOwners());
   // Find same owners
   for (JID jid : owners) {
     if (mucRoomEntityOwners.contains(jid)) {
       existingOwners.add(jid);
     }
   }
   // Don't delete the same owners
   owners.removeAll(existingOwners);
   room.addOwners(convertStringsToJIDs(specOwners), room.getRole());
   // Collect all roles to reset
   roles.addAll(owners);
   roles.addAll(room.getAdmins());
   roles.addAll(room.getMembers());
   roles.addAll(room.getOutcasts());
   for (JID jid : roles) {
     room.addNone(jid, room.getRole());
   }
   room.addOwners(convertStringsToJIDs(specOwners), room.getRole());
   if (specAdmins != null) {
     room.addAdmins(convertStringsToJIDs(specAdmins), room.getRole());
   }
   if (specMembers != null) {
     for (String memberJid : specMembers) {
       room.addMember(new JID(memberJid), null, room.getRole());
     }
   }
   if (specOutcasts != null) {
     for (String outcastJid : specOutcasts) {
       room.addOutcast(new JID(outcastJid), null, room.getRole());
     }
   }
 }
Ejemplo n.º 9
0
 public Map<String, Object> convertToRoomSpec(MUCRoom room) {
   Map<String, Object> roomSpec = new HashMap();
   roomSpec.put("naturalLanguageName", room.getNaturalLanguageName());
   roomSpec.put("name", room.getName());
   roomSpec.put("description", room.getDescription());
   roomSpec.put("canAnyoneDiscoverJID", room.canAnyoneDiscoverJID());
   roomSpec.put("canChangeNickname", room.canChangeNickname());
   roomSpec.put("canOccupantsChangeSubject", room.canOccupantsChangeSubject());
   roomSpec.put("canOccupantsInvite", room.canOccupantsInvite());
   roomSpec.put("publicRoom", room.isPublicRoom());
   roomSpec.put("password", room.getPassword());
   roomSpec.put("ID", room.getID());
   roomSpec.put("persistent", room.isPersistent());
   roomSpec.put("registrationEnabled", room.isRegistrationEnabled());
   roomSpec.put("logEnabled", room.isLogEnabled());
   roomSpec.put("loginRestrictedToNickname", room.isLoginRestrictedToNickname());
   roomSpec.put("maxUsers", room.getMaxUsers());
   roomSpec.put("membersOnly", room.isMembersOnly());
   roomSpec.put("moderated", room.isModerated());
   roomSpec.put("owners", convertJIDsToStringList(room.getOwners()));
   roomSpec.put("admins", convertJIDsToStringList(room.getAdmins()));
   roomSpec.put("members", convertJIDsToStringList(room.getMembers()));
   roomSpec.put("outcasts", convertJIDsToStringList(room.getOutcasts()));
   roomSpec.put("broadcastPresenceRoles", room.getRolesToBroadcastPresence());
   roomSpec.put("creationDate", room.getCreationDate());
   roomSpec.put("modificationDate", room.getModificationDate());
   return roomSpec;
 }