Search in sources :

Example 26 with FormField

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

the class IQRegisterHandler method initialize.

@Override
public void initialize(XMPPServer server) {
    super.initialize(server);
    userManager = server.getUserManager();
    rosterManager = server.getRosterManager();
    if (probeResult == null) {
        // Create the basic element of the probeResult which contains the basic registration
        // information (e.g. username, passoword and email)
        probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register"));
        probeResult.addElement("username");
        probeResult.addElement("password");
        probeResult.addElement("email");
        probeResult.addElement("name");
        // Create the registration form to include in the probeResult. The form will include
        // the basic information plus name and visibility of name and email.
        // TODO Future versions could allow plugin modules to add new fields to the form 
        final DataForm registrationForm = new DataForm(DataForm.Type.form);
        registrationForm.setTitle("XMPP Client Registration");
        registrationForm.addInstruction("Please provide the following information");
        final FormField fieldForm = registrationForm.addField();
        fieldForm.setVariable("FORM_TYPE");
        fieldForm.setType(FormField.Type.hidden);
        fieldForm.addValue("jabber:iq:register");
        final FormField fieldUser = registrationForm.addField();
        fieldUser.setVariable("username");
        fieldUser.setType(FormField.Type.text_single);
        fieldUser.setLabel("Username");
        fieldUser.setRequired(true);
        final FormField fieldName = registrationForm.addField();
        fieldName.setVariable("name");
        fieldName.setType(FormField.Type.text_single);
        fieldName.setLabel("Full name");
        if (UserManager.getUserProvider().isNameRequired()) {
            fieldName.setRequired(true);
        }
        final FormField fieldMail = registrationForm.addField();
        fieldMail.setVariable("email");
        fieldMail.setType(FormField.Type.text_single);
        fieldMail.setLabel("Email");
        if (UserManager.getUserProvider().isEmailRequired()) {
            fieldMail.setRequired(true);
        }
        final FormField fieldPwd = registrationForm.addField();
        fieldPwd.setVariable("password");
        fieldPwd.setType(FormField.Type.text_private);
        fieldPwd.setLabel("Password");
        fieldPwd.setRequired(true);
        // Add the registration form to the probe result.
        probeResult.add(registrationForm.getElement());
    }
    JiveGlobals.migrateProperty("register.inband");
    JiveGlobals.migrateProperty("register.password");
    // See if in-band registration should be enabled (default is true).
    registrationEnabled = JiveGlobals.getBooleanProperty("register.inband", true);
    // See if users can change their passwords (default is true).
    canChangePassword = JiveGlobals.getBooleanProperty("register.password", true);
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 27 with FormField

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

the class IQOfflineMessagesHandler method getExtendedInfo.

@Override
public DataForm getExtendedInfo(String name, String node, JID senderJID) {
    // Mark that offline messages shouldn't be sent when the user becomes available
    stopOfflineFlooding(senderJID);
    final DataForm dataForm = new DataForm(DataForm.Type.result);
    final FormField field1 = dataForm.addField();
    field1.setVariable("FORM_TYPE");
    field1.setType(FormField.Type.hidden);
    field1.addValue(NAMESPACE);
    final FormField field2 = dataForm.addField();
    field2.setVariable("number_of_messages");
    field2.addValue(String.valueOf(messageStore.getMessages(senderJID.getNode(), false).size()));
    return dataForm;
}
Also used : DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 28 with FormField

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

the class IQPEPHandler method createSubscriptionToPEPService.

/**
     * Generates and processes an IQ stanza that subscribes to a PEP service.
     *
     * @param pepService the PEP service of the owner.
     * @param subscriber the JID of the entity that is subscribing to the PEP service.
     * @param owner      the JID of the owner of the PEP service.
     */
private void createSubscriptionToPEPService(PEPService pepService, JID subscriber, JID owner) {
    // If `owner` has a PEP service, generate and process a pubsub subscription packet
    // that is equivalent to: (where 'from' field is JID of subscriber and 'to' field is JID of owner)
    //
    //        <iq type='set'
    //            from='nurse@capulet.com/chamber'
    //            to='juliet@capulet.com
    //            id='collsub'>
    //          <pubsub xmlns='http://jabber.org/protocol/pubsub'>
    //            <subscribe jid='nurse@capulet.com'/>
    //            <options>
    //              <x xmlns='jabber:x:data'>
    //                <field var='FORM_TYPE' type='hidden'>
    //                  <value>http://jabber.org/protocol/pubsub#subscribe_options</value>
    //                </field>
    //                <field var='pubsub#subscription_type'>
    //                  <value>items</value>
    //                </field>
    //                <field var='pubsub#subscription_depth'>
    //                  <value>all</value>
    //                </field>
    //              </x>
    //           </options>
    //         </pubsub>
    //        </iq>
    IQ subscriptionPacket = new IQ(IQ.Type.set);
    subscriptionPacket.setFrom(subscriber);
    subscriptionPacket.setTo(owner.toBareJID());
    Element pubsubElement = subscriptionPacket.setChildElement("pubsub", "http://jabber.org/protocol/pubsub");
    Element subscribeElement = pubsubElement.addElement("subscribe");
    subscribeElement.addAttribute("jid", subscriber.toBareJID());
    Element optionsElement = pubsubElement.addElement("options");
    Element xElement = optionsElement.addElement(QName.get("x", "jabber:x:data"));
    DataForm dataForm = new DataForm(xElement);
    FormField formField = dataForm.addField();
    formField.setVariable("FORM_TYPE");
    formField.setType(FormField.Type.hidden);
    formField.addValue("http://jabber.org/protocol/pubsub#subscribe_options");
    formField = dataForm.addField();
    formField.setVariable("pubsub#subscription_type");
    formField.addValue("items");
    formField = dataForm.addField();
    formField.setVariable("pubsub#subscription_depth");
    formField.addValue("all");
    pepServiceManager.process(pepService, subscriptionPacket);
}
Also used : Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 29 with FormField

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

the class LeafNode method addFormFields.

@Override
protected void addFormFields(DataForm form, boolean isEditing) {
    super.addFormFields(form, isEditing);
    FormField typeField = form.getField("pubsub#node_type");
    typeField.addValue("leaf");
    FormField formField = form.addField();
    formField.setVariable("pubsub#send_item_subscribe");
    if (isEditing) {
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.send_item_subscribe"));
    }
    formField.addValue(sendItemSubscribe);
    formField = form.addField();
    formField.setVariable("pubsub#persist_items");
    if (isEditing) {
        formField.setType(FormField.Type.boolean_type);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.persist_items"));
    }
    formField.addValue(persistPublishedItems);
    formField = form.addField();
    formField.setVariable("pubsub#max_items");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.max_items"));
    }
    formField.addValue(maxPublishedItems);
    formField = form.addField();
    formField.setVariable("pubsub#max_payload_size");
    if (isEditing) {
        formField.setType(FormField.Type.text_single);
        formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.max_payload_size"));
    }
    formField.addValue(maxPayloadSize);
}
Also used : FormField(org.xmpp.forms.FormField)

