Search in sources :

Example 41 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class FormManager method saveDataForm.

private void saveDataForm(Workgroup workgroup) {
    DataForm dataForm = new DataForm(DataForm.Type.form);
    WorkgroupForm form = getWebForm(workgroup);
    if (form.getTitle() != null) {
        dataForm.setTitle(form.getTitle());
    }
    if (form.getDescription() != null) {
        dataForm.addInstruction(form.getDescription());
    }
    List<FormElement> elems = new ArrayList<FormElement>();
    // Add normal elems
    int size = form.getFormElements().size();
    for (int j = 0; j < size; j++) {
        elems.add(form.getFormElementAt(j));
    }
    size = form.getHiddenVars().size();
    for (int k = 0; k < size; k++) {
        elems.add(form.getHiddenVars().get(k));
    }
    size = elems.size();
    for (int i = 0; i < size; i++) {
        FormElement elem = elems.get(i);
        FormField field = dataForm.addField();
        field.setLabel(elem.getLabel());
        field.setVariable(elem.getVariable());
        field.setRequired(elem.isRequired());
        if (elem.getDescription() != null) {
            field.setDescription(elem.getDescription());
        }
        if (elem.getAnswerType() == WorkgroupForm.FormEnum.textarea) {
            field.setType(FormField.Type.text_multi);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.textfield) {
            field.setType(FormField.Type.text_single);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.checkbox) {
            field.setType(FormField.Type.boolean_type);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.radio_button) {
            field.setType(FormField.Type.list_multi);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.dropdown_box) {
            field.setType(FormField.Type.list_single);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.hidden) {
            field.setType(FormField.Type.hidden);
        } else if (elem.getAnswerType() == WorkgroupForm.FormEnum.password) {
            field.setType(FormField.Type.text_private);
        }
        if (elem.getAnswers().size() > 0 && elem.getAnswerType() != WorkgroupForm.FormEnum.hidden) {
            for (String item : elem.getAnswers()) {
                field.addOption(item, item);
            }
        } else if (elem.getAnswers().size() > 0) {
            // Add hidden element values.
            for (String item : elem.getAnswers()) {
                field.addValue(item);
            }
        }
    }
    XStream xstream = new XStream();
    String xmlToSave = xstream.toXML(dataForm);
    DbProperties props = workgroup.getProperties();
    String context = "jive.dataform.wg";
    try {
        props.deleteProperty(context);
        props.setProperty(context, xmlToSave);
    } catch (UnauthorizedException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : XStream(com.thoughtworks.xstream.XStream) DataForm(org.xmpp.forms.DataForm) ArrayList(java.util.ArrayList) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) DbProperties(org.jivesoftware.xmpp.workgroup.DbProperties) FormField(org.xmpp.forms.FormField)

Example 42 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class IQOwnerHandler method refreshConfigurationFormValues.

private void refreshConfigurationFormValues() {
    room.lock.readLock().lock();
    try {
        FormField field = configurationForm.getField("muc#roomconfig_roomname");
        field.clearValues();
        field.addValue(room.getNaturalLanguageName());
        field = configurationForm.getField("muc#roomconfig_roomdesc");
        field.clearValues();
        field.addValue(room.getDescription());
        field = configurationForm.getField("muc#roomconfig_changesubject");
        field.clearValues();
        field.addValue((room.canOccupantsChangeSubject() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_maxusers");
        field.clearValues();
        field.addValue(Integer.toString(room.getMaxUsers()));
        field = configurationForm.getField("muc#roomconfig_presencebroadcast");
        field.clearValues();
        for (String roleToBroadcast : room.getRolesToBroadcastPresence()) {
            field.addValue(roleToBroadcast);
        }
        field = configurationForm.getField("muc#roomconfig_publicroom");
        field.clearValues();
        field.addValue((room.isPublicRoom() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_persistentroom");
        field.clearValues();
        field.addValue((room.isPersistent() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_moderatedroom");
        field.clearValues();
        field.addValue((room.isModerated() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_membersonly");
        field.clearValues();
        field.addValue((room.isMembersOnly() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_allowinvites");
        field.clearValues();
        field.addValue((room.canOccupantsInvite() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_passwordprotectedroom");
        field.clearValues();
        field.addValue((room.isPasswordProtected() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_roomsecret");
        field.clearValues();
        field.addValue(room.getPassword());
        field = configurationForm.getField("muc#roomconfig_whois");
        field.clearValues();
        field.addValue((room.canAnyoneDiscoverJID() ? "anyone" : "moderators"));
        field = configurationForm.getField("muc#roomconfig_allowpm");
        field.clearValues();
        field.addValue((room.canSendPrivateMessage()));
        field = configurationForm.getField("muc#roomconfig_enablelogging");
        field.clearValues();
        field.addValue((room.isLogEnabled() ? "1" : "0"));
        field = configurationForm.getField("x-muc#roomconfig_reservednick");
        field.clearValues();
        field.addValue((room.isLoginRestrictedToNickname() ? "1" : "0"));
        field = configurationForm.getField("x-muc#roomconfig_canchangenick");
        field.clearValues();
        field.addValue((room.canChangeNickname() ? "1" : "0"));
        field = configurationForm.getField("x-muc#roomconfig_registration");
        field.clearValues();
        field.addValue((room.isRegistrationEnabled() ? "1" : "0"));
        field = configurationForm.getField("muc#roomconfig_roomadmins");
        field.clearValues();
        for (JID jid : room.getAdmins()) {
            if (GroupJID.isGroup(jid)) {
                try {
                    // add each group member to the result (clients don't understand groups)
                    Group group = GroupManager.getInstance().getGroup(jid);
                    for (JID groupMember : group.getAll()) {
                        field.addValue(groupMember);
                    }
                } catch (GroupNotFoundException gnfe) {
                    Log.warn("Invalid group JID in the member list: " + jid);
                }
            } else {
                field.addValue(jid.toString());
            }
        }
        field = configurationForm.getField("muc#roomconfig_roomowners");
        field.clearValues();
        for (JID jid : room.getOwners()) {
            if (GroupJID.isGroup(jid)) {
                try {
                    // add each group member to the result (clients don't understand groups)
                    Group group = GroupManager.getInstance().getGroup(jid);
                    for (JID groupMember : group.getAll()) {
                        field.addValue(groupMember);
                    }
                } catch (GroupNotFoundException gnfe) {
                    Log.warn("Invalid group JID in the member list: " + jid);
                }
            } else {
                field.addValue(jid.toString());
            }
        }
        // Remove the old element
        probeResult.remove(probeResult.element(QName.get("x", "jabber:x:data")));
        // Add the new representation of configurationForm as an element 
        probeResult.add(configurationForm.getElement());
    } finally {
        room.lock.readLock().unlock();
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) GroupJID(org.jivesoftware.openfire.group.GroupJID) JID(org.xmpp.packet.JID) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) FormField(org.xmpp.forms.FormField)

Example 43 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class IQOwnerHandler method init.

private void init() {
    Element element = DocumentHelper.createElement(QName.get("query", "http://jabber.org/protocol/muc#owner"));
    configurationForm = new DataForm(DataForm.Type.form);
    configurationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.conf.title"));
    List<String> params = new ArrayList<>();
    params.add(room.getName());
    configurationForm.addInstruction(LocaleUtils.getLocalizedString("muc.form.conf.instruction", params));
    configurationForm.addField("FORM_TYPE", null, Type.hidden).addValue("http://jabber.org/protocol/muc#roomconfig");
    configurationForm.addField("muc#roomconfig_roomname", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomname"), Type.text_single);
    configurationForm.addField("muc#roomconfig_roomdesc", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomdesc"), Type.text_single);
    configurationForm.addField("muc#roomconfig_changesubject", LocaleUtils.getLocalizedString("muc.form.conf.owner_changesubject"), Type.boolean_type);
    final FormField maxUsers = configurationForm.addField("muc#roomconfig_maxusers", LocaleUtils.getLocalizedString("muc.form.conf.owner_maxusers"), Type.list_single);
    maxUsers.addOption("10", "10");
    maxUsers.addOption("20", "20");
    maxUsers.addOption("30", "30");
    maxUsers.addOption("40", "40");
    maxUsers.addOption("50", "50");
    maxUsers.addOption(LocaleUtils.getLocalizedString("muc.form.conf.none"), "0");
    final FormField broadcast = configurationForm.addField("muc#roomconfig_presencebroadcast", LocaleUtils.getLocalizedString("muc.form.conf.owner_presencebroadcast"), Type.list_multi);
    broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderator");
    broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.participant"), "participant");
    broadcast.addOption(LocaleUtils.getLocalizedString("muc.form.conf.visitor"), "visitor");
    configurationForm.addField("muc#roomconfig_publicroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_publicroom"), Type.boolean_type);
    configurationForm.addField("muc#roomconfig_persistentroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_persistentroom"), Type.boolean_type);
    configurationForm.addField("muc#roomconfig_moderatedroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_moderatedroom"), Type.boolean_type);
    configurationForm.addField("muc#roomconfig_membersonly", LocaleUtils.getLocalizedString("muc.form.conf.owner_membersonly"), Type.boolean_type);
    configurationForm.addField(null, null, Type.fixed).addValue(LocaleUtils.getLocalizedString("muc.form.conf.allowinvitesfixed"));
    configurationForm.addField("muc#roomconfig_allowinvites", LocaleUtils.getLocalizedString("muc.form.conf.owner_allowinvites"), Type.boolean_type);
    configurationForm.addField("muc#roomconfig_passwordprotectedroom", LocaleUtils.getLocalizedString("muc.form.conf.owner_passwordprotectedroom"), Type.boolean_type);
    configurationForm.addField(null, null, Type.fixed).addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomsecretfixed"));
    configurationForm.addField("muc#roomconfig_roomsecret", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomsecret"), Type.text_private);
    final FormField whois = configurationForm.addField("muc#roomconfig_whois", LocaleUtils.getLocalizedString("muc.form.conf.owner_whois"), Type.list_single);
    whois.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderators");
    whois.addOption(LocaleUtils.getLocalizedString("muc.form.conf.anyone"), "anyone");
    final FormField allowpm = configurationForm.addField("muc#roomconfig_allowpm", LocaleUtils.getLocalizedString("muc.form.conf.owner_allowpm"), Type.list_single);
    allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.anyone"), "anyone");
    allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderators");
    allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.participant"), "participants");
    allowpm.addOption(LocaleUtils.getLocalizedString("muc.form.conf.none"), "none");
    configurationForm.addField("muc#roomconfig_enablelogging", LocaleUtils.getLocalizedString("muc.form.conf.owner_enablelogging"), Type.boolean_type);
    configurationForm.addField("x-muc#roomconfig_reservednick", LocaleUtils.getLocalizedString("muc.form.conf.owner_reservednick"), Type.boolean_type);
    configurationForm.addField("x-muc#roomconfig_canchangenick", LocaleUtils.getLocalizedString("muc.form.conf.owner_canchangenick"), Type.boolean_type);
    configurationForm.addField(null, null, Type.fixed).addValue(LocaleUtils.getLocalizedString("muc.form.conf.owner_registration"));
    configurationForm.addField("x-muc#roomconfig_registration", LocaleUtils.getLocalizedString("muc.form.conf.owner_registration"), Type.boolean_type);
    configurationForm.addField(null, null, Type.fixed).addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomadminsfixed"));
    configurationForm.addField("muc#roomconfig_roomadmins", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomadmins"), Type.jid_multi);
    configurationForm.addField(null, null, Type.fixed).addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomownersfixed"));
    configurationForm.addField("muc#roomconfig_roomowners", LocaleUtils.getLocalizedString("muc.form.conf.owner_roomowners"), Type.jid_multi);
    // Create the probeResult and add the basic info together with the configuration form
    probeResult = element;
    probeResult.add(configurationForm.getElement());
}
Also used : Element(org.dom4j.Element) DataForm(org.xmpp.forms.DataForm) ArrayList(java.util.ArrayList) FormField(org.xmpp.forms.FormField)

Example 44 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class SearchPlugin method processGetPacket.

/**
	 * Processes an IQ stanza of type 'get', which in the context of 'Jabber Search' is a request for available search fields.
	 * 
	 * @param packet
	 *            An IQ stanza of type 'get'
	 * @return A result IQ stanza that contains the possbile search fields.
	 */
private IQ processGetPacket(IQ packet) {
    if (!packet.getType().equals(IQ.Type.get)) {
        throw new IllegalArgumentException("This method only accepts 'get' typed IQ stanzas as an argument.");
    }
    IQ replyPacket = IQ.createResultIQ(packet);
    Element queryResult = DocumentHelper.createElement(QName.get("query", NAMESPACE_JABBER_IQ_SEARCH));
    String instructions = LocaleUtils.getLocalizedString("advance.user.search.details", "search");
    // non-data form
    queryResult.addElement("instructions").addText(instructions);
    queryResult.addElement("first");
    queryResult.addElement("last");
    queryResult.addElement("nick");
    queryResult.addElement("email");
    DataForm searchForm = new DataForm(DataForm.Type.form);
    searchForm.setTitle(LocaleUtils.getLocalizedString("advance.user.search.title", "search"));
    searchForm.addInstruction(instructions);
    searchForm.addField("FORM_TYPE", null, FormField.Type.hidden).addValue(NAMESPACE_JABBER_IQ_SEARCH);
    searchForm.addField("search", LocaleUtils.getLocalizedString("advance.user.search.search", "search"), FormField.Type.text_single).setRequired(true);
    for (String searchField : getFilteredSearchFields()) {
        final FormField field = searchForm.addField();
        field.setVariable(searchField);
        field.setType(FormField.Type.boolean_type);
        field.addValue("1");
        field.setLabel(LocaleUtils.getLocalizedString("advance.user.search." + searchField.toLowerCase(), "search"));
        field.setRequired(false);
    }
    queryResult.add(searchForm.getElement());
    replyPacket.setChildElement(queryResult);
    return replyPacket;
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 45 with FormField

use of org.xmpp.forms.FormField in project Openfire by igniterealtime.

the class IQRegisterHandler method handleIQ.

@Override
public IQ handleIQ(IQ packet) throws PacketException, UnauthorizedException {
    ClientSession session = sessionManager.getSession(packet.getFrom());
    IQ reply = null;
    // If no session was found then answer an error (if possible)
    if (session == null) {
        Log.error("Error during registration. Session not found in " + sessionManager.getPreAuthenticatedKeys() + " for key " + packet.getFrom());
        // This error packet will probably won't make it through
        reply = IQ.createResultIQ(packet);
        reply.setChildElement(packet.getChildElement().createCopy());
        reply.setError(PacketError.Condition.internal_server_error);
        return reply;
    }
    if (IQ.Type.get.equals(packet.getType())) {
        // If inband registration is not allowed, return an error.
        if (!registrationEnabled) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.forbidden);
        } else {
            reply = IQ.createResultIQ(packet);
            if (session.getStatus() == Session.STATUS_AUTHENTICATED) {
                try {
                    User user = userManager.getUser(session.getUsername());
                    Element currentRegistration = probeResult.createCopy();
                    currentRegistration.addElement("registered");
                    currentRegistration.element("username").setText(user.getUsername());
                    currentRegistration.element("password").setText("");
                    currentRegistration.element("email").setText(user.getEmail() == null ? "" : user.getEmail());
                    currentRegistration.element("name").setText(user.getName());
                    Element form = currentRegistration.element(QName.get("x", "jabber:x:data"));
                    Iterator fields = form.elementIterator("field");
                    Element field;
                    while (fields.hasNext()) {
                        field = (Element) fields.next();
                        if ("username".equals(field.attributeValue("var"))) {
                            field.addElement("value").addText(user.getUsername());
                        } else if ("name".equals(field.attributeValue("var"))) {
                            field.addElement("value").addText(user.getName());
                        } else if ("email".equals(field.attributeValue("var"))) {
                            field.addElement("value").addText(user.getEmail() == null ? "" : user.getEmail());
                        }
                    }
                    reply.setChildElement(currentRegistration);
                } catch (UserNotFoundException e) {
                    reply.setChildElement(probeResult.createCopy());
                }
            } else {
                // This is a workaround. Since we don't want to have an incorrect TO attribute
                // value we need to clean up the TO attribute. The TO attribute will contain an
                // incorrect value since we are setting a fake JID until the user actually
                // authenticates with the server.
                reply.setTo((JID) null);
                reply.setChildElement(probeResult.createCopy());
            }
        }
    } else if (IQ.Type.set.equals(packet.getType())) {
        try {
            Element iqElement = packet.getChildElement();
            if (iqElement.element("remove") != null) {
                // If inband registration is not allowed, return an error.
                if (!registrationEnabled) {
                    reply = IQ.createResultIQ(packet);
                    reply.setChildElement(packet.getChildElement().createCopy());
                    reply.setError(PacketError.Condition.forbidden);
                } else {
                    if (session.getStatus() == Session.STATUS_AUTHENTICATED) {
                        User user = userManager.getUser(session.getUsername());
                        // Delete the user
                        userManager.deleteUser(user);
                        // Delete the roster of the user
                        rosterManager.deleteRoster(session.getAddress());
                        // Delete the user from all the Groups
                        GroupManager.getInstance().deleteUser(user);
                        reply = IQ.createResultIQ(packet);
                        session.process(reply);
                        // Take a quick nap so that the client can process the result
                        Thread.sleep(10);
                        // Close the user's connection
                        final StreamError error = new StreamError(StreamError.Condition.not_authorized);
                        for (ClientSession sess : sessionManager.getSessions(user.getUsername())) {
                            sess.deliverRawText(error.toXML());
                            sess.close();
                        }
                        // The reply has been sent so clean up the variable
                        reply = null;
                    } else {
                        throw new UnauthorizedException();
                    }
                }
            } else {
                String username;
                String password = null;
                String email = null;
                String name = null;
                User newUser;
                DataForm registrationForm;
                FormField field;
                Element formElement = iqElement.element("x");
                // Check if a form was used to provide the registration info
                if (formElement != null) {
                    // Get the sent form
                    registrationForm = new DataForm(formElement);
                    // Get the username sent in the form
                    List<String> values = registrationForm.getField("username").getValues();
                    username = (!values.isEmpty() ? values.get(0) : " ");
                    // Get the password sent in the form
                    field = registrationForm.getField("password");
                    if (field != null) {
                        values = field.getValues();
                        password = (!values.isEmpty() ? values.get(0) : " ");
                    }
                    // Get the email sent in the form
                    field = registrationForm.getField("email");
                    if (field != null) {
                        values = field.getValues();
                        email = (!values.isEmpty() ? values.get(0) : " ");
                    }
                    // Get the name sent in the form
                    field = registrationForm.getField("name");
                    if (field != null) {
                        values = field.getValues();
                        name = (!values.isEmpty() ? values.get(0) : " ");
                    }
                } else {
                    // Get the registration info from the query elements
                    username = iqElement.elementText("username");
                    password = iqElement.elementText("password");
                    email = iqElement.elementText("email");
                    name = iqElement.elementText("name");
                }
                if (email != null && email.matches("\\s*")) {
                    email = null;
                }
                if (name != null && name.matches("\\s*")) {
                    name = null;
                }
                // stringprep validity now.
                if (username != null) {
                    Stringprep.nodeprep(username);
                }
                if (session.getStatus() == Session.STATUS_AUTHENTICATED) {
                    // Flag that indicates if the user is *only* changing his password
                    boolean onlyPassword = false;
                    if (iqElement.elements().size() == 2 && iqElement.element("username") != null && iqElement.element("password") != null) {
                        onlyPassword = true;
                    }
                    // If users are not allowed to change their password, return an error.
                    if (password != null && !canChangePassword) {
                        reply = IQ.createResultIQ(packet);
                        reply.setChildElement(packet.getChildElement().createCopy());
                        reply.setError(PacketError.Condition.forbidden);
                        return reply;
                    } else // If inband registration is not allowed, return an error.
                    if (!onlyPassword && !registrationEnabled) {
                        reply = IQ.createResultIQ(packet);
                        reply.setChildElement(packet.getChildElement().createCopy());
                        reply.setError(PacketError.Condition.forbidden);
                        return reply;
                    } else {
                        User user = userManager.getUser(session.getUsername());
                        if (user.getUsername().equalsIgnoreCase(username)) {
                            if (password != null && password.trim().length() > 0) {
                                user.setPassword(password);
                            }
                            if (!onlyPassword) {
                                user.setEmail(email);
                            }
                            newUser = user;
                        } else if (password != null && password.trim().length() > 0) {
                            // An admin can create new accounts when logged in.
                            newUser = userManager.createUser(username, password, null, email);
                        } else {
                            // Deny registration of users with no password
                            reply = IQ.createResultIQ(packet);
                            reply.setChildElement(packet.getChildElement().createCopy());
                            reply.setError(PacketError.Condition.not_acceptable);
                            return reply;
                        }
                    }
                } else {
                    // If inband registration is not allowed, return an error.
                    if (!registrationEnabled) {
                        reply = IQ.createResultIQ(packet);
                        reply.setChildElement(packet.getChildElement().createCopy());
                        reply.setError(PacketError.Condition.forbidden);
                        return reply;
                    } else // information was not provided
                    if (password == null || password.trim().length() == 0) {
                        reply = IQ.createResultIQ(packet);
                        reply.setChildElement(packet.getChildElement().createCopy());
                        reply.setError(PacketError.Condition.not_acceptable);
                        return reply;
                    } else {
                        // Create the new account
                        newUser = userManager.createUser(username, password, name, email);
                    }
                }
                // Set and save the extra user info (e.g. full name, etc.)
                if (newUser != null && name != null && !name.equals(newUser.getName())) {
                    newUser.setName(name);
                }
                reply = IQ.createResultIQ(packet);
            }
        } catch (UserAlreadyExistsException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.conflict);
        } catch (UserNotFoundException e) {
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.bad_request);
        } catch (StringprepException e) {
            // The specified username is not correct according to the stringprep specs
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.jid_malformed);
        } catch (IllegalArgumentException e) {
            // At least one of the fields passed in is not valid
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.not_acceptable);
            Log.warn(e.getMessage(), e);
        } catch (UnsupportedOperationException e) {
            // The User provider is read-only so this operation is not allowed
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.not_allowed);
        } catch (Exception e) {
            // Some unexpected error happened so return an internal_server_error
            reply = IQ.createResultIQ(packet);
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setError(PacketError.Condition.internal_server_error);
            Log.error(e.getMessage(), e);
        }
    }
    if (reply != null) {
        // why is this done here instead of letting the iq handler do it?
        session.process(reply);
    }
    return null;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) StringprepException(gnu.inet.encoding.StringprepException) PacketException(org.jivesoftware.openfire.PacketException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) StringprepException(gnu.inet.encoding.StringprepException) StreamError(org.xmpp.packet.StreamError) ClientSession(org.jivesoftware.openfire.session.ClientSession) Iterator(java.util.Iterator) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) DataForm(org.xmpp.forms.DataForm) List(java.util.List) FormField(org.xmpp.forms.FormField)

Aggregations

FormField (org.xmpp.forms.FormField)76 DataForm (org.xmpp.forms.DataForm)67 Element (org.dom4j.Element)16 JID (org.xmpp.packet.JID)12 ArrayList (java.util.ArrayList)9 IQ (org.xmpp.packet.IQ)7 ClientSession (org.jivesoftware.openfire.session.ClientSession)6 Date (java.util.Date)4 List (java.util.List)4 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 Group (org.jivesoftware.openfire.group.Group)3 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)3 ParseException (java.text.ParseException)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 PacketException (org.jivesoftware.openfire.PacketException)2 GroupJID (org.jivesoftware.openfire.group.GroupJID)2 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)2 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)2