@Override
    public void execute(@Nonnull final SessionData data, Element command) {
        final Locale preferredLocale = SessionManager.getInstance().getLocaleForSession(data.getOwner());

        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(LocaleUtils.getLocalizedString("commands.admin.group.addgroup.note.groups-readonly", preferredLocale));
            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(LocaleUtils.getLocalizedString("commands.admin.group.addgroup.note.group-exists", preferredLocale));
            return;
        } catch (GroupNameInvalidException e) {
            // Group name not valid
            note.addAttribute("type", "error");
            note.setText(LocaleUtils.getLocalizedString("commands.admin.group.addgroup.note.group-name-invalid", preferredLocale));
            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);
        List<String> displayName = data.getData().get("displayName");
        List<String> groupList = data.getData().get("groupList");

        // New group is configured as a shared group
        switch (showInRoster) {
            case "nobody":
                // New group is not a shared group
                group.shareWithNobody();
                break;

            case "everybody":
                if (displayName == null) {
                    withErrors = true;
                } else {
                    group.shareWithEverybody(displayName.get(0));
                }
                break;

            case "spefgroups":
                if (displayName == null) {
                    withErrors = true;
                } else {
                    group.shareWithUsersInGroups(groupList, displayName.get(0));
                }
                break;

            case "onlyGroup":
                if (displayName == null) {
                    withErrors = true;
                } else {
                    group.shareWithUsersInSameGroup(displayName.get(0));
                }
                break;

            default:
                withErrors = true;
        }

        note.addAttribute("type", "info");
        note.setText(LocaleUtils.getLocalizedString((withErrors ? "commands.global.operation.finished.with-errors" : "commands.global.operation.finished.success"), preferredLocale));
    }
Command that allows to create and configure new groups.

@author Gaston Dombiak
xmppserver/src/main/java/org/jivesoftware/openfire/commands/admin/group/AddGroup.java