Search in sources :

Example 21 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class AddGroup method execute.

@Override
public void execute(SessionData data, Element command) {
    Element note = command.addElement("note");
    // Check if groups cannot be modified (backend is read-only)
    if (GroupManager.getInstance().isReadOnly()) {
        note.addAttribute("type", "error");
        note.setText("Groups are read only");
        return;
    }
    // Get requested group
    Group group;
    try {
        group = GroupManager.getInstance().createGroup(data.getData().get("group").get(0));
    } catch (GroupAlreadyExistsException e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Group already exists");
        return;
    }
    List<String> desc = data.getData().get("desc");
    if (desc != null && !desc.isEmpty()) {
        group.setDescription(desc.get(0));
    }
    List<String> members = data.getData().get("members");
    boolean withErrors = false;
    if (members != null) {
        Collection<JID> users = group.getMembers();
        for (String user : members) {
            try {
                users.add(new JID(user));
            } catch (Exception e) {
                Log.warn("User not added to group", e);
                withErrors = true;
            }
        }
    }
    String showInRoster = data.getData().get("showInRoster").get(0);
    if ("nobody".equals(showInRoster)) {
        // New group is not a shared group
        group.getProperties().put("sharedRoster.showInRoster", "nobody");
        group.getProperties().put("sharedRoster.displayName", " ");
        group.getProperties().put("sharedRoster.groupList", " ");
    } else {
        // New group is configured as a shared group
        if ("spefgroups".equals(showInRoster)) {
            // Show shared group to other groups
            showInRoster = "onlyGroup";
        }
        List<String> displayName = data.getData().get("displayName");
        List<String> groupList = data.getData().get("groupList");
        if (displayName != null) {
            group.getProperties().put("sharedRoster.showInRoster", showInRoster);
            group.getProperties().put("sharedRoster.displayName", displayName.get(0));
            if (groupList != null) {
                StringBuilder buf = new StringBuilder();
                String sep = "";
                for (String groupName : groupList) {
                    buf.append(sep).append(groupName);
                    sep = ",";
                }
                group.getProperties().put("sharedRoster.groupList", buf.toString());
            }
        } else {
            withErrors = true;
        }
    }
    note.addAttribute("type", "info");
    note.setText("Operation finished" + (withErrors ? " with errors" : " successfully"));
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) GroupAlreadyExistsException(org.jivesoftware.openfire.group.GroupAlreadyExistsException) Element(org.dom4j.Element) GroupAlreadyExistsException(org.jivesoftware.openfire.group.GroupAlreadyExistsException)

Example 22 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class GetListGroupUsers method execute.

@Override
public void execute(SessionData data, Element command) {
    Group group;
    try {
        group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
    } catch (GroupNotFoundException e) {
        // Group not found
        Element note = command.addElement("note");
        note.addAttribute("type", "error");
        note.setText("Group name does not exist");
        return;
    }
    DataForm form = new DataForm(DataForm.Type.result);
    form.addReportedField("jid", "User", FormField.Type.jid_single);
    form.addReportedField("admin", "Description", FormField.Type.boolean_type);
    // Add group members the result
    for (JID memberJID : group.getMembers()) {
        Map<String, Object> fields = new HashMap<>();
        fields.put("jid", memberJID.toString());
        fields.put("admin", false);
        form.addItemFields(fields);
    }
    // Add group admins the result
    for (JID memberJID : group.getAdmins()) {
        Map<String, Object> fields = new HashMap<>();
        fields.put("jid", memberJID.toString());
        fields.put("admin", true);
        form.addItemFields(fields);
    }
    command.add(form.getElement());
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) HashMap(java.util.HashMap) Element(org.dom4j.Element) DataForm(org.xmpp.forms.DataForm) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 23 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class UpdateGroup method addStageInformation.

