Commit af5853ae authored by Axel Brand's avatar Axel Brand Committed by daeva

Some Changes we did in PairProgramming, this is not working yet and will be refactored further

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/plugins@13530 b35dd754-fafc-0310-a699-88a17e54d16e
parent d8e59128
package org.jivesoftware.openfire.plugin.gojara.base;
import java.util.Set;
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.database.DatabaseManager;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.RemoteRosterInterceptor;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.ConcurrentHashSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.Packet;
public class MainInterceptor implements PacketInterceptor {
private static final Logger Log = LoggerFactory
.getLogger(RemoteRosterInterceptor.class);
private Set<String> activeTransports = new ConcurrentHashSet<String>();
private DatabaseManager _db;
private RemoteRosterInterceptor interceptor;
public MainInterceptor() {
Log.debug("Started MainInterceptor");
_db = DatabaseManager.getInstance();
interceptor = new RemoteRosterInterceptor();
}
public void addTransport(String subDomain) {
this.activeTransports.add(subDomain);
Log.debug("Added interceptor for subdomain " + subDomain
+ " to MainInterceptor");
}
public boolean removeTransport(String subDomain) {
if (this.activeTransports.contains(subDomain)) {
this.activeTransports.remove(subDomain);
return true;
}
return false;
}
@Override
public void interceptPacket(Packet packet, Session session,
boolean incoming, boolean processed) throws PacketRejectedException {
String from = packet.getFrom().toString();
String to = packet.getTo().toString();
//TODO: Not intercepting Messages & Presences
if (activeTransports.contains(to) || activeTransports.contains(from)) {
String subdomain = activeTransports.contains(to) ? to : from;
interceptor.interceptPacket(packet, session, incoming, processed, subdomain);
logForStatistic(packet, incoming, processed, to);
}
// // PacketInterceptor interceptor = this.activeTransports.get(to);
// if (interceptor != null) {
// return;
// }
//
// // interceptor = this.activeTransports.get(from);
// if (interceptor != null) {
// interceptor.interceptPacket(packet, session, incoming, processed);
// logForStatistic(packet, incoming, processed, from);
// return;
// }
}
private void logForStatistic(Packet packet, boolean incoming,
boolean processed, String subdomain) {
String from = packet.getFrom().toString();
String to = packet.getTo().toString();
if (from != null && to != null && processed && incoming) {
/*
* Spectrum sends a Ping to itself through the server to check if
* the server is alive. We ignore that for statistics
*/
if (to.toString().equals(from.toString())
&& to.toString().equals(subdomain))
return;
String type = packet.getClass().getName();
_db.addNewLogEntry(subdomain, type, from.toString(), to.toString());
}
}
}
...@@ -15,6 +15,7 @@ import org.jivesoftware.openfire.component.ComponentEventListener; ...@@ -15,6 +15,7 @@ import org.jivesoftware.openfire.component.ComponentEventListener;
import org.jivesoftware.openfire.component.InternalComponentManager; import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.container.Plugin; import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager; import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.interceptor.InterceptorManager;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.handler.AbstractInterceptorHandler; import org.jivesoftware.openfire.plugin.gojara.messagefilter.handler.AbstractInterceptorHandler;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.handler.GatewayInterceptorHandler; import org.jivesoftware.openfire.plugin.gojara.messagefilter.handler.GatewayInterceptorHandler;
import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper; import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper;
...@@ -46,15 +47,21 @@ public class RemoteRosterPlugin implements Plugin { ...@@ -46,15 +47,21 @@ public class RemoteRosterPlugin implements Plugin {
private static final Logger Log = LoggerFactory.getLogger(RemoteRosterPlugin.class); private static final Logger Log = LoggerFactory.getLogger(RemoteRosterPlugin.class);
private static PluginManager pluginManager; private static PluginManager pluginManager;
private final SessionManager _sessionManager = SessionManager.getInstance(); private final SessionManager _sessionManager = SessionManager.getInstance();
private Map<String, AbstractInterceptorHandler> _interceptors = new HashMap<String, AbstractInterceptorHandler>(); // private Map<String, AbstractInterceptorHandler> _interceptors = new HashMap<String, AbstractInterceptorHandler>();
private Set<String> _waitingForIQResponse = new HashSet<String>(); private Set<String> _waitingForIQResponse = new HashSet<String>();
private PropertyEventListener _settingsObserver; private PropertyEventListener _settingsObserver;
private MainInterceptor mainInterceptor = new MainInterceptor();
private InterceptorManager iManager = InterceptorManager.getInstance();
public void initializePlugin(PluginManager manager, File pluginDirectory) { public void initializePlugin(PluginManager manager, File pluginDirectory) {
Log.debug("Starting RemoteRoster Plugin"); Log.debug("Starting RemoteRoster Plugin");
pluginManager = manager; pluginManager = manager;
iManager.addInterceptor(mainInterceptor);
manageExternalComponents(); manageExternalComponents();
listenToSettings(); listenToSettings();
Log.debug("Started Gojara successfully. Currently running interceptors: "+iManager.getInterceptors().size());
} }
/* /*
...@@ -68,23 +75,26 @@ public class RemoteRosterPlugin implements Plugin { ...@@ -68,23 +75,26 @@ public class RemoteRosterPlugin implements Plugin {
* Check if the unregistered component contains to one of our * Check if the unregistered component contains to one of our
* package interceptors * package interceptors
*/ */
@Override
public void componentUnregistered(JID componentJID) { public void componentUnregistered(JID componentJID) {
ComponentSession session = _sessionManager.getComponentSession(componentJID.getDomain()); // ComponentSession session = _sessionManager.getComponentSession(componentJID.getDomain());
if (session != null && _interceptors.containsKey(session.getExternalComponent().getInitialSubdomain())) { // if (session != null && _interceptors.containsKey(session.getExternalComponent().getInitialSubdomain())) {
String initialSubdomain = session.getExternalComponent().getInitialSubdomain(); // String initialSubdomain = session.getExternalComponent().getInitialSubdomain();
// Remove it from Map & ComponentManager // Remove it from Map & ComponentManager
removeInterceptor(initialSubdomain); removeInterceptor(componentJID.toString());
} // }
} }
/* /*
* If there is a new external Component, check if it is a gateway * If there is a new external Component, check if it is a gateway
* and add create a package interceptor if it is enabled * and add create a package interceptor if it is enabled
*/ */
@Override
public void componentRegistered(JID componentJID) { public void componentRegistered(JID componentJID) {
_waitingForIQResponse.add(componentJID.getDomain()); _waitingForIQResponse.add(componentJID.getDomain());
} }
@Override
public void componentInfoReceived(IQ iq) { public void componentInfoReceived(IQ iq) {
String from = iq.getFrom().getDomain(); String from = iq.getFrom().getDomain();
// Waiting for this external component sending an IQ response to // Waiting for this external component sending an IQ response to
...@@ -95,7 +105,8 @@ public class RemoteRosterPlugin implements Plugin { ...@@ -95,7 +105,8 @@ public class RemoteRosterPlugin implements Plugin {
List<Node> nodes = XpathHelper.findNodesInDocument(doc, "//disco:identity[@category='gateway']"); List<Node> nodes = XpathHelper.findNodesInDocument(doc, "//disco:identity[@category='gateway']");
// Is this external component a gateway and there is no // Is this external component a gateway and there is no
// package interceptor for it? // package interceptor for it?
if (nodes.size() > 0 && !_interceptors.containsKey(from)) { // if (nodes.size() > 0 && !_interceptors.containsKey(from)) {
if (nodes.size() > 0) {
updateInterceptors(from); updateInterceptors(from);
} }
...@@ -122,9 +133,10 @@ public class RemoteRosterPlugin implements Plugin { ...@@ -122,9 +133,10 @@ public class RemoteRosterPlugin implements Plugin {
} }
public void destroyPlugin() { public void destroyPlugin() {
for (String key : _interceptors.keySet()) { // for (String key : _interceptors.keySet()) {
_interceptors.get(key).stop(); // _interceptors.get(key).stop();
} // }
iManager.removeInterceptor(mainInterceptor);
PropertyEventDispatcher.removeListener(_settingsObserver); PropertyEventDispatcher.removeListener(_settingsObserver);
pluginManager = null; pluginManager = null;
} }
...@@ -132,13 +144,15 @@ public class RemoteRosterPlugin implements Plugin { ...@@ -132,13 +144,15 @@ public class RemoteRosterPlugin implements Plugin {
private void updateInterceptors(String componentJID) { private void updateInterceptors(String componentJID) {
boolean allowed = JiveGlobals.getBooleanProperty("plugin.remoteroster.jids." + componentJID, false); boolean allowed = JiveGlobals.getBooleanProperty("plugin.remoteroster.jids." + componentJID, false);
if (allowed) { if (allowed) {
if (!_interceptors.containsKey(componentJID)) { // if (!_interceptors.containsKey(componentJID)) {
createNewPackageIntercetor(componentJID); // createNewPackageIntercetor(componentJID);
} // }
mainInterceptor.addTransport(componentJID);
} else { } else {
if (_interceptors.containsKey(componentJID)) { // if (_interceptors.containsKey(componentJID)) {
removeInterceptor(componentJID); // removeInterceptor(componentJID);
} // }
mainInterceptor.removeTransport(componentJID);
} }
} }
...@@ -152,11 +166,12 @@ public class RemoteRosterPlugin implements Plugin { ...@@ -152,11 +166,12 @@ public class RemoteRosterPlugin implements Plugin {
} }
private void removeInterceptor(String initialSubdomain) { private void removeInterceptor(String initialSubdomain) {
AbstractInterceptorHandler interceptor = _interceptors.get(initialSubdomain); mainInterceptor.removeTransport(initialSubdomain);
if (interceptor != null) { // AbstractInterceptorHandler interceptor = _interceptors.get(initialSubdomain);
_interceptors.remove(initialSubdomain); // if (interceptor != null) {
interceptor.stop(); // _interceptors.remove(initialSubdomain);
} // interceptor.stop();
// }
} }
/* /*
...@@ -165,9 +180,10 @@ public class RemoteRosterPlugin implements Plugin { ...@@ -165,9 +180,10 @@ public class RemoteRosterPlugin implements Plugin {
* specified gateway * specified gateway
*/ */
private void createNewPackageIntercetor(String initialSubdomain) { private void createNewPackageIntercetor(String initialSubdomain) {
AbstractInterceptorHandler interceptor = new GatewayInterceptorHandler(initialSubdomain); mainInterceptor.addTransport(initialSubdomain);
_interceptors.put(initialSubdomain, interceptor); // AbstractInterceptorHandler interceptor = new GatewayInterceptorHandler(initialSubdomain);
interceptor.start(); // _interceptors.put(initialSubdomain, interceptor);
// interceptor.start();
} }
} }
...@@ -14,18 +14,22 @@ import org.jivesoftware.util.PropertyEventListener; ...@@ -14,18 +14,22 @@ import org.jivesoftware.util.PropertyEventListener;
*/ */
public abstract class RemoteRosterPropertyListener implements PropertyEventListener { public abstract class RemoteRosterPropertyListener implements PropertyEventListener {
@Override
public void xmlPropertySet(String property, Map<String, Object> params) { public void xmlPropertySet(String property, Map<String, Object> params) {
} }
@Override
public void xmlPropertyDeleted(String property, Map<String, Object> params) { public void xmlPropertyDeleted(String property, Map<String, Object> params) {
} }
@Override
public void propertySet(String property, Map<String, Object> params) { public void propertySet(String property, Map<String, Object> params) {
if (property.contains("plugin.remoteroster.jids.")) { if (property.contains("plugin.remoteroster.jids.")) {
changedProperty(property.replace("plugin.remoteroster.jids.", "")); changedProperty(property.replace("plugin.remoteroster.jids.", ""));
} }
} }
@Override
public void propertyDeleted(String property, Map<String, Object> params) { public void propertyDeleted(String property, Map<String, Object> params) {
String hostname = XMPPServer.getInstance().getServerInfo().getXMPPDomain(); String hostname = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
property += "." + hostname; property += "." + hostname;
......
...@@ -27,15 +27,16 @@ public class DiscoPackageInterceptorHandler implements PacketInterceptor { ...@@ -27,15 +27,16 @@ public class DiscoPackageInterceptorHandler implements PacketInterceptor {
private PermissionManager _permissions; private PermissionManager _permissions;
private String _subDomain; private String _subDomain;
private String _serverDomain; private String _host;
public DiscoPackageInterceptorHandler(String subdomain) { public DiscoPackageInterceptorHandler(String subdomain) {
_permissions = new PermissionManager(); _permissions = new PermissionManager();
_subDomain = subdomain; _subDomain = subdomain;
XMPPServer server = XMPPServer.getInstance(); XMPPServer server = XMPPServer.getInstance();
_serverDomain = server.getServerInfo().getXMPPDomain(); _host = server.getServerInfo().getHostname();
} }
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException { throws PacketRejectedException {
if (_permissions.isGatewayLimited(_subDomain)) { if (_permissions.isGatewayLimited(_subDomain)) {
...@@ -44,11 +45,11 @@ public class DiscoPackageInterceptorHandler implements PacketInterceptor { ...@@ -44,11 +45,11 @@ public class DiscoPackageInterceptorHandler implements PacketInterceptor {
Element root = iqpacket.getChildElement(); Element root = iqpacket.getChildElement();
if (root == null) if (root == null)
return; return;
if (iqpacket.getFrom() == null || iqpacket.getFrom().toString().equals(_serverDomain)) { String ns = root.getNamespaceURI();
String ns = root.getNamespaceURI(); if (ns.equals("http://jabber.org/protocol/disco#items") && iqpacket.getType().equals(IQ.Type.result)) {
if (ns.equals("http://jabber.org/protocol/disco#items") && iqpacket.getType().equals(IQ.Type.result)) { if (!_permissions.allowedForUser(_subDomain, iqpacket.getTo())) {
if (!_permissions.allowedForUser(_subDomain, iqpacket.getTo())) { if (iqpacket.getFrom().toString().equals(_host)) {
List<Node> nodes = XpathHelper.findNodesInDocument(root.getDocument(), "//discoitems:item"); List<Node> nodes = XpathHelper.findNodesInDocument(root.getDocument(), "//discoitems:item");
for (Node node : nodes) { for (Node node : nodes) {
if (node.valueOf("@jid").equals(_subDomain)) { if (node.valueOf("@jid").equals(_subDomain)) {
......
...@@ -33,6 +33,7 @@ public class IQLastInterceptor implements PacketInterceptor { ...@@ -33,6 +33,7 @@ public class IQLastInterceptor implements PacketInterceptor {
_subDomain = subdomain; _subDomain = subdomain;
} }
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException { throws PacketRejectedException {
......
...@@ -20,39 +20,30 @@ public class StatisticPackageInterceptor implements PacketInterceptor { ...@@ -20,39 +20,30 @@ public class StatisticPackageInterceptor implements PacketInterceptor {
private String _subdomain; private String _subdomain;
private DatabaseManager _db; private DatabaseManager _db;
// private static final Logger Log = LoggerFactory.getLogger(StatisticPackageInterceptor.class);
public StatisticPackageInterceptor(String subdomain) { public StatisticPackageInterceptor(String subdomain) {
_subdomain = subdomain; _subdomain = subdomain;
_db = DatabaseManager.getInstance(); _db = DatabaseManager.getInstance();
} }
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException { throws PacketRejectedException {
try { JID from = packet.getFrom();
JID from = packet.getFrom(); JID to = packet.getTo();
JID to = packet.getTo();
if (from != null && to != null && processed && incoming) { if (from != null && to != null && processed && incoming) {
if (from.toString().contains(_subdomain) || to.toString().contains(_subdomain)) { if (from.toString().contains(_subdomain) || to.toString().contains(_subdomain)) {
/* /*
* Spectrum sends a Ping to itself through the server to * Spectrum sends a Ping to itself through the server to check
* check if the server is alive. We ignore that for * if the server is alive. We ignore that for statistics
* statistics */
*/ if (to.toString().equals(from.toString()) && to.toString().equals(_subdomain))
if (to.toString().equals(from.toString()) && to.toString().equals(_subdomain)) return;
return; String type = packet.getClass().getName();
String type = packet.getClass().getName(); _db.addNewLogEntry(_subdomain, type, from.toString(), to.toString());
_db.addNewLogEntry(_subdomain, type, from.toString(), to.toString());
}
} }
} catch (IllegalArgumentException e) {
// Log.warn("There was an illegal JID while writing gojara gateway statistics! "+e.getMessage());
// TODO: IF there are packages with an invalid from or to jid like
// to="@somehost.com" Tinder will throw an exception. We cannot
// prevent that, because we want to know if there is a from and to
// jid.
} }
} }
} }
...@@ -6,12 +6,8 @@ import java.util.Map; ...@@ -6,12 +6,8 @@ import java.util.Map;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.interceptor.PacketInterceptor; import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException; import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.AbstractRemoteRosterProcessor; import org.jivesoftware.openfire.plugin.gojara.database.DatabaseManager;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.ClientToComponentUpdateProcessor; import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.*;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.DiscoIQRegisteredProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.NonPersistantRosterProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.ReceiveComponentUpdatesProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.SendRosterProcessor;
import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper; import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper;
import org.jivesoftware.openfire.roster.RosterManager; import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
...@@ -34,24 +30,28 @@ import org.xmpp.packet.Presence; ...@@ -34,24 +30,28 @@ import org.xmpp.packet.Presence;
* @author Holger Bergunde * @author Holger Bergunde
* *
*/ */
public class RemoteRosterInterceptor implements PacketInterceptor { public class RemoteRosterInterceptor {
private static final Logger Log = LoggerFactory.getLogger(RemoteRosterInterceptor.class); private static final Logger Log = LoggerFactory
private String _mySubdomain; .getLogger(RemoteRosterInterceptor.class);
// private String _mySubdomain;
private Map<String, AbstractRemoteRosterProcessor> _packetProcessor = new HashMap<String, AbstractRemoteRosterProcessor>(); private Map<String, AbstractRemoteRosterProcessor> _packetProcessor = new HashMap<String, AbstractRemoteRosterProcessor>();
private DatabaseManager _db;
private String _host;
public RemoteRosterInterceptor(String initialSubdomain) { public RemoteRosterInterceptor(String initialSubdomain) {
_db = DatabaseManager.getInstance();
Log.debug("Starting Package Interceptor for " + initialSubdomain); Log.debug("Starting Package Interceptor for " + initialSubdomain);
_mySubdomain = initialSubdomain;
XMPPServer server = XMPPServer.getInstance(); XMPPServer server = XMPPServer.getInstance();
RosterManager rosterMananger = server.getRosterManager(); RosterManager rosterMananger = server.getRosterManager();
AbstractRemoteRosterProcessor sendroster = new SendRosterProcessor(rosterMananger, _mySubdomain); AbstractRemoteRosterProcessor sendroster = new SendRosterProcessor(
AbstractRemoteRosterProcessor receiveChanges = new ReceiveComponentUpdatesProcessor(rosterMananger, rosterMananger);
_mySubdomain); AbstractRemoteRosterProcessor receiveChanges = new ReceiveComponentUpdatesProcessor(rosterMananger);
AbstractRemoteRosterProcessor iqRegistered = new DiscoIQRegisteredProcessor(_mySubdomain); AbstractRemoteRosterProcessor iqRegistered = new DiscoIQRegisteredProcessor();
AbstractRemoteRosterProcessor nonPersistant = new NonPersistantRosterProcessor(rosterMananger, _mySubdomain); AbstractRemoteRosterProcessor nonPersistant = new NonPersistantRosterProcessor(
AbstractRemoteRosterProcessor updateToComponent = new ClientToComponentUpdateProcessor(_mySubdomain); rosterMananger);
AbstractRemoteRosterProcessor updateToComponent = new ClientToComponentUpdateProcessor();
_packetProcessor.put("sendRoster", sendroster); _packetProcessor.put("sendRoster", sendroster);
_packetProcessor.put("receiveChanges", receiveChanges); _packetProcessor.put("receiveChanges", receiveChanges);
_packetProcessor.put("sparkIQRegistered", iqRegistered); _packetProcessor.put("sparkIQRegistered", iqRegistered);
...@@ -59,72 +59,125 @@ public class RemoteRosterInterceptor implements PacketInterceptor { ...@@ -59,72 +59,125 @@ public class RemoteRosterInterceptor implements PacketInterceptor {
_packetProcessor.put("clientToComponentUpdate", updateToComponent); _packetProcessor.put("clientToComponentUpdate", updateToComponent);
} }
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) public RemoteRosterInterceptor() {
_db = DatabaseManager.getInstance();
Log.debug("Starting RemoteRosterInterceptor - BINGO");
XMPPServer server = XMPPServer.getInstance();
RosterManager rosterMananger = server.getRosterManager();
AbstractRemoteRosterProcessor sendroster = new SendRosterProcessor(
rosterMananger);
AbstractRemoteRosterProcessor receiveChanges = new ReceiveComponentUpdatesProcessor(rosterMananger);
AbstractRemoteRosterProcessor iqRegistered = new DiscoIQRegisteredProcessor();
AbstractRemoteRosterProcessor nonPersistant = new NonPersistantRosterProcessor(
rosterMananger);
AbstractRemoteRosterProcessor updateToComponent = new ClientToComponentUpdateProcessor();
AbstractRemoteRosterProcessor discoPackage = new DiscoPackageProcessor();
_packetProcessor.put("sendRoster", sendroster);
_packetProcessor.put("receiveChanges", receiveChanges);
_packetProcessor.put("sparkIQRegistered", iqRegistered);
_packetProcessor.put("handleNonPersistant", nonPersistant);
_packetProcessor.put("clientToComponentUpdate", updateToComponent);
_packetProcessor.put("DiscoPackage",discoPackage);
_host = server.getServerInfo().getHostname();
}
public void interceptPacket(Packet packet, Session session,
boolean incoming, boolean processed, String subdomain)
throws PacketRejectedException { throws PacketRejectedException {
if (!processed && incoming) { if (!processed && incoming) {
if (packet instanceof IQ) { if (packet instanceof IQ) {
Log.debug("Incoming unprocessed package i might be interested in. I'm " + this.hashCode()+ " for subdomain " Log.debug("Incoming unprocessed package i might be interested in. I am: "
+ this._mySubdomain + ". Package: \n" + packet.toString() + "\n"); + this.hashCode()
+ " my subd: "
+ subdomain
+ " Package: \n" + packet.toString() + "\n");
IQ myPacket = (IQ) packet; IQ myPacket = (IQ) packet;
if (myPacket.getFrom() == null || myPacket.getTo() == null) { if (myPacket.getTo() == null) {
/* /*
* If getTo() == null this is maybe a roster update from the * If getTo() == null this is maybe a roster update from the
* Client to the Server, check if we should mirror this * Client to the Server, check if we should mirror this
* package to external component * package to external component
*/ */
if (myPacket.getFrom() != null && myPacket.getType().equals(IQ.Type.set) if (myPacket.getFrom() != null
&& myPacket.getTo() == null) { && myPacket.getType().equals(IQ.Type.set)) {
if (XpathHelper.findNodesInDocument(myPacket.getChildElement().getDocument(), "//roster:item") if (XpathHelper.findNodesInDocument(
.size() > 0) { myPacket.getChildElement().getDocument(),
_packetProcessor.get("clientToComponentUpdate").process(myPacket); "//roster:item").size() > 0) {
_packetProcessor.get("clientToComponentUpdate")
.process(myPacket, subdomain);
} }
} }
return; return;
} }
// String ns = root.getNamespaceURI();
// if (ns.equals("http://jabber.org/protocol/disco#items") && iqpacket.getType().equals(IQ.Type.result)){
//
// }
@SuppressWarnings("unused")
String from = myPacket.getFrom().toString(); String from = myPacket.getFrom().toString();
String to = myPacket.getTo().toString(); String to = myPacket.getTo().toString();
if (from.equals(_host)){
if (from.equals(_mySubdomain)) { _packetProcessor.get("DiscoPackage").process(packet,subdomain);
if (myPacket.getType().equals(IQ.Type.get)
&& XpathHelper.findNodesInDocument(myPacket.getElement().getDocument(), "//roster:*").size() == 1) { } else if (from.equals(subdomain)) {
if (myPacket.getType().equals(IQ.Type.get)
&& XpathHelper.findNodesInDocument(
myPacket.getElement().getDocument(),
"//roster:*").size() == 1) {
// This Package is a roster request by remote component // This Package is a roster request by remote component
_packetProcessor.get("sendRoster").process(packet); _packetProcessor.get("sendRoster").process(packet,
} else if (myPacket.getType().equals(IQ.Type.set) subdomain);
&& XpathHelper.findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item").size() >= 1) { } else if (myPacket.getType().equals(IQ.Type.set)
&& XpathHelper.findNodesInDocument(
myPacket.getElement().getDocument(),
"//roster:item").size() >= 1) {
// Component sends roster update // Component sends roster update
_packetProcessor.get("receiveChanges").process(packet); _packetProcessor.get("receiveChanges").process(packet,
subdomain);
} }
} else if (to.equals(_mySubdomain) } else if (to.equals(subdomain)
&& myPacket.getType().equals(IQ.Type.get) && myPacket.getType().equals(IQ.Type.get)
&& myPacket.toString().contains("http://jabber.org/protocol/disco#info")) { && myPacket.toString().contains(
"http://jabber.org/protocol/disco#info")) {
/* /*
* modify the disco#info for spark clients if enabled in * modify the disco#info for spark clients if enabled in
* admin panel * admin panel
*/ */
_packetProcessor.get("sparkIQRegistered").process(packet); _packetProcessor.get("sparkIQRegistered").process(packet,
} subdomain);
} else if (!JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)) { }
if (packet instanceof Presence && packet.getFrom().toString().equals(_mySubdomain) } else if (!JiveGlobals.getBooleanProperty(
&& !packet.getElement().getStringValue().equals("Connecting")){ "plugin.remoteroster.persistent", false)) {
System.out.println("Test for NonPersistant-Roster Cleanup!"); if (packet instanceof Presence
_packetProcessor.get("handleNonPersistant").process(packet); && packet.getFrom().toString().equals(subdomain)
&& !packet.getElement().getStringValue()
.equals("Connecting")) {
System.out
.println("Test for NonPersistant-Roster Cleanup!");
_packetProcessor.get("handleNonPersistant").process(packet,
subdomain);
} }
} }
} }
} }
} }
// currently we dont need this, and it didnt seem to occur often anyway. Will test it later. // currently we dont need this, and it didnt seem to occur often anyway. Will
// test it later.
// could potentially save some traffic // could potentially save some traffic
//else if (packet instanceof Presence){ // else if (packet instanceof Presence){
// String to = packet.getTo().toString(); // String to = packet.getTo().toString();
// if (!to.equals(_mySubdomain) && to.contains(_mySubdomain)){ // if (!to.equals(_mySubdomain) && to.contains(_mySubdomain)){
// //
// Presence myPacket = ((Presence) packet); // Presence myPacket = ((Presence) packet);
// if (myPacket.getType().equals(Presence.Type.unavailable) || myPacket.getType().equals(Presence.Type.probe) || // if (myPacket.getType().equals(Presence.Type.unavailable) ||
// myPacket.getType().equals(null)){ // myPacket.getType().equals(Presence.Type.probe) ||
// System.out.println("this presence would be wasted"); // myPacket.getType().equals(null)){
// throw new PacketRejectedException(); // System.out.println("this presence would be wasted");
// } // throw new PacketRejectedException();
// } // }
\ No newline at end of file // }
\ No newline at end of file
...@@ -40,7 +40,7 @@ abstract public class AbstractRemoteRosterProcessor { ...@@ -40,7 +40,7 @@ abstract public class AbstractRemoteRosterProcessor {
* @param packet * @param packet
* @throws PacketRejectedException * @throws PacketRejectedException
*/ */
abstract public void process(Packet packet) throws PacketRejectedException; abstract public void process(Packet packet, String subdomain) throws PacketRejectedException;
/** /**
* Use this method if you want to send your own packets through openfire * Use this method if you want to send your own packets through openfire
......
...@@ -33,7 +33,7 @@ public class CleanUpRosterProcessor extends AbstractRemoteRosterProcessor { ...@@ -33,7 +33,7 @@ public class CleanUpRosterProcessor extends AbstractRemoteRosterProcessor {
} }
@Override @Override
public void process(Packet packet) throws PacketRejectedException { public void process(Packet packet, String subdomain) throws PacketRejectedException {
if (packet instanceof IQ) { if (packet instanceof IQ) {
IQ iqPacket = (IQ) packet; IQ iqPacket = (IQ) packet;
......
...@@ -21,16 +21,16 @@ import org.xmpp.packet.Packet; ...@@ -21,16 +21,16 @@ import org.xmpp.packet.Packet;
*/ */
public class ClientToComponentUpdateProcessor extends AbstractRemoteRosterProcessor { public class ClientToComponentUpdateProcessor extends AbstractRemoteRosterProcessor {
private String _myDomain; // private String _myDomain;
public ClientToComponentUpdateProcessor(String mySubdomain) { public ClientToComponentUpdateProcessor() {
Log.debug("Created ClientToComponentUpdateProcessor for " + mySubdomain); Log.debug("Created ClientToComponentUpdateProcessor");
_myDomain = mySubdomain; // _myDomain = mySubdomain;
} }
@Override @Override
public void process(Packet packet) throws PacketRejectedException { public void process(Packet packet, String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in ClientToComponentUpdateProcessor for " + _myDomain); Log.debug("Processing packet in ClientToComponentUpdateProcessor for " + subdomain);
Element query = ((IQ) packet).getChildElement(); Element query = ((IQ) packet).getChildElement();
if (query != null && query.getNamespaceURI().equals("jabber:iq:roster")) { if (query != null && query.getNamespaceURI().equals("jabber:iq:roster")) {
if (findNodesInDocument(query.getDocument(), "//roster:item").size() > 0) { if (findNodesInDocument(query.getDocument(), "//roster:item").size() > 0) {
...@@ -39,10 +39,10 @@ public class ClientToComponentUpdateProcessor extends AbstractRemoteRosterProces ...@@ -39,10 +39,10 @@ public class ClientToComponentUpdateProcessor extends AbstractRemoteRosterProces
// TODO: We ignore remove iq packets for now. There might be // TODO: We ignore remove iq packets for now. There might be
// conflicts // conflicts
// when we remove our legacy network registration. // when we remove our legacy network registration.
if (jid.contains("@" + _myDomain) && !n.valueOf("@subscription").equals("remove")) { if (jid.contains("@" + subdomain) && !n.valueOf("@subscription").equals("remove")) {
Log.debug("Mirroring packet from local network to legacy component " + _myDomain); Log.debug("Mirroring packet from local network to legacy component " + subdomain);
IQ forward = (IQ) packet.createCopy(); IQ forward = (IQ) packet.createCopy();
forward.setTo(_myDomain); forward.setTo(subdomain);
dispatchPacket(forward); dispatchPacket(forward);
} }
} }
......
...@@ -29,16 +29,16 @@ import org.xmpp.packet.Packet; ...@@ -29,16 +29,16 @@ import org.xmpp.packet.Packet;
public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor { public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
private boolean _isRegistered = false; private boolean _isRegistered = false;
private String _mySubdoman; // private String _mySubdoman;
public DiscoIQRegisteredProcessor(String subdomain) { public DiscoIQRegisteredProcessor() {
Log.debug("Created DiscoIQResigteredProcessor for " + subdomain); Log.debug("Created DiscoIQResigteredProcessor");
_mySubdoman = subdomain; // _mySubdoman = subdomain;
} }
@Override @Override
public void process(Packet packet) throws PacketRejectedException { public void process(Packet packet, final String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in DiscoIQResigteredProcessor for " + _mySubdoman); Log.debug("Processing packet in DiscoIQResigteredProcessor for " + subdomain);
// Check if the jabber:iq:register is enabled in admin panel // Check if the jabber:iq:register is enabled in admin panel
boolean isFeatureEnabled = JiveGlobals.getBooleanProperty("plugin.remoteroster.sparkDiscoInfo", false); boolean isFeatureEnabled = JiveGlobals.getBooleanProperty("plugin.remoteroster.sparkDiscoInfo", false);
if (!isFeatureEnabled) { if (!isFeatureEnabled) {
...@@ -51,6 +51,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor { ...@@ -51,6 +51,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
final InterceptorManager interceptorManager = InterceptorManager.getInstance(); final InterceptorManager interceptorManager = InterceptorManager.getInstance();
final PacketInterceptor interceptor = new PacketInterceptor() { final PacketInterceptor interceptor = new PacketInterceptor() {
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException { throws PacketRejectedException {
if (!processed && incoming) { if (!processed && incoming) {
...@@ -61,13 +62,13 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor { ...@@ -61,13 +62,13 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
return; return;
String ns = iqPacket.getChildElement().getNamespace().getURI(); String ns = iqPacket.getChildElement().getNamespace().getURI();
if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("jabber:iq:register") if (iqPacket.getType().equals(IQ.Type.result) && ns.equals("jabber:iq:register")
&& iqPacket.getFrom().toString().equals(_mySubdoman)) { && iqPacket.getFrom().toString().equals(subdomain)) {
// Check if we are already registered // Check if we are already registered
setRegistered(iqPacket.toString().contains("<registered/>")); setRegistered(iqPacket.toString().contains("<registered/>"));
throw new PacketRejectedException(); throw new PacketRejectedException();
} else if (iqPacket.getType().equals(IQ.Type.result) } else if (iqPacket.getType().equals(IQ.Type.result)
&& ns.equals("http://jabber.org/protocol/disco#info") && ns.equals("http://jabber.org/protocol/disco#info")
&& iqPacket.getFrom().toString().equals(_mySubdoman)) { && iqPacket.getFrom().toString().equals(subdomain)) {
/* /*
* This is the answer of the disco#info from spark * This is the answer of the disco#info from spark
...@@ -86,7 +87,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor { ...@@ -86,7 +87,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
} }
}; };
Log.debug("Creating my own listener for jabber:iq:register result to external component " + _mySubdoman); Log.debug("Creating my own listener for jabber:iq:register result to external component " + subdomain);
interceptorManager.addInterceptor(interceptor); interceptorManager.addInterceptor(interceptor);
IQ askComponent = new IQ(); IQ askComponent = new IQ();
...@@ -102,7 +103,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor { ...@@ -102,7 +103,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
@Override @Override
public void run() { public void run() {
Log.debug("Removing my created listener for jabber:iq:register. Component " + _mySubdoman); Log.debug("Removing my created listener for jabber:iq:register. Component " + subdomain);
interceptorManager.removeInterceptor(interceptor); interceptorManager.removeInterceptor(interceptor);
} }
}; };
......
package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors;
import java.util.List;
import org.dom4j.Element;
import org.dom4j.Node;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.interceptor.PacketInterceptor;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.RemoteRosterInterceptor;
import org.jivesoftware.openfire.plugin.gojara.permissions.PermissionManager;
import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper;
import org.jivesoftware.openfire.session.Session;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Packet;
/**
*
* If the access to external components or gateways is limited to a special
* group in GoJara settings we have to filter the disco#infos from the server to
* the client. If the user is not on the list we are hiding the specified info
* and remove the item containing the gateways subdomain
*
* @author Holger Bergunde
*
*/
public class DiscoPackageProcessor extends AbstractRemoteRosterProcessor{
private PermissionManager _permissions;
public DiscoPackageProcessor() {
_permissions = new PermissionManager();
}
@Override
public void process (Packet packet, String subdomain) throws PacketRejectedException {
if (_permissions.isGatewayLimited(subdomain)) {
IQ iqpacket = (IQ) packet;
Element root = iqpacket.getChildElement();
if (root == null)
return;
String ns = root.getNamespaceURI();
if (ns.equals("http://jabber.org/protocol/disco#items") && iqpacket.getType().equals(IQ.Type.result)) {
if (!_permissions.allowedForUser(subdomain, iqpacket.getTo())) {
List<Node> nodes = XpathHelper.findNodesInDocument(root.getDocument(), "//discoitems:item");
for (Node node : nodes) {
if (node.valueOf("@jid").equals(subdomain)) {
root.remove(node);
}
}
}
}
}
}
}
...@@ -12,8 +12,11 @@ import org.xmpp.packet.Presence; ...@@ -12,8 +12,11 @@ import org.xmpp.packet.Presence;
/** /**
* This class is a part of the command pattern used in * This class is a part of the command pattern used in
* {@link RemoteRosterInterceptor}. If the remote contacts should not be saved * {@link RemoteRosterInterceptor}. If the remote contacts should not be
* permanently in the users roster this command will clean up the users roster. * saved permanently in the users Roster, this command will delete
* contacts to the corresponding Transport upon receiving unavailable presence
* from transport. This way the Users Roster will not get modified by the automated
* unsubscribe presences triggered by deleting RosterItem in OF-Roster
* *
* @author Holger Bergunde * @author Holger Bergunde
* *
...@@ -21,17 +24,17 @@ import org.xmpp.packet.Presence; ...@@ -21,17 +24,17 @@ import org.xmpp.packet.Presence;
public class NonPersistantRosterProcessor extends AbstractRemoteRosterProcessor { public class NonPersistantRosterProcessor extends AbstractRemoteRosterProcessor {
private RosterManager _rosterManager; private RosterManager _rosterManager;
private String _subDomain; // private String _subDomain;
public NonPersistantRosterProcessor(RosterManager rostermananger, String subdomain) { public NonPersistantRosterProcessor(RosterManager rostermananger) {
Log.debug("Created NonPersistantProcessor for " + subdomain); Log.debug("Created NonPersistantProcessor");
_rosterManager = rostermananger; _rosterManager = rostermananger;
_subDomain = subdomain; // _subDomain = subdomain;
} }
@Override @Override
public void process(Packet packet) throws PacketRejectedException { public void process(Packet packet, String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in NonPersistantRosterProcessor for " + _subDomain); Log.debug("Processing packet in NonPersistantRosterProcessor for " + subdomain);
Presence myPacket = (Presence) packet; Presence myPacket = (Presence) packet;
String to = myPacket.getTo().toString(); String to = myPacket.getTo().toString();
String username = getUsernameFromJid(to); String username = getUsernameFromJid(to);
...@@ -41,7 +44,7 @@ public class NonPersistantRosterProcessor extends AbstractRemoteRosterProcessor ...@@ -41,7 +44,7 @@ public class NonPersistantRosterProcessor extends AbstractRemoteRosterProcessor
Collection<RosterItem> items = roster.getRosterItems(); Collection<RosterItem> items = roster.getRosterItems();
for (RosterItem item : items) { for (RosterItem item : items) {
String itemName = item.getJid().toString(); String itemName = item.getJid().toString();
if (itemName.contains(_subDomain) && !itemName.equals(_subDomain)) { if (itemName.contains(subdomain) && !itemName.equals(subdomain)) {
Log.debug("Removing contact " + item.getJid().toString() + " from contact list."); Log.debug("Removing contact " + item.getJid().toString() + " from contact list.");
roster.deleteRosterItem(item.getJid(), false); roster.deleteRosterItem(item.getJid(), false);
} }
......
package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors; package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import org.dom4j.Element;
import org.dom4j.Node; import org.dom4j.Node;
import org.dom4j.tree.DefaultElement;
import org.jivesoftware.openfire.SharedGroupException; import org.jivesoftware.openfire.SharedGroupException;
import org.jivesoftware.openfire.interceptor.PacketRejectedException; import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.RemoteRosterInterceptor; import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.RemoteRosterInterceptor;
...@@ -32,17 +35,17 @@ import org.xmpp.packet.Packet; ...@@ -32,17 +35,17 @@ import org.xmpp.packet.Packet;
public class ReceiveComponentUpdatesProcessor extends AbstractRemoteRosterProcessor { public class ReceiveComponentUpdatesProcessor extends AbstractRemoteRosterProcessor {
private RosterManager _rosterManager; private RosterManager _rosterManager;
private String _mySubdomain; // private String _mySubdomain;
public ReceiveComponentUpdatesProcessor(RosterManager rosterManager, String subdomain) { public ReceiveComponentUpdatesProcessor(RosterManager rosterManager) {
_mySubdomain = subdomain; // _mySubdomain = subdomain;
Log.debug("Created ReceiveComponentUpdatesProcessor for " + _mySubdomain); Log.debug("Created ReceiveComponentUpdatesProcessor");
_rosterManager = rosterManager; _rosterManager = rosterManager;
} }
@Override @Override
public void process(Packet packet) throws PacketRejectedException { public void process(Packet packet, String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in ClientToComponentUpdateProcessor for " + _mySubdomain); Log.debug("Processing packet in ClientToComponentUpdateProcessor for " + subdomain);
IQ myPacket = (IQ) packet; IQ myPacket = (IQ) packet;
IQ response = IQ.createResultIQ(myPacket); IQ response = IQ.createResultIQ(myPacket);
...@@ -90,14 +93,13 @@ public class ReceiveComponentUpdatesProcessor extends AbstractRemoteRosterProces ...@@ -90,14 +93,13 @@ public class ReceiveComponentUpdatesProcessor extends AbstractRemoteRosterProces
} }
} else if (subvalue.equals("remove")){ } else if (subvalue.equals("remove")){
try { try {
roster = _rosterManager.getRoster(username); if (jid.equals(myPacket.getFrom().toString())) {
Log.debug("Removing contact " + username + " from contact list."); // Do not Try to Remove component itself as its not added.
//If the contact didnt exist in contact list it is likely the transport itself in which case break;
//we do not want to forward this msg to server...
RosterItem item = roster.deleteRosterItem(new JID(jid), false);
if (item == null) {
throw new PacketRejectedException();
} }
roster = _rosterManager.getRoster(username);
roster.deleteRosterItem(new JID(jid), false);
Log.debug("Removed contact " + jid + " from contact list of " + username);
} catch (UserNotFoundException e) { } catch (UserNotFoundException e) {
Log.debug("Could not find user while cleaning up the roster in GoJara for user " + username, e); Log.debug("Could not find user while cleaning up the roster in GoJara for user " + username, e);
response.setType(IQ.Type.error); response.setType(IQ.Type.error);
......
...@@ -30,17 +30,17 @@ import org.xmpp.packet.Packet; ...@@ -30,17 +30,17 @@ import org.xmpp.packet.Packet;
public class SendRosterProcessor extends AbstractRemoteRosterProcessor { public class SendRosterProcessor extends AbstractRemoteRosterProcessor {
private RosterManager _rosterManager; private RosterManager _rosterManager;
private String _componentName; // private String _componentName;
public SendRosterProcessor(RosterManager rosterMananger, String componentName) { public SendRosterProcessor(RosterManager rosterMananger) {
Log.debug("Created SendRosterProcessor for " + componentName); Log.debug("Created SendRosterProcessor");
_rosterManager = rosterMananger; _rosterManager = rosterMananger;
_componentName = componentName; // _componentName = componentName;
} }
@Override @Override
public void process(Packet packet) throws PacketRejectedException { public void process(Packet packet, String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in SendRosterProcessor for " + _componentName); Log.debug("Processing packet in SendRosterProcessor for " + subdomain);
IQ myPacket = (IQ) packet; IQ myPacket = (IQ) packet;
String user = myPacket.getTo().toString(); String user = myPacket.getTo().toString();
...@@ -51,23 +51,23 @@ public class SendRosterProcessor extends AbstractRemoteRosterProcessor { ...@@ -51,23 +51,23 @@ public class SendRosterProcessor extends AbstractRemoteRosterProcessor {
try { try {
roster = _rosterManager.getRoster(username); roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems(); Collection<RosterItem> items = roster.getRosterItems();
sendRosterToComponent(myPacket, items); sendRosterToComponent(myPacket, items, subdomain);
} catch (UserNotFoundException e) { } catch (UserNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
sendEmptyRoster(myPacket); sendEmptyRoster(myPacket, subdomain);
} }
} }
private void sendRosterToComponent(IQ requestPacket, Collection<RosterItem> items) { private void sendRosterToComponent(IQ requestPacket, Collection<RosterItem> items, String subdomain) {
Log.debug("Sending contacts from user " + requestPacket.getFrom().toString() + " to external Component"); Log.debug("Sending contacts from user " + requestPacket.getFrom().toString() + " to external Component");
IQ response = IQ.createResultIQ(requestPacket); IQ response = IQ.createResultIQ(requestPacket);
response.setTo(_componentName); response.setTo(subdomain);
Element query = new DefaultElement("query"); Element query = new DefaultElement("query");
for (RosterItem i : items) { for (RosterItem i : items) {
if (i.getJid().toString().contains(_componentName)) { if (i.getJid().toString().contains(subdomain)) {
Log.debug("Roster exchange for external component " + _componentName + ". Sending user " Log.debug("Roster exchange for external component " + subdomain + ". Sending user "
+ i.getJid().toString()); + i.getJid().toString());
Element item = new DefaultElement("item", null); Element item = new DefaultElement("item", null);
item.add(new DefaultAttribute("jid", i.getJid().toString())); item.add(new DefaultAttribute("jid", i.getJid().toString()));
...@@ -87,11 +87,11 @@ public class SendRosterProcessor extends AbstractRemoteRosterProcessor { ...@@ -87,11 +87,11 @@ public class SendRosterProcessor extends AbstractRemoteRosterProcessor {
dispatchPacket(response); dispatchPacket(response);
} }
private void sendEmptyRoster(Packet requestPacket){ private void sendEmptyRoster(Packet requestPacket, String subdomain){
Log.debug("Sending nonpersistant-RemoteRosterResponse to external Component"); Log.debug("Sending nonpersistant-RemoteRosterResponse to external Component");
IQ iq = (IQ) requestPacket; IQ iq = (IQ) requestPacket;
IQ response = IQ.createResultIQ(iq); IQ response = IQ.createResultIQ(iq);
response.setTo(_componentName); response.setTo(subdomain);
Element query = new DefaultElement("query"); Element query = new DefaultElement("query");
query.addNamespace("", "jabber:iq:roster"); query.addNamespace("", "jabber:iq:roster");
response.setChildElement(query); response.setChildElement(query);
......
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