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;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.container.Plugin;
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.GatewayInterceptorHandler;
import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper;
......@@ -46,15 +47,21 @@ public class RemoteRosterPlugin implements Plugin {
private static final Logger Log = LoggerFactory.getLogger(RemoteRosterPlugin.class);
private static PluginManager pluginManager;
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 PropertyEventListener _settingsObserver;
private MainInterceptor mainInterceptor = new MainInterceptor();
private InterceptorManager iManager = InterceptorManager.getInstance();
public void initializePlugin(PluginManager manager, File pluginDirectory) {
Log.debug("Starting RemoteRoster Plugin");
pluginManager = manager;
iManager.addInterceptor(mainInterceptor);
manageExternalComponents();
listenToSettings();
Log.debug("Started Gojara successfully. Currently running interceptors: "+iManager.getInterceptors().size());
}
/*
......@@ -68,23 +75,26 @@ public class RemoteRosterPlugin implements Plugin {
* Check if the unregistered component contains to one of our
* package interceptors
*/
@Override
public void componentUnregistered(JID componentJID) {
ComponentSession session = _sessionManager.getComponentSession(componentJID.getDomain());
if (session != null && _interceptors.containsKey(session.getExternalComponent().getInitialSubdomain())) {
String initialSubdomain = session.getExternalComponent().getInitialSubdomain();
// ComponentSession session = _sessionManager.getComponentSession(componentJID.getDomain());
// if (session != null && _interceptors.containsKey(session.getExternalComponent().getInitialSubdomain())) {
// String initialSubdomain = session.getExternalComponent().getInitialSubdomain();
// Remove it from Map & ComponentManager
removeInterceptor(initialSubdomain);
}
removeInterceptor(componentJID.toString());
// }
}
/*
* If there is a new external Component, check if it is a gateway
* and add create a package interceptor if it is enabled
*/
@Override
public void componentRegistered(JID componentJID) {
_waitingForIQResponse.add(componentJID.getDomain());
}
@Override
public void componentInfoReceived(IQ iq) {
String from = iq.getFrom().getDomain();
// Waiting for this external component sending an IQ response to
......@@ -95,7 +105,8 @@ public class RemoteRosterPlugin implements Plugin {
List<Node> nodes = XpathHelper.findNodesInDocument(doc, "//disco:identity[@category='gateway']");
// Is this external component a gateway and there is no
// package interceptor for it?
if (nodes.size() > 0 && !_interceptors.containsKey(from)) {
// if (nodes.size() > 0 && !_interceptors.containsKey(from)) {
if (nodes.size() > 0) {
updateInterceptors(from);
}
......@@ -122,9 +133,10 @@ public class RemoteRosterPlugin implements Plugin {
}
public void destroyPlugin() {
for (String key : _interceptors.keySet()) {
_interceptors.get(key).stop();
}
// for (String key : _interceptors.keySet()) {
// _interceptors.get(key).stop();
// }
iManager.removeInterceptor(mainInterceptor);
PropertyEventDispatcher.removeListener(_settingsObserver);
pluginManager = null;
}
......@@ -132,13 +144,15 @@ public class RemoteRosterPlugin implements Plugin {
private void updateInterceptors(String componentJID) {
boolean allowed = JiveGlobals.getBooleanProperty("plugin.remoteroster.jids." + componentJID, false);
if (allowed) {
if (!_interceptors.containsKey(componentJID)) {
createNewPackageIntercetor(componentJID);
}
// if (!_interceptors.containsKey(componentJID)) {
// createNewPackageIntercetor(componentJID);
// }
mainInterceptor.addTransport(componentJID);
} else {
if (_interceptors.containsKey(componentJID)) {
removeInterceptor(componentJID);
}
// if (_interceptors.containsKey(componentJID)) {
// removeInterceptor(componentJID);
// }
mainInterceptor.removeTransport(componentJID);
}
}
......@@ -152,11 +166,12 @@ public class RemoteRosterPlugin implements Plugin {
}
private void removeInterceptor(String initialSubdomain) {
AbstractInterceptorHandler interceptor = _interceptors.get(initialSubdomain);
if (interceptor != null) {
_interceptors.remove(initialSubdomain);
interceptor.stop();
}
mainInterceptor.removeTransport(initialSubdomain);
// AbstractInterceptorHandler interceptor = _interceptors.get(initialSubdomain);
// if (interceptor != null) {
// _interceptors.remove(initialSubdomain);
// interceptor.stop();
// }
}
/*
......@@ -165,9 +180,10 @@ public class RemoteRosterPlugin implements Plugin {
* specified gateway
*/
private void createNewPackageIntercetor(String initialSubdomain) {
AbstractInterceptorHandler interceptor = new GatewayInterceptorHandler(initialSubdomain);
_interceptors.put(initialSubdomain, interceptor);
interceptor.start();
mainInterceptor.addTransport(initialSubdomain);
// AbstractInterceptorHandler interceptor = new GatewayInterceptorHandler(initialSubdomain);
// _interceptors.put(initialSubdomain, interceptor);
// interceptor.start();
}
}
......@@ -14,18 +14,22 @@ import org.jivesoftware.util.PropertyEventListener;
*/
public abstract class RemoteRosterPropertyListener implements PropertyEventListener {
@Override
public void xmlPropertySet(String property, Map<String, Object> params) {
}
@Override
public void xmlPropertyDeleted(String property, Map<String, Object> params) {
}
@Override
public void propertySet(String property, Map<String, Object> params) {
if (property.contains("plugin.remoteroster.jids.")) {
changedProperty(property.replace("plugin.remoteroster.jids.", ""));
}
}
@Override
public void propertyDeleted(String property, Map<String, Object> params) {
String hostname = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
property += "." + hostname;
......
......@@ -27,15 +27,16 @@ public class DiscoPackageInterceptorHandler implements PacketInterceptor {
private PermissionManager _permissions;
private String _subDomain;
private String _serverDomain;
private String _host;
public DiscoPackageInterceptorHandler(String subdomain) {
_permissions = new PermissionManager();
_subDomain = subdomain;
XMPPServer server = XMPPServer.getInstance();
_serverDomain = server.getServerInfo().getXMPPDomain();
_host = server.getServerInfo().getHostname();
}
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException {
if (_permissions.isGatewayLimited(_subDomain)) {
......@@ -44,11 +45,11 @@ public class DiscoPackageInterceptorHandler implements PacketInterceptor {
Element root = iqpacket.getChildElement();
if (root == null)
return;
if (iqpacket.getFrom() == null || iqpacket.getFrom().toString().equals(_serverDomain)) {
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())) {
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())) {
if (iqpacket.getFrom().toString().equals(_host)) {
List<Node> nodes = XpathHelper.findNodesInDocument(root.getDocument(), "//discoitems:item");
for (Node node : nodes) {
if (node.valueOf("@jid").equals(_subDomain)) {
......
......@@ -33,6 +33,7 @@ public class IQLastInterceptor implements PacketInterceptor {
_subDomain = subdomain;
}
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException {
......
......@@ -20,39 +20,30 @@ public class StatisticPackageInterceptor implements PacketInterceptor {
private String _subdomain;
private DatabaseManager _db;
// private static final Logger Log = LoggerFactory.getLogger(StatisticPackageInterceptor.class);
public StatisticPackageInterceptor(String subdomain) {
_subdomain = subdomain;
_db = DatabaseManager.getInstance();
}
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException {
try {
JID from = packet.getFrom();
JID to = packet.getTo();
if (from != null && to != null && processed && incoming) {
if (from.toString().contains(_subdomain) || to.toString().contains(_subdomain)) {
/*
* 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());
}
JID from = packet.getFrom();
JID to = packet.getTo();
if (from != null && to != null && processed && incoming) {
if (from.toString().contains(_subdomain) || to.toString().contains(_subdomain)) {
/*
* 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());
}
} 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;
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.processors.AbstractRemoteRosterProcessor;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.ClientToComponentUpdateProcessor;
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.database.DatabaseManager;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors.*;
import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper;
import org.jivesoftware.openfire.roster.RosterManager;
import org.jivesoftware.openfire.session.Session;
......@@ -34,24 +30,28 @@ import org.xmpp.packet.Presence;
* @author Holger Bergunde
*
*/
public class RemoteRosterInterceptor implements PacketInterceptor {
public class RemoteRosterInterceptor {
private static final Logger Log = LoggerFactory.getLogger(RemoteRosterInterceptor.class);
private String _mySubdomain;
private static final Logger Log = LoggerFactory
.getLogger(RemoteRosterInterceptor.class);
// private String _mySubdomain;
private Map<String, AbstractRemoteRosterProcessor> _packetProcessor = new HashMap<String, AbstractRemoteRosterProcessor>();
private DatabaseManager _db;
private String _host;
public RemoteRosterInterceptor(String initialSubdomain) {
_db = DatabaseManager.getInstance();
Log.debug("Starting Package Interceptor for " + initialSubdomain);
_mySubdomain = initialSubdomain;
XMPPServer server = XMPPServer.getInstance();
RosterManager rosterMananger = server.getRosterManager();
AbstractRemoteRosterProcessor sendroster = new SendRosterProcessor(rosterMananger, _mySubdomain);
AbstractRemoteRosterProcessor receiveChanges = new ReceiveComponentUpdatesProcessor(rosterMananger,
_mySubdomain);
AbstractRemoteRosterProcessor iqRegistered = new DiscoIQRegisteredProcessor(_mySubdomain);
AbstractRemoteRosterProcessor nonPersistant = new NonPersistantRosterProcessor(rosterMananger, _mySubdomain);
AbstractRemoteRosterProcessor updateToComponent = new ClientToComponentUpdateProcessor(_mySubdomain);
AbstractRemoteRosterProcessor sendroster = new SendRosterProcessor(
rosterMananger);
AbstractRemoteRosterProcessor receiveChanges = new ReceiveComponentUpdatesProcessor(rosterMananger);
AbstractRemoteRosterProcessor iqRegistered = new DiscoIQRegisteredProcessor();
AbstractRemoteRosterProcessor nonPersistant = new NonPersistantRosterProcessor(
rosterMananger);
AbstractRemoteRosterProcessor updateToComponent = new ClientToComponentUpdateProcessor();
_packetProcessor.put("sendRoster", sendroster);
_packetProcessor.put("receiveChanges", receiveChanges);
_packetProcessor.put("sparkIQRegistered", iqRegistered);
......@@ -59,72 +59,125 @@ public class RemoteRosterInterceptor implements PacketInterceptor {
_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 {
if (!processed && incoming) {
if (packet instanceof IQ) {
Log.debug("Incoming unprocessed package i might be interested in. I'm " + this.hashCode()+ " for subdomain "
+ this._mySubdomain + ". Package: \n" + packet.toString() + "\n");
Log.debug("Incoming unprocessed package i might be interested in. I am: "
+ this.hashCode()
+ " my subd: "
+ subdomain
+ " Package: \n" + packet.toString() + "\n");
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
* Client to the Server, check if we should mirror this
* package to external component
*/
if (myPacket.getFrom() != null && myPacket.getType().equals(IQ.Type.set)
&& myPacket.getTo() == null) {
if (XpathHelper.findNodesInDocument(myPacket.getChildElement().getDocument(), "//roster:item")
.size() > 0) {
_packetProcessor.get("clientToComponentUpdate").process(myPacket);
if (myPacket.getFrom() != null
&& myPacket.getType().equals(IQ.Type.set)) {
if (XpathHelper.findNodesInDocument(
myPacket.getChildElement().getDocument(),
"//roster:item").size() > 0) {
_packetProcessor.get("clientToComponentUpdate")
.process(myPacket, subdomain);
}
}
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 to = myPacket.getTo().toString();
if (from.equals(_mySubdomain)) {
if (myPacket.getType().equals(IQ.Type.get)
&& XpathHelper.findNodesInDocument(myPacket.getElement().getDocument(), "//roster:*").size() == 1) {
if (from.equals(_host)){
_packetProcessor.get("DiscoPackage").process(packet,subdomain);
} 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
_packetProcessor.get("sendRoster").process(packet);
} else if (myPacket.getType().equals(IQ.Type.set)
&& XpathHelper.findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item").size() >= 1) {
_packetProcessor.get("sendRoster").process(packet,
subdomain);
} else if (myPacket.getType().equals(IQ.Type.set)
&& XpathHelper.findNodesInDocument(
myPacket.getElement().getDocument(),
"//roster:item").size() >= 1) {
// 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.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
* admin panel
*/
_packetProcessor.get("sparkIQRegistered").process(packet);
}
} else if (!JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)) {
if (packet instanceof Presence && packet.getFrom().toString().equals(_mySubdomain)
&& !packet.getElement().getStringValue().equals("Connecting")){
System.out.println("Test for NonPersistant-Roster Cleanup!");
_packetProcessor.get("handleNonPersistant").process(packet);
_packetProcessor.get("sparkIQRegistered").process(packet,
subdomain);
}
} else if (!JiveGlobals.getBooleanProperty(
"plugin.remoteroster.persistent", false)) {
if (packet instanceof Presence
&& 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
//else if (packet instanceof Presence){
// String to = packet.getTo().toString();
// if (!to.equals(_mySubdomain) && to.contains(_mySubdomain)){
//
// Presence myPacket = ((Presence) packet);
// if (myPacket.getType().equals(Presence.Type.unavailable) || myPacket.getType().equals(Presence.Type.probe) ||
// myPacket.getType().equals(null)){
// System.out.println("this presence would be wasted");
// throw new PacketRejectedException();
// }
// }
\ No newline at end of file
// else if (packet instanceof Presence){
// String to = packet.getTo().toString();
// if (!to.equals(_mySubdomain) && to.contains(_mySubdomain)){
//
// Presence myPacket = ((Presence) packet);
// if (myPacket.getType().equals(Presence.Type.unavailable) ||
// myPacket.getType().equals(Presence.Type.probe) ||
// myPacket.getType().equals(null)){
// System.out.println("this presence would be wasted");
// throw new PacketRejectedException();
// }
// }
\ No newline at end of file
......@@ -40,7 +40,7 @@ abstract public class AbstractRemoteRosterProcessor {
* @param packet
* @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
......
......@@ -33,7 +33,7 @@ public class CleanUpRosterProcessor extends AbstractRemoteRosterProcessor {
}
@Override
public void process(Packet packet) throws PacketRejectedException {
public void process(Packet packet, String subdomain) throws PacketRejectedException {
if (packet instanceof IQ) {
IQ iqPacket = (IQ) packet;
......
......@@ -21,16 +21,16 @@ import org.xmpp.packet.Packet;
*/
public class ClientToComponentUpdateProcessor extends AbstractRemoteRosterProcessor {
private String _myDomain;
// private String _myDomain;
public ClientToComponentUpdateProcessor(String mySubdomain) {
Log.debug("Created ClientToComponentUpdateProcessor for " + mySubdomain);
_myDomain = mySubdomain;
public ClientToComponentUpdateProcessor() {
Log.debug("Created ClientToComponentUpdateProcessor");
// _myDomain = mySubdomain;
}
@Override
public void process(Packet packet) throws PacketRejectedException {
Log.debug("Processing packet in ClientToComponentUpdateProcessor for " + _myDomain);
public void process(Packet packet, String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in ClientToComponentUpdateProcessor for " + subdomain);
Element query = ((IQ) packet).getChildElement();
if (query != null && query.getNamespaceURI().equals("jabber:iq:roster")) {
if (findNodesInDocument(query.getDocument(), "//roster:item").size() > 0) {
......@@ -39,10 +39,10 @@ public class ClientToComponentUpdateProcessor extends AbstractRemoteRosterProces
// TODO: We ignore remove iq packets for now. There might be
// conflicts
// when we remove our legacy network registration.
if (jid.contains("@" + _myDomain) && !n.valueOf("@subscription").equals("remove")) {
Log.debug("Mirroring packet from local network to legacy component " + _myDomain);
if (jid.contains("@" + subdomain) && !n.valueOf("@subscription").equals("remove")) {
Log.debug("Mirroring packet from local network to legacy component " + subdomain);
IQ forward = (IQ) packet.createCopy();
forward.setTo(_myDomain);
forward.setTo(subdomain);
dispatchPacket(forward);
}
}
......
......@@ -29,16 +29,16 @@ import org.xmpp.packet.Packet;
public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
private boolean _isRegistered = false;
private String _mySubdoman;
// private String _mySubdoman;
public DiscoIQRegisteredProcessor(String subdomain) {
Log.debug("Created DiscoIQResigteredProcessor for " + subdomain);
_mySubdoman = subdomain;
public DiscoIQRegisteredProcessor() {
Log.debug("Created DiscoIQResigteredProcessor");
// _mySubdoman = subdomain;
}
@Override
public void process(Packet packet) throws PacketRejectedException {
Log.debug("Processing packet in DiscoIQResigteredProcessor for " + _mySubdoman);
public void process(Packet packet, final String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in DiscoIQResigteredProcessor for " + subdomain);
// Check if the jabber:iq:register is enabled in admin panel
boolean isFeatureEnabled = JiveGlobals.getBooleanProperty("plugin.remoteroster.sparkDiscoInfo", false);
if (!isFeatureEnabled) {
......@@ -51,6 +51,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
final InterceptorManager interceptorManager = InterceptorManager.getInstance();
final PacketInterceptor interceptor = new PacketInterceptor() {
@Override
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed)
throws PacketRejectedException {
if (!processed && incoming) {
......@@ -61,13 +62,13 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
return;
String ns = iqPacket.getChildElement().getNamespace().getURI();
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
setRegistered(iqPacket.toString().contains("<registered/>"));
throw new PacketRejectedException();
} else if (iqPacket.getType().equals(IQ.Type.result)
&& 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
......@@ -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);
IQ askComponent = new IQ();
......@@ -102,7 +103,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
@Override
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);
}
};
......
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;
/**
* This class is a part of the command pattern used in
* {@link RemoteRosterInterceptor}. If the remote contacts should not be saved
* permanently in the users roster this command will clean up the users roster.
* {@link RemoteRosterInterceptor}. If the remote contacts should not be
* 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
*
......@@ -21,17 +24,17 @@ import org.xmpp.packet.Presence;
public class NonPersistantRosterProcessor extends AbstractRemoteRosterProcessor {
private RosterManager _rosterManager;
private String _subDomain;
// private String _subDomain;
public NonPersistantRosterProcessor(RosterManager rostermananger, String subdomain) {
Log.debug("Created NonPersistantProcessor for " + subdomain);
public NonPersistantRosterProcessor(RosterManager rostermananger) {
Log.debug("Created NonPersistantProcessor");
_rosterManager = rostermananger;
_subDomain = subdomain;
// _subDomain = subdomain;
}
@Override
public void process(Packet packet) throws PacketRejectedException {
Log.debug("Processing packet in NonPersistantRosterProcessor for " + _subDomain);
public void process(Packet packet, String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in NonPersistantRosterProcessor for " + subdomain);
Presence myPacket = (Presence) packet;
String to = myPacket.getTo().toString();
String username = getUsernameFromJid(to);
......@@ -41,7 +44,7 @@ public class NonPersistantRosterProcessor extends AbstractRemoteRosterProcessor
Collection<RosterItem> items = roster.getRosterItems();
for (RosterItem item : items) {
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.");
roster.deleteRosterItem(item.getJid(), false);
}
......
package org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.processors;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.tree.DefaultElement;
import org.jivesoftware.openfire.SharedGroupException;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.messagefilter.remoteroster.RemoteRosterInterceptor;
......@@ -32,17 +35,17 @@ import org.xmpp.packet.Packet;
public class ReceiveComponentUpdatesProcessor extends AbstractRemoteRosterProcessor {
private RosterManager _rosterManager;
private String _mySubdomain;
// private String _mySubdomain;
public ReceiveComponentUpdatesProcessor(RosterManager rosterManager, String subdomain) {
_mySubdomain = subdomain;
Log.debug("Created ReceiveComponentUpdatesProcessor for " + _mySubdomain);
public ReceiveComponentUpdatesProcessor(RosterManager rosterManager) {
// _mySubdomain = subdomain;
Log.debug("Created ReceiveComponentUpdatesProcessor");
_rosterManager = rosterManager;
}
@Override
public void process(Packet packet) throws PacketRejectedException {
Log.debug("Processing packet in ClientToComponentUpdateProcessor for " + _mySubdomain);
public void process(Packet packet, String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in ClientToComponentUpdateProcessor for " + subdomain);
IQ myPacket = (IQ) packet;
IQ response = IQ.createResultIQ(myPacket);
......@@ -90,14 +93,13 @@ public class ReceiveComponentUpdatesProcessor extends AbstractRemoteRosterProces
}
} else if (subvalue.equals("remove")){
try {
roster = _rosterManager.getRoster(username);
Log.debug("Removing contact " + username + " from contact list.");
//If the contact didnt exist in contact list it is likely the transport itself in which case
//we do not want to forward this msg to server...
RosterItem item = roster.deleteRosterItem(new JID(jid), false);
if (item == null) {
throw new PacketRejectedException();
if (jid.equals(myPacket.getFrom().toString())) {
// Do not Try to Remove component itself as its not added.
break;
}
roster = _rosterManager.getRoster(username);
roster.deleteRosterItem(new JID(jid), false);
Log.debug("Removed contact " + jid + " from contact list of " + username);
} catch (UserNotFoundException e) {
Log.debug("Could not find user while cleaning up the roster in GoJara for user " + username, e);
response.setType(IQ.Type.error);
......
......@@ -30,17 +30,17 @@ import org.xmpp.packet.Packet;
public class SendRosterProcessor extends AbstractRemoteRosterProcessor {
private RosterManager _rosterManager;
private String _componentName;
// private String _componentName;
public SendRosterProcessor(RosterManager rosterMananger, String componentName) {
Log.debug("Created SendRosterProcessor for " + componentName);
public SendRosterProcessor(RosterManager rosterMananger) {
Log.debug("Created SendRosterProcessor");
_rosterManager = rosterMananger;
_componentName = componentName;
// _componentName = componentName;
}
@Override
public void process(Packet packet) throws PacketRejectedException {
Log.debug("Processing packet in SendRosterProcessor for " + _componentName);
public void process(Packet packet, String subdomain) throws PacketRejectedException {
Log.debug("Processing packet in SendRosterProcessor for " + subdomain);
IQ myPacket = (IQ) packet;
String user = myPacket.getTo().toString();
......@@ -51,23 +51,23 @@ public class SendRosterProcessor extends AbstractRemoteRosterProcessor {
try {
roster = _rosterManager.getRoster(username);
Collection<RosterItem> items = roster.getRosterItems();
sendRosterToComponent(myPacket, items);
sendRosterToComponent(myPacket, items, subdomain);
} catch (UserNotFoundException e) {
e.printStackTrace();
}
} 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");
IQ response = IQ.createResultIQ(requestPacket);
response.setTo(_componentName);
response.setTo(subdomain);
Element query = new DefaultElement("query");
for (RosterItem i : items) {
if (i.getJid().toString().contains(_componentName)) {
Log.debug("Roster exchange for external component " + _componentName + ". Sending user "
if (i.getJid().toString().contains(subdomain)) {
Log.debug("Roster exchange for external component " + subdomain + ". Sending user "
+ i.getJid().toString());
Element item = new DefaultElement("item", null);
item.add(new DefaultAttribute("jid", i.getJid().toString()));
......@@ -87,11 +87,11 @@ public class SendRosterProcessor extends AbstractRemoteRosterProcessor {
dispatchPacket(response);
}
private void sendEmptyRoster(Packet requestPacket){
private void sendEmptyRoster(Packet requestPacket, String subdomain){
Log.debug("Sending nonpersistant-RemoteRosterResponse to external Component");
IQ iq = (IQ) requestPacket;
IQ response = IQ.createResultIQ(iq);
response.setTo(_componentName);
response.setTo(subdomain);
Element query = new DefaultElement("query");
query.addNamespace("", "jabber:iq:roster");
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