@Override
protected void addStageInformation(SessionData data, Element command) {
    DataForm form = new DataForm(DataForm.Type.form);
    if (data.getStage() == 0) {
        form.setTitle("Update group configuration");
        form.addInstruction("Fill out this form to specify the group to update.");
        FormField field = form.addField();
        field.setType(FormField.Type.hidden);
        field.setVariable("FORM_TYPE");
        field.addValue("http://jabber.org/protocol/admin");
        field = form.addField();
        field.setType(FormField.Type.text_single);
        field.setLabel("Group Name");
        field.setVariable("group");
        field.setRequired(true);
    } else {
        // Check if groups cannot be modified (backend is read-only)
        if (GroupManager.getInstance().isReadOnly()) {
            Element note = command.addElement("note");
            note.addAttribute("type", "error");
            note.setText("Groups are read only");
            return;
        }
        // Get requested group
        Group group;
        try {
            group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
        } catch (GroupNotFoundException e) {
            // Group not found
            Element note = command.addElement("note");
            note.addAttribute("type", "error");
            note.setText("Group not found");
            return;
        }
        form.setTitle("Update group configuration");
        form.addInstruction("Fill out this form with the new group configuration.");
        FormField field = form.addField();
        field.setType(FormField.Type.hidden);
        field.setVariable("FORM_TYPE");
        field.addValue("http://jabber.org/protocol/admin");
        field = form.addField();
        field.setType(FormField.Type.text_multi);
        field.setLabel("Description");
        field.setVariable("desc");
        if (group.getDescription() != null) {
            field.addValue(group.getDescription());
        }
        field = form.addField();
        field.setType(FormField.Type.list_single);
        field.setLabel("Shared group visibility");
        field.setVariable("showInRoster");
        field.addValue("nobody");
        field.addOption("Disable sharing group in rosters", "nobody");
        field.addOption("Show group in all users' rosters", "everybody");
        field.addOption("Show group in group members' rosters", "onlyGroup");
        field.addOption("Show group to members' rosters of these groups", "spefgroups");
        field.setRequired(true);
        String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
        if (showInRoster != null) {
            if ("onlyGroup".equals(showInRoster) && group.getProperties().get("sharedRoster.groupList").trim().length() > 0) {
                // Show shared group to other groups
                showInRoster = "spefgroups";
            }
            field.addValue(showInRoster);
        }
        field = form.addField();
        field.setType(FormField.Type.list_multi);
        field.setVariable("groupList");
        for (Group otherGroup : GroupManager.getInstance().getGroups()) {
            field.addOption(otherGroup.getName(), otherGroup.getName());
        }
        String groupList = group.getProperties().get("sharedRoster.groupList");
        if (groupList != null) {
            Collection<String> groups = new ArrayList<>();
            StringTokenizer tokenizer = new StringTokenizer(groupList, ",\t\n\r\f");
            while (tokenizer.hasMoreTokens()) {
                String tok = tokenizer.nextToken().trim();
                groups.add(tok.trim());
            }
            for (String othergroup : groups) {
                field.addValue(othergroup);
            }
        }
        field = form.addField();
        field.setType(FormField.Type.text_single);
        field.setLabel("Group Display Name");
        field.setVariable("displayName");
        String displayName = group.getProperties().get("sharedRoster.displayName");
        if (displayName != null) {
            field.addValue(displayName);
        }
    }
    // Add the form to the command
    command.add(form.getElement());
}
Also used : Group(org.jivesoftware.openfire.group.Group) StringTokenizer(java.util.StringTokenizer) Element(org.dom4j.Element) DataForm(org.xmpp.forms.DataForm) ArrayList(java.util.ArrayList) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) FormField(org.xmpp.forms.FormField)

Example 24 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class GroupAdminRemoved method execute.

@Override
public void execute(SessionData sessionData, Element command) {
    Element note = command.addElement("note");
    Map<String, List<String>> data = sessionData.getData();
    // Get the group name
    String groupname;
    try {
        groupname = get(data, "groupName", 0);
    } catch (NullPointerException npe) {
        note.addAttribute("type", "error");
        note.setText("Group name required parameter.");
        return;
    }
    // Creates event params.
    Map<String, Object> params = null;
    try {
        // Get the admin
        String admin = get(data, "admin", 0);
        // Adds the admin
        params = new HashMap<>();
        params.put("admin", admin);
    } catch (NullPointerException npe) {
        note.addAttribute("type", "error");
        note.setText("Admin required parameter.");
        return;
    }
    // Sends the event
    Group group;
    try {
        group = GroupManager.getInstance().getGroup(groupname, true);
        // Fire event.
        GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.admin_removed, params);
    } catch (GroupNotFoundException e) {
        note.addAttribute("type", "error");
        note.setText("Group not found.");
    }
    // Answer that the operation was successful
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully");
}
Also used : Group(org.jivesoftware.openfire.group.Group) Element(org.dom4j.Element) List(java.util.List) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 25 with Group

use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.

the class RosterManager method userDeleting.

@Override
public void userDeleting(User user, Map<String, Object> params) {
    // Shared public groups that have a presence subscription of type FROM
    // for the deleted user should no longer have a reference to the deleted user
    JID userJID = server.createJID(user.getUsername(), null);
    // of type FROM for the new user
    for (Group group : getPublicSharedGroups()) {
        // Get group members of public group
        Collection<JID> users = new HashSet<>(group.getMembers());
        users.addAll(group.getAdmins());
        // Update the roster of each group member to include a subscription of type FROM
        for (JID userToUpdate : users) {
            // Get the roster to update
            Roster roster = null;
            if (server.isLocal(userToUpdate)) {
                // Check that the user exists, if not then continue with the next user
                try {
                    UserManager.getInstance().getUser(userToUpdate.getNode());
                } catch (UserNotFoundException e) {
                    continue;
                }
                roster = rosterCache.get(userToUpdate.getNode());
            }
            // Only update rosters in memory
            if (roster != null) {
                roster.deleteSharedUser(group, userJID);
            }
            if (!server.isLocal(userToUpdate)) {
                // Unsusbcribe from the presence of the remote user. This is only necessary for
                // remote users and may only work with remote users that **automatically**
                // accept presence subscription requests
                sendSubscribeRequest(userJID, userToUpdate, false);
            }
        }
    }
    deleteRoster(userJID);
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID)

Aggregations

Group (org.jivesoftware.openfire.group.Group)84 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)42 JID (org.xmpp.packet.JID)30 Element (org.dom4j.Element)20 ArrayList (java.util.ArrayList)19 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)11 User (org.jivesoftware.openfire.user.User)9 List (java.util.List)7 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)7 StringTokenizer (java.util.StringTokenizer)6 GroupManager (org.jivesoftware.openfire.group.GroupManager)5 HashMap (java.util.HashMap)4 GroupEntity (org.jivesoftware.openfire.plugin.rest.entity.GroupEntity)4 DataForm (org.xmpp.forms.DataForm)4 IQ (org.xmpp.packet.IQ)4 HashSet (java.util.HashSet)3 XMPPServer (org.jivesoftware.openfire.XMPPServer)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2