Commit ab861462 authored by csh's avatar csh

OF-725 OF should return error if a message stanza is blocked

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13989 b35dd754-fafc-0310-a699-88a17e54d16e
parent f2485476
...@@ -35,6 +35,7 @@ import org.jivesoftware.openfire.interceptor.PacketRejectedException; ...@@ -35,6 +35,7 @@ import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.privacy.PrivacyList; import org.jivesoftware.openfire.privacy.PrivacyList;
import org.jivesoftware.openfire.privacy.PrivacyListManager; import org.jivesoftware.openfire.privacy.PrivacyListManager;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.LocalClientSession;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.openfire.user.UserManager; import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
...@@ -376,9 +377,29 @@ public class IQRouter extends BasicModule { ...@@ -376,9 +377,29 @@ public class IQRouter extends BasicModule {
} }
} }
else { else {
// JID is of the form <node@domain/resource> or belongs to a remote server ClientSession session = sessionManager.getSession(packet.getFrom());
// or to an uninstalled component boolean isAcceptable = true;
routingTable.routePacket(recipientJID, packet, false); if (session instanceof LocalClientSession) {
// Check if we could process IQ stanzas from the recipient.
// If not, return a not-acceptable error as per XEP-0016:
// If the user attempts to send an outbound stanza to a contact and that stanza type is blocked, the user's server MUST NOT route the stanza to the contact but instead MUST return a <not-acceptable/> error
IQ dummyIQ = packet.createCopy();
dummyIQ.setFrom(packet.getTo());
dummyIQ.setTo(packet.getFrom());
if (!((LocalClientSession) session).canProcess(dummyIQ)) {
packet.setTo(session.getAddress());
packet.setFrom((JID) null);
packet.setError(PacketError.Condition.not_acceptable);
session.process(packet);
isAcceptable = false;
}
}
if (isAcceptable) {
// JID is of the form <node@domain/resource> or belongs to a remote server
// or to an uninstalled component
routingTable.routePacket(recipientJID, packet, false);
}
} }
} }
catch (Exception e) { catch (Exception e) {
......
...@@ -25,8 +25,11 @@ package org.jivesoftware.openfire; ...@@ -25,8 +25,11 @@ package org.jivesoftware.openfire;
import org.jivesoftware.openfire.container.BasicModule; import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.interceptor.InterceptorManager; import org.jivesoftware.openfire.interceptor.InterceptorManager;
import org.jivesoftware.openfire.interceptor.PacketRejectedException; import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.session.ClientSession; import org.jivesoftware.openfire.privacy.PrivacyList;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.privacy.PrivacyListManager;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.LocalClientSession;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.openfire.user.UserManager; import org.jivesoftware.openfire.user.UserManager;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -109,13 +112,30 @@ public class MessageRouter extends BasicModule { ...@@ -109,13 +112,30 @@ public class MessageRouter extends BasicModule {
return; return;
} }
try { boolean isAcceptable = true;
// Deliver stanza to requested route if (session instanceof LocalClientSession) {
routingTable.routePacket(recipientJID, packet, false); // Check if we could process messages from the recipient.
// If not, return a not-acceptable error as per XEP-0016:
// If the user attempts to send an outbound stanza to a contact and that stanza type is blocked, the user's server MUST NOT route the stanza to the contact but instead MUST return a <not-acceptable/> error
Message dummyMessage = packet.createCopy();
dummyMessage.setFrom(packet.getTo());
dummyMessage.setTo(packet.getFrom());
if (!((LocalClientSession) session).canProcess(dummyMessage)) {
packet.setTo(session.getAddress());
packet.setFrom((JID)null);
packet.setError(PacketError.Condition.not_acceptable);
session.process(packet);
isAcceptable = false;
}
} }
catch (Exception e) { if (isAcceptable) {
log.error("Failed to route packet: " + packet.toXML(), e); try {
routingFailed(recipientJID, packet); // Deliver stanza to requested route
routingTable.routePacket(recipientJID, packet, false);
} catch (Exception e) {
log.error("Failed to route packet: " + packet.toXML(), e);
routingFailed(recipientJID, packet);
}
} }
} }
else { else {
......
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