/**
  * Copy to groups.
  *
  * @param currentUser the current user
  * @param newUser the new user
  */
 private static void copyToGroups(String currentUser, String newUser) {
   GroupManager groupManager = GroupManager.getInstance();
   for (Group group : groupManager.getGroups()) {
     if (group.isUser(currentUser)) {
       group.getMembers().add(XMPPServer.getInstance().createJID(newUser, null));
     }
   }
 }
Beispiel #2
0
 public void addUserToGroup(String userJid, String groupName) throws GroupNotFoundException {
   log.debug("addUserToGroup " + userJid + " GroupName " + groupName);
   JID jid = new JID(userJid);
   Group group = groupManager.getGroup(groupName, true);
   if (group.getAdmins().contains(jid)) {
     log.debug("Admins already has " + jid);
   } else {
     group.getMembers().add(jid);
   }
 }
Beispiel #3
0
  public void createGroup(String groupName, String adminJid, String description)
      throws IllegalArgumentException {
    log.debug("createGroup groupName = " + groupName);
    Group group = null;
    JID jid = new JID(adminJid);
    if (!jid.getDomain().equals(this.getXmppDomain())) {
      throw new IllegalArgumentException("Domain must be local domain");
    }

    try {
      group = groupManager.getGroup(groupName);
    } catch (GroupNotFoundException ex) {
      try {
        group = groupManager.createGroup(groupName);

      } catch (GroupAlreadyExistsException ex1) {
        log.debug("Group already exists - not creating group");
      }
    }
    group.setDescription(description);
    group.getAdmins().remove(jid);
    group.getAdmins().add(jid);
  }
  @Override
  public IQ handleIQ(IQ packet) throws UnauthorizedException {
    IQ result = IQ.createResultIQ(packet);
    String username = packet.getFrom().getNode();
    if (!serverName.equals(packet.getFrom().getDomain()) || username == null) {
      // Users of remote servers are not allowed to get their "shared groups". Users of
      // remote servers cannot have shared groups in this server.
      // Besides, anonymous users do not belong to shared groups so answer an error
      result.setChildElement(packet.getChildElement().createCopy());
      result.setError(PacketError.Condition.not_allowed);
      return result;
    }

    Collection<Group> groups = rosterManager.getSharedGroups(username);
    Element sharedGroups =
        result.setChildElement("sharedgroup", "http://www.jivesoftware.org/protocol/sharedgroup");
    for (Group sharedGroup : groups) {
      String displayName = sharedGroup.getProperties().get("sharedRoster.displayName");
      if (displayName != null) {
        sharedGroups.addElement("group").setText(displayName);
      }
    }
    return result;
  }
  /**
   * True if the specified bookmark should be appended to the users list of bookmarks.
   *
   * @param jid the jid of the user.
   * @param bookmark the bookmark.
   * @return true if bookmark should be appended.
   */
  private static boolean isBookmarkForJID(JID jid, Bookmark bookmark) {
    String username = jid.getNode();

    if (bookmark.getUsers().contains(username)) {
      return true;
    }

    Collection<String> groups = bookmark.getGroups();

    if (groups != null && !groups.isEmpty()) {
      GroupManager groupManager = GroupManager.getInstance();
      for (String groupName : groups) {
        try {
          Group group = groupManager.getGroup(groupName);
          if (group.isUser(jid.getNode())) {
            return true;
          }
        } catch (GroupNotFoundException e) {
          Log.debug(e.getMessage(), e);
        }
      }
    }
    return false;
  }
