Commit 077ffed0 authored by guus's avatar guus

OF-468: Ensure that JIDS of subscription stanzas are bare.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@12561 b35dd754-fafc-0310-a699-88a17e54d16e
parent e7685d90
...@@ -107,11 +107,39 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand ...@@ -107,11 +107,39 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
} }
public void process(Presence presence) throws PacketException { public void process(Presence presence) throws PacketException {
try { if (presence == null) {
JID senderJID = presence.getFrom(); throw new IllegalArgumentException("Argument 'presence' cannot be null.");
JID recipientJID = presence.getTo(); }
Presence.Type type = presence.getType();
final Presence.Type type = presence.getType();
if (type != Presence.Type.subscribe
&& type != Presence.Type.unsubscribe
&& type != Presence.Type.subscribed
&& type != Presence.Type.unsubscribed) {
throw new IllegalArgumentException("Packet processed by PresenceSubscribeHandler is "
+ "not of a subscription-related type, but: " + type);
}
// RFC-6121 paragraph 3: "When a server processes or generates an outbound presence stanza
// of type "subscribe", "subscribed", "unsubscribe", or "unsubscribed", the server MUST stamp
// the outgoing presence stanza with the bare JID <localpart@domainpart> of the sending entity,
// not the full JID <localpart@domainpart/resourcepart>."
presence.setFrom(presence.getFrom().toBareJID());
// RFC-6121 paragraph 3.1.3: "Before processing the inbound presence subscription request, the
// contact's server SHOULD check the syntax of the JID contained in the 'to' attribute. If the
// JID is of the form <contact@domainpart/resourcepart> instead of <contact@domainpart>, the
// contact's server SHOULD treat it as if the request had been directed to the contact's bare
// JID and modify the 'to' address accordingly.
if (presence.getTo() != null) {
presence.setTo(presence.getTo().toBareJID());
}
final JID senderJID = presence.getFrom();
final JID recipientJID = presence.getTo();
try {
// Reject presence subscription requests sent to the local server itself. // Reject presence subscription requests sent to the local server itself.
if (recipientJID == null || recipientJID.toString().equals(serverName)) { if (recipientJID == null || recipientJID.toString().equals(serverName)) {
if (type == Presence.Type.subscribe) { if (type == Presence.Type.subscribe) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment