Commit c502109a authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Forward messages sent to the server hostname to a configurable set of JID's. JM-312


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1557 b35dd754-fafc-0310-a699-88a17e54d16e
parent bf21e9ae
...@@ -11,12 +11,15 @@ ...@@ -11,12 +11,15 @@
package org.jivesoftware.messenger; package org.jivesoftware.messenger;
import org.xmpp.packet.Message;
import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError;
import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.PacketError;
import java.util.StringTokenizer;
/** /**
* <p>Route message packets throughout the server.</p> * <p>Route message packets throughout the server.</p>
...@@ -33,6 +36,8 @@ public class MessageRouter extends BasicModule { ...@@ -33,6 +36,8 @@ public class MessageRouter extends BasicModule {
private RoutingTable routingTable; private RoutingTable routingTable;
private SessionManager sessionManager; private SessionManager sessionManager;
private String serverName;
/** /**
* Constructs a message router. * Constructs a message router.
*/ */
...@@ -63,6 +68,14 @@ public class MessageRouter extends BasicModule { ...@@ -63,6 +68,14 @@ public class MessageRouter extends BasicModule {
{ {
JID recipientJID = packet.getTo(); JID recipientJID = packet.getTo();
// If the message was sent to the server hostname then forward the message to
// a configurable set of JID's (probably admin users)
if (recipientJID.getNode() == null && recipientJID.getResource() == null &&
serverName.equals(recipientJID.getDomain())) {
sendMessageToAdmins(packet);
return;
}
try { try {
routingTable.getBestRoute(recipientJID).process(packet); routingTable.getBestRoute(recipientJID).process(packet);
} }
...@@ -89,10 +102,54 @@ public class MessageRouter extends BasicModule { ...@@ -89,10 +102,54 @@ public class MessageRouter extends BasicModule {
} }
} }
/**
* Forwards the received message to the list of users defined in the property
* <b>xmpp.forward.admins</b>. The property may include bare JIDs or just usernames separated
* by commas or black spaces. When using bare JIDs the target user may belong to a remote
* server.<p>
*
* If the property <b>xmpp.forward.admins</b> was not defined then the message will be sent
* to all the users allowed to enter the admin console.
*
* @param packet the message to forward.
*/
private void sendMessageToAdmins(Message packet) {
String jids = JiveGlobals.getProperty("xmpp.forward.admins");
if (jids != null && jids.trim().length() > 0) {
// Forward the message to the users specified in the "xmpp.forward.admins" property
StringTokenizer tokenizer = new StringTokenizer(jids, ", ");
while (tokenizer.hasMoreTokens()) {
String username = tokenizer.nextToken();
Message forward = packet.createCopy();
if (username.contains("@")) {
// Use the specified bare JID address as the target address
forward.setTo(username);
}
else {
forward.setTo(username + "@" + serverName);
}
route(forward);
}
}
else {
// Forward the message to the users allowed to log into the admin console
jids = JiveGlobals.getXMLProperty("adminConsole.authorizedUsernames");
jids = (jids == null || jids.trim().length() == 0) ? "admin" : jids;
StringTokenizer tokenizer = new StringTokenizer(jids, ",");
while (tokenizer.hasMoreTokens()) {
String username = tokenizer.nextToken();
Message forward = packet.createCopy();
forward.setTo(username + "@" + serverName);
route(forward);
}
}
}
public void initialize(XMPPServer server) { public void initialize(XMPPServer server) {
super.initialize(server); super.initialize(server);
messageStrategy = server.getOfflineMessageStrategy(); messageStrategy = server.getOfflineMessageStrategy();
routingTable = server.getRoutingTable(); routingTable = server.getRoutingTable();
sessionManager = server.getSessionManager(); sessionManager = server.getSessionManager();
serverName = server.getServerInfo().getName();
} }
} }
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