Example 30 with FormField

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

the class Node method configure.

/**
     * Changes the node configuration based on the completed data form. Only owners or
     * sysadmins are allowed to change the node configuration. The completed data form
     * cannot remove all node owners. An exception is going to be thrown if the new form
     * tries to leave the node without owners.
     *
     * @param completedForm the completed data form.
     * @throws NotAcceptableException if completed data form tries to leave the node without owners.
     */
public void configure(DataForm completedForm) throws NotAcceptableException {
    boolean wasPresenceBased = isPresenceBasedDelivery();
    if (DataForm.Type.cancel.equals(completedForm.getType())) {
    // Existing node configuration is applied (i.e. nothing is changed)
    } else if (DataForm.Type.submit.equals(completedForm.getType())) {
        List<String> values;
        String booleanValue;
        // Get the new list of owners
        FormField ownerField = completedForm.getField("pubsub#owner");
        boolean ownersSent = ownerField != null;
        List<JID> owners = new ArrayList<>();
        if (ownersSent) {
            for (String value : ownerField.getValues()) {
                try {
                    owners.add(new JID(value));
                } catch (Exception e) {
                // Do nothing
                }
            }
        }
        // Answer a not-acceptable error if all the current owners will be removed
        if (ownersSent && owners.isEmpty()) {
            throw new NotAcceptableException();
        }
        for (FormField field : completedForm.getFields()) {
            if ("FORM_TYPE".equals(field.getVariable())) {
            // Do nothing
            } else if ("pubsub#deliver_payloads".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                deliverPayloads = "1".equals(booleanValue);
            } else if ("pubsub#notify_config".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                notifyConfigChanges = "1".equals(booleanValue);
            } else if ("pubsub#notify_delete".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                notifyDelete = "1".equals(booleanValue);
            } else if ("pubsub#notify_retract".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                notifyRetract = "1".equals(booleanValue);
            } else if ("pubsub#presence_based_delivery".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                presenceBasedDelivery = "1".equals(booleanValue);
            } else if ("pubsub#subscribe".equals(field.getVariable())) {
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                subscriptionEnabled = "1".equals(booleanValue);
            } else if ("pubsub#subscription_required".equals(field.getVariable())) {
                // TODO Replace this variable for the one defined in the JEP (once one is defined)
                values = field.getValues();
                booleanValue = (values.size() > 0 ? values.get(0) : "1");
                subscriptionConfigurationRequired = "1".equals(booleanValue);
            } else if ("pubsub#type".equals(field.getVariable())) {
                values = field.getValues();
                payloadType = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#body_xslt".equals(field.getVariable())) {
                values = field.getValues();
                bodyXSLT = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#dataform_xslt".equals(field.getVariable())) {
                values = field.getValues();
                dataformXSLT = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#access_model".equals(field.getVariable())) {
                values = field.getValues();
                if (values.size() > 0) {
                    accessModel = AccessModel.valueOf(values.get(0));
                }
            } else if ("pubsub#publish_model".equals(field.getVariable())) {
                values = field.getValues();
                if (values.size() > 0) {
                    publisherModel = PublisherModel.valueOf(values.get(0));
                }
            } else if ("pubsub#roster_groups_allowed".equals(field.getVariable())) {
                // Get the new list of roster group(s) allowed to subscribe and retrieve items
                rosterGroupsAllowed = new ArrayList<>();
                for (String value : field.getValues()) {
                    addAllowedRosterGroup(value);
                }
            } else if ("pubsub#contact".equals(field.getVariable())) {
                // Get the new list of users that may be contacted with questions
                contacts = new ArrayList<>();
                for (String value : field.getValues()) {
                    try {
                        addContact(new JID(value));
                    } catch (Exception e) {
                    // Do nothing
                    }
                }
            } else if ("pubsub#description".equals(field.getVariable())) {
                values = field.getValues();
                description = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#language".equals(field.getVariable())) {
                values = field.getValues();
                language = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#title".equals(field.getVariable())) {
                values = field.getValues();
                name = values.size() > 0 ? values.get(0) : " ";
            } else if ("pubsub#itemreply".equals(field.getVariable())) {
                values = field.getValues();
                if (values.size() > 0) {
                    replyPolicy = ItemReplyPolicy.valueOf(values.get(0));
                }
            } else if ("pubsub#replyroom".equals(field.getVariable())) {
                // Get the new list of multi-user chat rooms to specify for replyroom
                replyRooms = new ArrayList<>();
                for (String value : field.getValues()) {
                    try {
                        addReplyRoom(new JID(value));
                    } catch (Exception e) {
                    // Do nothing
                    }
                }
            } else if ("pubsub#replyto".equals(field.getVariable())) {
                // Get the new list of JID(s) to specify for replyto
                replyTo = new ArrayList<>();
                for (String value : field.getValues()) {
                    try {
                        addReplyTo(new JID(value));
                    } catch (Exception e) {
                    // Do nothing
                    }
                }
            } else if ("pubsub#collection".equals(field.getVariable())) {
                // Set the parent collection node
                values = field.getValues();
                String newParent = values.size() > 0 ? values.get(0) : " ";
                Node newParentNode = service.getNode(newParent);
                if (!(newParentNode instanceof CollectionNode)) {
                    throw new NotAcceptableException("Specified node in field pubsub#collection [" + newParent + "] " + ((newParentNode == null) ? "does not exist" : "is not a collection node"));
                }
                changeParent((CollectionNode) newParentNode);
            } else {
                // Let subclasses be configured by specified fields
                configure(field);
            }
        }
        // Set new list of owners of the node
        if (ownersSent) {
            // Calculate owners to remove and remove them from the DB
            Collection<JID> oldOwners = getOwners();
            oldOwners.removeAll(owners);
            for (JID jid : oldOwners) {
                removeOwner(jid);
            }
            // Calculate new owners and add them to the DB
            owners.removeAll(getOwners());
            for (JID jid : owners) {
                addOwner(jid);
            }
        }
        // TODO Before removing owner or admin check if user was changed from admin to owner or vice versa. This way his subscriptions are not going to be deleted.
        // Set the new list of publishers
        FormField publisherField = completedForm.getField("pubsub#publisher");
        if (publisherField != null) {
            // New list of publishers was sent to update publishers of the node
            List<JID> publishers = new ArrayList<>();
            for (String value : publisherField.getValues()) {
                try {
                    publishers.add(new JID(value));
                } catch (Exception e) {
                // Do nothing
                }
            }
            // Calculate publishers to remove and remove them from the DB
            Collection<JID> oldPublishers = getPublishers();
            oldPublishers.removeAll(publishers);
            for (JID jid : oldPublishers) {
                removePublisher(jid);
            }
            // Calculate new publishers and add them to the DB
            publishers.removeAll(getPublishers());
            for (JID jid : publishers) {
                addPublisher(jid);
            }
        }
        // Let subclasses have a chance to finish node configuration based on
        // the completed form
        postConfigure(completedForm);
        // Update the modification date to reflect the last time when the node's configuration
        // was modified
        modificationDate = new Date();
        // Notify subscribers that the node configuration has changed
        nodeConfigurationChanged();
    }
    // Store the new or updated node in the backend store
    saveToDB();
    // Check if we need to subscribe or unsubscribe from affiliate presences
    if (wasPresenceBased != isPresenceBasedDelivery()) {
        if (isPresenceBasedDelivery()) {
            addPresenceSubscriptions();
        } else {
            cancelPresenceSubscriptions();
        }
    }
}
Also used : JID(org.xmpp.packet.JID) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Date(java.util.Date) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) 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