<p>Some XMPP features must be offered by the server itself, or can't be available, that's the case of &xep0163; which is used in several places (e.g. bookmarks storage). But it can be desirable to use an external entity to manage some of these features, because it implements things that the server don't, or because it uses a special implementation useful in a particular case. Some people may also want to decentralize a feature on an entity under their control. This XEP try to solve these cases.<br/>Additionaly, a method to do generic treatments (independent of server) on stanza is also provided.</p>
<p>Here are some use cases of namespace delegation:</p>
<ul>
<li>use an external component for a PEP service because the server doesn't implement it or lacks some features</li>
<li>decentralize a server feature to an entity under client control</li>
<li>make a component which react on new user registration, independent of server implementation</li>
<li>server agnostic roster filtering</li>
</ul>
</section1>
<section1topic='Requirements'anchor='reqs'>
<p>Namespace delegation can be used in two modes:</p>
<ul>
<li><strong>admin</strong> mode, where delegation is specified by the server administrator.</li>
<li><strong>client</strong> mode, where it can be requested by any user.</li>
</ul>
<p>In <em>admin</em> mode, the managing entity manages stanza of the delegated namespace for all users registered on the server. The namespace delegation MUST be totally transparent for the managed entities.</p>
<p>In <em>client</em> mode, a managing entity MUST have an explicit authorization for any namespace he wants to use. Client SHOULD be able to check and revoke granted permissions, and if it's not possible, permissions MUST be revoked after a disconnection.</p>
</section1>
<section1topic='Glossary'anchor='glossary'>
<ul>
<li><strong>Delegated namespace</strong> — the namespace being managed by an external entity.</li>
<p>Once the managing entity is authenticated and stream is started, the server send it a &MESSAGE; stanza with a <delegation/> elements which MUST have the <strong>'urn:xmpp:delegation:1'</strong> namespace. This element contains <delegated/> elements which MUST contain a 'namespace' attribute indicating the delegated namespace. If there is additional attribute filtering, the <delegated/> can have children <attribute/> elements which MUST contain a 'name' attribute with the name of the filtering attribute.</p>
<p>Here <em>pubsub.capulet.lit</em> will received all stanzas of pubsub namespace sent to <em>capulet.lit</em>. It will also receive MAM stanzas, but only if the 'node' attribute is present in &QUERY;.</p>
<p>When a server receives a stanza for a delegated namespace which is either directed to him (no 'to' attribute, or 'to' attribute with its own JID), or directed to any bare jid (and only bare jid) that it manages (i.e. the <em>domainpart</em> is a domain handled by the server where delegation is activated), it MUST forwards it to the managing entity:</p>
<p>To forward, an &IQ; stanza of type "set" is used which contain a <delegation/> element (with namespace <em>'urn:xmpp:delegation:1'</em>) which in turn contain a <forwarded/> element encapsulating the initial stanza, according to &xep0297;:</p>
<p>Then the server MUST decapsulate the &IQ; result, MUST insure that the 'to' and the 'from' attribute corresponds to respectively the 'from' and the 'to' attributes of the initial stanza, MUST insure that the 'id' attribute of the decapsulated stanza is the same as the initial 'id' attribute and that 'type' is "result". If everything is alright, it can send the decapsulated stanza to Juliet.</p>
<p>If the forwarded result from managing entity is bad (i.e. wrong 'to', 'from', 'id' or 'result' attributes), the server MUST send an &IQ; error with condition <service-unavailable/> to managed entity, and MAY close the connexion with managing entity.</p>
<p><strong>N.B.₁:</strong> If the server encounter a delegated namespace and the managing entity is not available, it MUST return an &IQ; stanza of type "error" with an error condition of <service-unavailable/></p>
<p><strong>N.B.₂:</strong> Similarly, if the managing entity return an &IQ; stanza of type "error", the server must return itself an &IQ; stanza of type "error" with an error condition of <service-unavailable/></p>
<p><strong>N.B.₃:</strong> If the server encounter a delegated namespace but the filtering attribute does not match, it MUST follow its normal behaviour, i.e. it must follow the same behaviour it would have had if the namespace was not delegated at all</p>
<p>If a stanza is sent by the managing entity on a managed namespace, the server MUST NOT forward it. This way, the managing entity can use privileged entity to do specific treatments, a kind of universal plugin (i.e. working with all servers implementing &xep0355; and &xep0356;).</p>
<p>In the following examples, <em>juliet@capulet.lit</em> has its "<em>jabber:iq:roster</em>" namespace delegated to <em>filter.capulet.lit</em>. <em>filter.capulet.lit</em> is a server agnostic component which filters allowed entities (which can be added to a roster), and sort them in enforced groups.</p>
<examplecaption='Juliet adds Romeo to her roster'><![CDATA[
<iqfrom='juliet@capulet.lit/balcony'
id='roster1'
type='set'>
<queryxmlns='jabber:iq:roster'>
<itemjid='romeo@montaigu.lit'
name='My Romeo'>
</item>
</query>
</iq>
]]></example>
<examplecaption='server forwards stanza to managing entity'><![CDATA[
<p><em>filter.capulet.lit</em> accepts to add Romeo, but all JIDs with a <em>montaigu.lit</em> must be in a "Rivals" group, so it first returns a success result (Romeo is accepted).</p>
<p>At this stade, the entity is accepted, but not added to the roster. <em>filter.capulet.lit</em> is also a privileged entity which can manage "<em>jabber:iq:roster</em>", so it uses this ability to add Romeo in the enforced group:</p>
<p>The namespace is delegated, but as the stanza is from the managing entity, the server manages it normally. The entity is also privileged, so it can change the stanza of Juliet, the server accepts:</p>
<p>In <em>client</em> mode, the managing entity is not certified by the server administrator, so the delegation MUST be <strong>explicitly</strong> allowed by the managed entity. This is initiated by the managing entity (it can be after an interaction with a managed entity, like a subscription).</p>
<p>To request delegation for a particular entity, the managing entity MUST have an &IQ; stanza with <em>'urn:xmpp:delegation:1'</em> namespace. The &QUERY; element MUST have a 'to' attribute which specify the entity it wants to manage.</p>
<p>Namespace delegations are asked with a <delegate/> element, which MUST contain a 'namespace' attribute set to the requested namespace.</p>
<p>Once received the delegation request, the server ask to the client if it grants access to the requested namespace using &xep0004;. The server use a challenge which it MUST have generated itself.
<p>The server SHOULD include a warning message, SHOULD translate the namespace to human friendly names (and MAY keep the original namespace in addition) and MUST set the default value to '<strong>0</strong>' (permission refused). The server MUST use namespaces as field var, so a client can use them to have a customized display.</p>
<p>Finaly, the server notifies the entity of the granted delegation. It do this in the same way as for <linkurl='#admin_perm'>admin mode</link>, except that the <delegation/> element has an attitional 'to' attribute set to the managed entity bare jid:</p>
<examplecaption='server advertise delegated namespaces for juliet'><![CDATA[
<p>The managing entity can now manage the namespace in a similar way as in <linkurl='#stanza_forward'>admin mode</link> but with different rules:</p>
<ol>
<li>if the stanza is directed to the delegating server (no 'to' attribute, or 'to' attribute with the server own JID), <strong>and</strong> the 'from' attribute belong to a managed entity (e.g. <em>juliet@capulet.lit/balcony</em> if <em>juliet@capulet.lit</em> is a managed entity) <strong>and</strong> the namespace of the stanza has been delegated by the managed entity, then the delegating server MUST forward it to the managing entity accepted by the managed entity, in the same way as in <linkurl='#stanza_forward'>admin mode</link>.</li>
<li>if the stanza is directed to the bare jid (and only the bare jid) of the managed entity (e.g. the 'to' attribute is set to <em>juliet@capulet.lit</em> and the namespace has been delegated by the managed entity, then the server MUST forward it to the managing entity accepted by the managed entity, in the same way as in <linkurl='#stanza_forward'>admin mode</link>, for any 'from' attribute but the jid of the managing entity.</li>
<li>in all other cases, the server MUST NOT forward the stanza</li>
<p>Server SHOULD provide a way for clients to check already delegated namespaces, and revoke them by using &xep0050; on the well-defined command node <strong>'urn:xmpp:delegation:1#configure'</strong>.</p>
<p>If present, the configuration commands MUST allow at least to check delegations granted to a managing entity, and to revoke them. A server MAY offer an option to keep delegations from one session to an other (see <linkurl='#rules'>business rules</link>).</p>
<p>If a server or an entity supports the namespace delegation protocol, it MUST report that fact by including a service discovery feature of "<em>urn:xmpp:delegation:1</em>" in response to a &xep0030; information request:</p>
<p>When a server delegates a namespace to a managing entity, the later can have particular features which must be advertised by the former with disco protocol.</p>
<p>This is done by using a disco node, which is built in the following way: if pubsub.capulet.int manages pubsub namespace, it MUST report that fact in discovery feature, and have a '<strong>urn:xmpp:delegation:1::http://jabber.org/protocol/pubsub</strong>' node which reports the managed features.</p><p>The node name is obtained by concatenating this XEP namespace (<strong>urn:xmpp:delegation:1</strong>), a '<strong>::</strong>' separator, and the delegated namespace (here <strong>http://jabber.org/protocol/pubsub</strong>).<br/>The server MUST advertise the result in its own discovery answer, and MUST ignore features of its internal component (here internal PubSub service).</p>
<p>In the following example, the capulet.int server delegates its internal PEP component to pubsub.capulet.int. capulet.int only supports REQUIRED PubSub features and auto-create, while pubsub.capulet.int supports REQUIRED PubSub features and publish-options, but not auto-create. <br/>juliet@capulet.int asks its server what it is capable of, she is specially interested in PubSub capabilities.</p>
<examplecaption="Juliet asks her server its available features"><![CDATA[
<p><strong>N.B.:</strong> In the special case of attribute filtering, the server still display managing entity's features for the whole delegated namespace instead of its own internal ones.</p>
<section3topic='Rediction Of Bare JID Disco Info'>
<p>As an entity may ask for discovery information on bare JID, which the server would answer, the managing entity must be able to send this kind of information.</p>
<p>To do so, the mechanism is the same as for server features, but the separator is '<strong>:bare:</strong>' instead of '<strong>::</strong>':</p>
<examplecaption="Juliet asks features for its own bare JID"><![CDATA[
<p>Extensions of Service Discovery as specified in &xep0128; follow the same rules: for the delegated namespace, internal extensions MUST be removed and extensions of managing entity MUST be included instead.</p>
<li>In client mode, server MAY keep delegations granted to an entity by a client from one session to an other, but if it does so, it MUST provide configuration like explained in the <linkurl='#configuration'>suitable section</link>. If server offers this feature, it SHOULD add a field directly in configuration commands.</li>
<li>If a client can't check or revoke delegations (i.e. it doesn't support &xep0050;) when granting them, the server MUST NOT keep granted delegations from one session to an other, and delegations will be asked on each new session.</li>
<li>If delegations are changed during a session, server MUST notify managing entity of the new delegations, like in <linkurl='#client_delegation'>client delegation request use case</link>.</li>
<li>If delegations are kept between sessions in client mode, and the managing entity is not available or return an error, the server MUST return an &IQ; error with condition <service-unavailable/> when a delegated namespace is requested, like explained in <linkurl='#stanza_forward'>"Server Forwards Delegated &IQ; Stanza" section</link>.</li>
<li>The namespace of this XEP (<strong>urn:xmpp:delegation:1</strong>) MUST NOT be delegated. If an entity requests it, the server MUST return a &forbidden; error.</li>
<li>As admin mode is far more easy to implement than client mode, and client mode may impact performances, a server MAY choose to only implement the former.</li>
<li>Because of the performance impact, a server SHOULD ask for <linkurl='#disco_nesting'>disco features to nest</link> to managing entity when delegation is accepted, and keep them in cache.</li>
<li>&rfc6120; section 10.1 require in-order processing of stanzas, which may be problematic for this extension: either the server blocks the traffic until the managing entity answer - which can lead to severe performance impact -, or the server doesn't block and may loose order. The recommended way is to not block the traffic while waiting for managing entity answer to avoid performance issues. A future version of this XEP may include an attribute to request traffic blocking. In admin mode the server implementation MAY chooses to have a blocking option (which SHOULD be per namespace, not global).
<li>Managing entity can manage sensitive data, <em>admin</em> delegation should be granted carefuly, only if you absolutely trust the entity.</li>
<li>A server MAY choose to filter allowed namespaces. In this case, it MUST always set the allowed type of filtered namespaces to <strong>0</strong>.</li>
<li>In case of filtering, a whitelist system is more secure and SHOULD be prefered to a blacklist (idealy, configuration would allow no filtering, whitelist filtering and blacklist filtering).</li>