Beispiel #6
0
  /**
   * Set the current groups for the item.
   *
   * @param groups The new lists of groups the item belongs to.
   * @throws org.jivesoftware.openfire.SharedGroupException if trying to remove shared group.
   */
  public void setGroups(List<String> groups) throws SharedGroupException {
    if (groups == null) {
      this.groups = new LinkedList<String>();
    } else {
      // Raise an error if the user is trying to remove the item from a shared group
      for (Group group : getSharedGroups()) {
        // Get the display name of the group
        String groupName = group.getProperties().get("sharedRoster.displayName");
        // Check if the group has been removed from the new groups list
        if (!groups.contains(groupName)) {
          throw new SharedGroupException("Cannot remove item from shared group");
        }
      }

      // Remove shared groups from the param
      Collection<Group> existingGroups = GroupManager.getInstance().getSharedGroups();
      for (Iterator<String> it = groups.iterator(); it.hasNext(); ) {
        String groupName = it.next();
        try {
          // Optimistic approach for performance reasons. Assume first that the shared
          // group name is the same as the display name for the shared roster

          // Check if exists a shared group with this name
          Group group = GroupManager.getInstance().getGroup(groupName);
          // Get the display name of the group
          String displayName = group.getProperties().get("sharedRoster.displayName");
          if (displayName != null && displayName.equals(groupName)) {
            // Remove the shared group from the list (since it exists)
            try {
              it.remove();
            } catch (IllegalStateException e) {
              // Do nothing
            }
          }
        } catch (GroupNotFoundException e) {
          // Check now if there is a group whose display name matches the requested group
          for (Group group : existingGroups) {
            // Get the display name of the group
            String displayName = group.getProperties().get("sharedRoster.displayName");
            if (displayName != null && displayName.equals(groupName)) {
              // Remove the shared group from the list (since it exists)
              try {
                it.remove();
              } catch (IllegalStateException ise) {
                // Do nothing
              }
            }
          }
        }
      }
      this.groups = groups;
    }
  }
Beispiel #7
0
 /**
  * Removes a group from the shared groups list.
  *
  * @param sharedGroup The shared group to remove from the list of shared groups.
  */
 public void removeSharedGroup(Group sharedGroup) {
   sharedGroups.remove(sharedGroup.getName());
   invisibleSharedGroups.remove(sharedGroup.getName());
 }
Beispiel #8
0
 /**
  * Adds a new group to the list shared groups that won't be sent to the user. These groups are for
  * internal use and help track the reason why a roster item has a presence subscription of type
  * FROM when using shared groups.
  *
  * @param sharedGroup The shared group to add to the list of shared groups.
  */
 public void addInvisibleSharedGroup(Group sharedGroup) {
   invisibleSharedGroups.add(sharedGroup.getName());
 }
Beispiel #9
0
 public boolean isUserInGroup(String jid, String groupName) throws GroupNotFoundException {
   Group group = groupManager.getGroup(groupName, true);
   return group.isUser(jid);
 }
