Commit 2c6154d1 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Improved logic to detect JIDs of remote servers. JM-355


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1722 b35dd754-fafc-0310-a699-88a17e54d16e
parent a273c81a
...@@ -85,6 +85,7 @@ public class XMPPServer { ...@@ -85,6 +85,7 @@ public class XMPPServer {
private ClassLoader loader; private ClassLoader loader;
private PluginManager pluginManager; private PluginManager pluginManager;
private InternalComponentManager componentManager;
/** /**
* True if in setup mode * True if in setup mode
...@@ -131,8 +132,10 @@ public class XMPPServer { ...@@ -131,8 +132,10 @@ public class XMPPServer {
/** /**
* Returns true if the given address is local to the server (managed by this * Returns true if the given address is local to the server (managed by this
* server domain). * server domain). Return false even if the jid's domain matches a local component's
* service JID.
* *
* @param jid the JID to check.
* @return true if the address is a local address to this server. * @return true if the address is a local address to this server.
*/ */
public boolean isLocal(JID jid) { public boolean isLocal(JID jid) {
...@@ -143,6 +146,24 @@ public class XMPPServer { ...@@ -143,6 +146,24 @@ public class XMPPServer {
return local; return local;
} }
/**
* Returns true if the given address does not match the local server hostname and does not
* match a component service JID.
*
* @param jid the JID to check.
* @return true if the given address does not match the local server hostname and does not
* match a component service JID.
*/
public boolean isRemote(JID jid) {
if (jid != null) {
String domain = jid.getDomain();
if (!name.equals(domain) && componentManager.getComponent(domain) == null) {
return true;
}
}
return false;
}
/** /**
* Creates an XMPPAddress local to this server. * Creates an XMPPAddress local to this server.
* *
...@@ -175,6 +196,7 @@ public class XMPPServer { ...@@ -175,6 +196,7 @@ public class XMPPServer {
} }
loader = Thread.currentThread().getContextClassLoader(); loader = Thread.currentThread().getContextClassLoader();
componentManager = InternalComponentManager.getInstance();
initialized = true; initialized = true;
} }
......
...@@ -11,13 +11,13 @@ ...@@ -11,13 +11,13 @@
package org.jivesoftware.messenger.net; package org.jivesoftware.messenger.net;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.*; import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.xmpp.packet.Packet; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
/** /**
...@@ -28,9 +28,9 @@ import org.xmpp.packet.Presence; ...@@ -28,9 +28,9 @@ import org.xmpp.packet.Presence;
*/ */
public class SocketPacketWriteHandler implements ChannelHandler { public class SocketPacketWriteHandler implements ChannelHandler {
private XMPPServer server;
private SessionManager sessionManager; private SessionManager sessionManager;
private OfflineMessageStrategy messageStrategy; private OfflineMessageStrategy messageStrategy;
private String serverName = XMPPServer.getInstance().getServerInfo().getName();
private RoutingTable routingTable; private RoutingTable routingTable;
public SocketPacketWriteHandler(SessionManager sessionManager, RoutingTable routingTable, public SocketPacketWriteHandler(SessionManager sessionManager, RoutingTable routingTable,
...@@ -38,13 +38,14 @@ public class SocketPacketWriteHandler implements ChannelHandler { ...@@ -38,13 +38,14 @@ public class SocketPacketWriteHandler implements ChannelHandler {
this.sessionManager = sessionManager; this.sessionManager = sessionManager;
this.messageStrategy = messageStrategy; this.messageStrategy = messageStrategy;
this.routingTable = routingTable; this.routingTable = routingTable;
this.server = XMPPServer.getInstance();
} }
public void process(Packet packet) throws UnauthorizedException, PacketException { public void process(Packet packet) throws UnauthorizedException, PacketException {
try { try {
JID recipient = packet.getTo(); JID recipient = packet.getTo();
// Check if the target domain belongs to a remote server // Check if the target domain belongs to a remote server
if (recipient != null && !recipient.getDomain().contains(serverName)) { if (server.isRemote(recipient)) {
try { try {
// Locate the route to the remote server and ask it to process the packet // Locate the route to the remote server and ask it to process the packet
routingTable.getRoute(recipient).process(packet); routingTable.getRoute(recipient).process(packet);
......
...@@ -305,9 +305,10 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -305,9 +305,10 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
component.processPacket(presence); component.processPacket(presence);
} }
else { else {
String serverDomain = server.getServerInfo().getName();
// Check if the probee may be hosted by this server // Check if the probee may be hosted by this server
if (!probee.getDomain().contains(serverDomain)) { /*String serverDomain = server.getServerInfo().getName();
if (!probee.getDomain().contains(serverDomain)) {*/
if (server.isRemote(probee)) {
// Send the probe presence to the remote server // Send the probe presence to the remote server
Presence probePresence = new Presence(); Presence probePresence = new Presence();
probePresence.setType(Presence.Type.probe); probePresence.setType(Presence.Type.probe);
......
...@@ -94,7 +94,7 @@ public class PresencePlugin implements Plugin { ...@@ -94,7 +94,7 @@ public class PresencePlugin implements Plugin {
public Presence getPresence(String sender, String jid) throws UserNotFoundException { public Presence getPresence(String sender, String jid) throws UserNotFoundException {
JID targetJID = new JID(jid); JID targetJID = new JID(jid);
// Check that the sender is not requesting information of a remote server entity // Check that the sender is not requesting information of a remote server entity
if (targetJID.getDomain() == null || !targetJID.getDomain().contains(hostname)) { if (targetJID.getDomain() == null || XMPPServer.getInstance().isRemote(targetJID)) {
throw new UserNotFoundException("Domain does not matches local server domain"); throw new UserNotFoundException("Domain does not matches local server domain");
} }
if (!hostname.equals(targetJID.getDomain())) { if (!hostname.equals(targetJID.getDomain())) {
......
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