Beispiel #10
0
 public void removeUserFromGroup(String userJid, String groupName) throws GroupNotFoundException {
   JID jid = new JID(userJid);
   Group group = groupManager.getGroup(groupName, true);
   group.getMembers().remove(jid);
   group.getAdmins().remove(jid);
 }
  public void _jspService(HttpServletRequest request, HttpServletResponse response)
      throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;

    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html");
      pageContext =
          _jspxFactory.getPageContext(this, request, response, "error.jsp", true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\n\n\n\n\n\n\n\n\n\n\n\n");
      org.jivesoftware.util.WebManager webManager = null;
      synchronized (_jspx_page_context) {
        webManager =
            (org.jivesoftware.util.WebManager)
                _jspx_page_context.getAttribute("webManager", PageContext.PAGE_SCOPE);
        if (webManager == null) {
          webManager = new org.jivesoftware.util.WebManager();
          _jspx_page_context.setAttribute("webManager", webManager, PageContext.PAGE_SCOPE);
        }
      }
      out.write('\n');
      out.write('\n');
      // Get parameters
      boolean cancel = request.getParameter("cancel") != null;
      String username = ParamUtils.getParameter(request, "username");
      String jid = ParamUtils.getParameter(request, "jid");
      String nickname = ParamUtils.getParameter(request, "nickname");
      String groups = ParamUtils.getParameter(request, "groups");
      Integer sub = ParamUtils.getIntParameter(request, "sub", 0);
      boolean save = ParamUtils.getBooleanParameter(request, "save");

      // Handle a cancel
      if (cancel) {
        response.sendRedirect("user-roster.jsp?username="******"UTF-8"));
        return;
      }

      // Load the user's roster object
      Roster roster = webManager.getRosterManager().getRoster(username);

      // Load the roster item from the user's roster.
      RosterItem item = roster.getRosterItem(new JID(jid));

      // Handle a roster item delete:
      if (save) {
        List<String> groupList = new ArrayList<String>();
        if (groups != null) {
          for (String group : groups.split(",")) {
            groupList.add(group.trim());
          }
        }
        item.setNickname(nickname);
        item.setGroups(groupList);
        item.setSubStatus(RosterItem.SubType.getTypeFromInt(sub));
        // Delete the roster item
        roster.updateRosterItem(item);
        // Log the event
        webManager.logEvent("deleted roster item from " + username, "roster item:\njid = " + jid);
        // Done, so redirect
        response.sendRedirect(
            "user-roster.jsp?username="******"UTF-8")
                + "&editsuccess=true");
        return;
      }

      out.write("\n\n<html>\n    <head>\n        <title>");
      if (_jspx_meth_fmt_message_0(_jspx_page_context)) return;
      out.write(
          "</title>\n        <meta name=\"subPageID\" content=\"user-roster\"/>\n        <meta name=\"extraParams\" content=\"");
      out.print("username="******"UTF-8"));
      out.write("\"/>\n    </head>\n    <body>\n\n<p>\n");
      //  fmt:message
      org.apache.taglibs.standard.tag.rt.fmt.MessageTag _jspx_th_fmt_message_1 =
          (org.apache.taglibs.standard.tag.rt.fmt.MessageTag)
              _jspx_tagPool_fmt_message_key.get(
                  org.apache.taglibs.standard.tag.rt.fmt.MessageTag.class);
      _jspx_th_fmt_message_1.setPageContext(_jspx_page_context);
      _jspx_th_fmt_message_1.setParent(null);
      _jspx_th_fmt_message_1.setKey("user.roster.edit.info");
      int _jspx_eval_fmt_message_1 = _jspx_th_fmt_message_1.doStartTag();
      if (_jspx_eval_fmt_message_1 != javax.servlet.jsp.tagext.Tag.SKIP_BODY) {
        if (_jspx_eval_fmt_message_1 != javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE) {
          out = _jspx_page_context.pushBody();
          _jspx_th_fmt_message_1.setBodyContent((javax.servlet.jsp.tagext.BodyContent) out);
          _jspx_th_fmt_message_1.doInitBody();
        }
        do {
          out.write("\n    ");
          //  fmt:param
          org.apache.taglibs.standard.tag.rt.fmt.ParamTag _jspx_th_fmt_param_0 =
              (org.apache.taglibs.standard.tag.rt.fmt.ParamTag)
                  _jspx_tagPool_fmt_param_value_nobody.get(
                      org.apache.taglibs.standard.tag.rt.fmt.ParamTag.class);
          _jspx_th_fmt_param_0.setPageContext(_jspx_page_context);
          _jspx_th_fmt_param_0.setParent((javax.servlet.jsp.tagext.Tag) _jspx_th_fmt_message_1);
          _jspx_th_fmt_param_0.setValue(StringUtils.escapeForXML(username));
          int _jspx_eval_fmt_param_0 = _jspx_th_fmt_param_0.doStartTag();
          if (_jspx_th_fmt_param_0.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
            _jspx_tagPool_fmt_param_value_nobody.reuse(_jspx_th_fmt_param_0);
            return;
          }
          _jspx_tagPool_fmt_param_value_nobody.reuse(_jspx_th_fmt_param_0);
          out.write('\n');
          int evalDoAfterBody = _jspx_th_fmt_message_1.doAfterBody();
          if (evalDoAfterBody != javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN) break;
        } while (true);
        if (_jspx_eval_fmt_message_1 != javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE)
          out = _jspx_page_context.popBody();
      }
      if (_jspx_th_fmt_message_1.doEndTag() == javax.servlet.jsp.tagext.Tag.SKIP_PAGE) {
        _jspx_tagPool_fmt_message_key.reuse(_jspx_th_fmt_message_1);
        return;
      }
      _jspx_tagPool_fmt_message_key.reuse(_jspx_th_fmt_message_1);
      out.write("\n</p>\n\n<fieldset>\n    <legend>");
      if (_jspx_meth_fmt_message_2(_jspx_page_context)) return;
      out.write(
          "</legend>\n    <div>\n    <table cellpadding=\"3\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n    <tbody>\n        <tr>\n            <td class=\"c1\">\n                ");
      if (_jspx_meth_fmt_message_3(_jspx_page_context)) return;
      out.write(":\n            </td>\n            <td>\n                ");
      out.print(StringUtils.escapeHTMLTags(jid));
      out.write(
          "\n            </td>\n        </tr>\n        <tr>\n            <td class=\"c1\">\n                ");
      if (_jspx_meth_fmt_message_4(_jspx_page_context)) return;
      out.write(":\n            </td>\n            <td>\n                ");
      out.print(StringUtils.escapeHTMLTags(item.getNickname()));
      out.write(
          "\n            </td>\n        </tr>\n        <tr>\n            <td class=\"c1\">\n                ");
      if (_jspx_meth_fmt_message_5(_jspx_page_context)) return;
      out.write(":\n            </td>\n            <td>\n                ");

      List<String> groupList = item.getGroups();
      if (!groupList.isEmpty()) {
        int count = 0;
        for (String group : groupList) {
          if (count != 0) {
            out.print(",");
          }
          out.print(StringUtils.escapeForXML(group));
          count++;
        }
      } else {
        out.print("<i>None</i>");
      }

      out.write(
          "\n            </td>\n        </tr>\n        <tr>\n            <td class=\"c1\">\n                <a href=\"group-summary.jsp\">");
      if (_jspx_meth_fmt_message_6(_jspx_page_context)) return;
      out.write("</a>:\n            </td>\n            <td>\n                ");

      Collection<Group> sharedGroups = item.getSharedGroups();
      if (!sharedGroups.isEmpty()) {
        int count = 0;
        for (Group group : sharedGroups) {
          if (count != 0) {
            out.print(",");
          }
          out.print(
              "<a href='group-edit.jsp?group="
                  + URLEncoder.encode(group.getName(), "UTF-8")
                  + "'>");
          out.print(StringUtils.escapeForXML(group.getName()));
          out.print("</a>");
          count++;
        }
      } else {
        out.print("<i>None</i>");
      }

      out.write(
          "\n            </td>\n        </tr>\n        <tr>\n            <td class=\"c1\">\n                ");
      if (_jspx_meth_fmt_message_7(_jspx_page_context)) return;
      out.write(":\n            </td>\n            <td>\n                ");
      out.print(StringUtils.escapeHTMLTags(item.getSubStatus().getName()));
      out.write(
          "\n            </td>\n        </tr>\n    </tbody>\n    </table>\n    </div>\n</fieldset>\n\n<br><br>\n\n<form style=\"display: inline\" action=\"user-roster-edit.jsp\">\n<input type=\"hidden\" name=\"jid\" value=\"");
      out.print(StringUtils.escapeForXML(jid));
      out.write("\">\n<input type=\"hidden\" name=\"username\" value=\"");
      out.print(StringUtils.escapeForXML(username));
      out.write("\">\n<input type=\"submit\" value=\"");
      if (_jspx_meth_fmt_message_8(_jspx_page_context)) return;
      out.write("\">\n</form>\n\n");
      if (sharedGroups.isEmpty()) {
        out.write(
            "\n<form style=\"display: inline\" action=\"user-roster-delete.jsp\">\n<input type=\"hidden\" name=\"jid\" value=\"");
        out.print(StringUtils.escapeForXML(jid));
        out.write("\">\n<input type=\"hidden\" name=\"username\" value=\"");
        out.print(StringUtils.escapeForXML(username));
        out.write("\">\n<input type=\"submit\" value=\"");
        if (_jspx_meth_fmt_message_9(_jspx_page_context)) return;
        out.write("\">\n</form>\n");
      }
      out.write("\n\n    </body>\n</html>\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)) {
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0) out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }