Commit 09cac46a authored by Axel Brand's avatar Axel Brand Committed by daeva

- Fixed some Processors / If statements regarding these.

- Added Stub for MUC-Blocking (Website stuff & Processor), not working withour errors yet so still commented out.
- Fixed Error thrown when register:removing a Transport.


git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/plugins@13550 b35dd754-fafc-0310-a699-88a17e54d16e
parent b0970725
......@@ -52,6 +52,7 @@ GoJara Plugin Changelog
<li>We completely ignore Packets with malformed JIDs now, this should cause less Warnings/Errors</li>
<li>Freezing the Interceptor on Destroy of the Plugin should make GoJara properly shutdown and not cause trouble on reload/update</li>
<li>Optimized Processors have better performance</li>
<li>Reject iq:roster packets with item jid=subdomain as they will throw errors on register:remove</li>
</ul>
......
......@@ -27,7 +27,7 @@ public class MainInterceptor implements PacketInterceptor {
private Boolean frozen;
public MainInterceptor() {
Log.debug("Started MainInterceptor for GoJara Plugin.");
Log.info("Started MainInterceptor for GoJara Plugin.");
XMPPServer server = XMPPServer.getInstance();
RosterManager rosterMananger = server.getRosterManager();
......@@ -38,6 +38,8 @@ public class MainInterceptor implements PacketInterceptor {
AbstractRemoteRosterProcessor iqLastProcessor = new IQLastProcessor();
AbstractRemoteRosterProcessor updateToComponent = new ClientToComponentUpdateProcessor(activeTransports);
AbstractRemoteRosterProcessor whitelistProcessor = new WhitelistProcessor(activeTransports);
// AbstractRemoteRosterProcessor mucblockProcessor = new
// MUCBlockProcessor();
packetProcessors.put("sparkIQRegistered", iqRegistered);
packetProcessors.put("iqRosterPayload", iqRosterPayload);
packetProcessors.put("handleNonPersistant", nonPersistant);
......@@ -45,18 +47,19 @@ public class MainInterceptor implements PacketInterceptor {
packetProcessors.put("iqLastProcessor", iqLastProcessor);
packetProcessors.put("clientToComponentUpdate", updateToComponent);
packetProcessors.put("whitelistProcessor", whitelistProcessor);
// packetProcessors.put("mucblockProcessor", mucblockProcessor);
frozen = false;
}
// These get called from our RemoteRosterPlugin
public boolean addTransport(String subDomain) {
Log.debug("Trying to add " + subDomain + "to Set of watched Transports.");
Log.info("Trying to add " + subDomain + " to Set of watched Transports.");
return this.activeTransports.add(subDomain);
}
public boolean removeTransport(String subDomain) {
Log.debug("Trying to remove " + subDomain + " from Set of watched Transports.");
Log.info("Trying to remove " + subDomain + " from Set of watched Transports.");
return this.activeTransports.remove(subDomain);
// if (this.activeTransports.contains(subDomain)) {
// this.activeTransports.remove(subDomain);
......@@ -65,9 +68,8 @@ public class MainInterceptor implements PacketInterceptor {
// return false;
}
// idk if this "smells" but as we still dont know why OF is not correctly
// shutting down our Interceptor better safe then sorry
public void freeze() {
Log.info("Freezing GoJara Maininterceptor.");
frozen = true;
}
......@@ -78,10 +80,12 @@ public class MainInterceptor implements PacketInterceptor {
* if we find it.
*/
private String searchJIDforSubdomain(String jid) {
if (!jid.isEmpty()) {
for (String subdomain : activeTransports) {
if (subdomain.contains(jid))
return subdomain;
}
}
return "";
}
......@@ -101,7 +105,7 @@ public class MainInterceptor implements PacketInterceptor {
String from = "";
String to = "";
if (!processed || (incoming && processed)){
if (!processed || (incoming && processed)) {
try {
if (packet.getFrom() != null)
......@@ -114,74 +118,72 @@ public class MainInterceptor implements PacketInterceptor {
}
}
if (incoming && !processed) {
// We ignore Pings from S2 to S2 itself. We test for Log first so
// that we can return in case
// The packet doesnt have any watched namespace, but we still may want to log it.
String from_s = searchJIDforSubdomain(from);
String to_s = searchJIDforSubdomain(to);
String subdomain = from_s.isEmpty() ? to_s : from_s;
if (!from.equals(to) && !subdomain.isEmpty() && !(from.isEmpty() && to.isEmpty()))
packetProcessors.get("statisticsProcessor").process(packet, subdomain, to, from);
if (packet instanceof IQ) {
IQ myPacket = (IQ) packet;
Element query = myPacket.getChildElement();
IQ iqPacket = (IQ) packet;
Element query = iqPacket.getChildElement();
if (query == null)
return;
// Jabber:IQ:roster Indicates Client to Component update or Rosterpush
// Jabber:IQ:roster Indicates Client to Component update or
// Rosterpush
else if (query.getNamespaceURI().equals("jabber:iq:roster")) {
Log.debug("Incoming RosterPackage i might be interested in. I'm " + this.hashCode() + "\n Package: \n "
+ packet.toString() + "\n");
if (to.isEmpty())
if (to.isEmpty() && iqPacket.getType().equals(IQ.Type.set))
packetProcessors.get("clientToComponentUpdate").process(packet, "", to, from);
else if (!from.isEmpty() && activeTransports.contains(from))
packetProcessors.get("iqRosterPayload").process(packet, from, to, from);
}
// Disco#Info - check for register processing
else if (query.getNamespaceURI().equals("http://jabber.org/protocol/disco#info") && !to.isEmpty()
&& activeTransports.contains(to)) {
Log.debug("Incoming Disco#info might be interested in. I'm " + this.hashCode() + "\n Package: \n " + packet.toString()
+ "\n");
else if (query.getNamespaceURI().equals("http://jabber.org/protocol/disco#info") && !to.isEmpty() && activeTransports.contains(to)
&& iqPacket.getType().equals(IQ.Type.get)) {
packetProcessors.get("sparkIQRegistered").process(packet, to, to, from);
}
// Check for Rostercleanup in Nonpersistant-mode
} else if (packet instanceof Presence && !JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false)) {
} else if (!JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", false) && packet instanceof Presence) {
if (activeTransports.contains(from))
packetProcessors.get("handleNonPersistant").process(packet, from, to, from);
}
} else if (incoming && processed && JiveGlobals.getBooleanProperty("plugin.remoteroster.iqLastFilter", false)) {
// JABBER:IQ:LAST
if (packet instanceof IQ) {
IQ myPacket = (IQ) packet;
Element query = myPacket.getChildElement();
if (query != null && query.getNamespaceURI().equals("jabber:iq:last")) {
String subdomain = searchJIDforSubdomain(to);
if (!subdomain.isEmpty()) {
Log.debug("Incoming unprocessed Package i might be interested in. I'm " + this.hashCode() + "\n Package: \n "
+ packet.toString() + "\n");
packetProcessors.get("iqLastProcessor").process(packet, subdomain, to, from);
}
}
} else if (incoming && processed) {
// We ignore Pings from S2 to S2 itself. We test for Log first so
// that we can return in case
// The packet doesnt have any watched namespace, but we still may
// want to log it.
String from_s = searchJIDforSubdomain(from);
String to_s = searchJIDforSubdomain(to);
String subdomain = from_s.isEmpty() ? to_s : from_s;
if (!from.equals(to) && !subdomain.isEmpty())
packetProcessors.get("statisticsProcessor").process(packet, subdomain, to, from);
// JABBER:IQ:LAST - Autoresponse Feature
if (JiveGlobals.getBooleanProperty("plugin.remoteroster.iqLastFilter", false) && packet instanceof IQ) {
IQ iqPacket = (IQ) packet;
Element query = iqPacket.getChildElement();
if (query != null && query.getNamespaceURI().equals("jabber:iq:last") && !to_s.isEmpty())
packetProcessors.get("iqLastProcessor").process(packet, to_s, to, from);
}
} else if (!incoming && !processed) {
// DISCO#ITEMS - Whitelisting Feature
if (packet instanceof IQ) {
IQ myPacket = (IQ) packet;
Element query = myPacket.getChildElement();
if (query != null && query.getNamespaceURI().equals("http://jabber.org/protocol/disco#items")) {
Log.debug("Outgoing processed Package i might be interested in. I'm " + this.hashCode() + " Package: \n "
+ packet.toString() + "\n");
packetProcessors.get("whiteListProcessor").process(packet, "", to, from);
}
}
IQ iqPacket = (IQ) packet;
Element query = iqPacket.getChildElement();
if (query == null)
return;
// If we want the StatisticsProcessor to diff between Outgoing and
// Incoming, it would go here
// DISCO#ITEMS - Whitelisting Feature
if (query.getNamespaceURI().equals("http://jabber.org/protocol/disco#items"))
packetProcessors.get("whitelistProcessor").process(packet, "", to, from);
// DISCO#INFO - MUC-block-Feature
// else if
// (JiveGlobals.getBooleanProperty("plugin.remoteroster.mucBlock",
// false)
// &&
// query.getNamespaceURI().equals("http://jabber.org/protocol/disco#info")
// && !from.isEmpty() && activeTransports.contains(from))
// packetProcessors.get("mucblockProcessor").process(packet,
// from, to, from);
}
}
}
}
......@@ -27,7 +27,7 @@ public class ClientToComponentUpdateProcessor extends AbstractRemoteRosterProces
public ClientToComponentUpdateProcessor(Set<String> activeTransports) {
watchedSubdomains = activeTransports;
Log.debug("Created ClientToComponentUpdateProcessor");
Log.info("Created ClientToComponentUpdateProcessor");
}
private String searchJIDforSubdomain(String jid) {
......
......@@ -29,7 +29,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
private boolean _isRegistered = false;
public DiscoIQRegisteredProcessor() {
Log.debug("Created DiscoIQRegisteredProcessor");
Log.info("Created DiscoIQRegisteredProcessor");
}
@Override
......
......@@ -20,7 +20,7 @@ import org.xmpp.packet.Packet;
public class IQLastProcessor extends AbstractRemoteRosterProcessor{
public IQLastProcessor() {
Log.debug("Created IQLastProcessor");
Log.info("Created IQLastProcessor");
}
/**
......
......@@ -36,7 +36,7 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
private RosterManager _rosterManager;
public IQRosterPayloadProcessor(RosterManager rosterMananger) {
Log.debug("Created IQRosterPayloadProcessor");
Log.info("Created IQRosterPayloadProcessor");
_rosterManager = rosterMananger;
}
......@@ -108,7 +108,7 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
dispatchPacket(response);
}
private void handleIQset(IQ myPacket, String subdomain, String username) {
private void handleIQset(IQ myPacket, String subdomain, String username) throws PacketRejectedException {
IQ response = IQ.createResultIQ(myPacket);
List<Node> nodes = findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item");
......@@ -118,9 +118,10 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
String jid = n.valueOf("@jid");
String name = n.valueOf("@name");
String subvalue = n.valueOf("@subscription");
// We dont want to add or delete the subdomain itself
// We dont want to add or delete the subdomain itself, so we have to reject that packet, it seems openfire itself
// can interpret the iq:roster remove stanzas in some way, this was causing trouble on register:remove
if (jid.equals(subdomain))
continue;
throw new PacketRejectedException();
if (subvalue.equals("both")) {
try {
......@@ -132,7 +133,7 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
grouplist.add(groupName);
}
boolean rosterPersistent = JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", true);
Log.debug("Adding/Updating Contact " + jid + " to roster of" + username);
Log.debug("Adding/Updating Contact " + jid + " to roster of " + username);
try {
RosterItem item = roster.getRosterItem(new JID(jid));
item.setGroups(grouplist);
......
package org.jivesoftware.openfire.plugin.gojara.messagefilter.processors;
import java.util.List;
import org.dom4j.Element;
import org.dom4j.Node;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.plugin.gojara.utils.XpathHelper;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Packet;
/**
*
* @author axel.frederik.brand
*
*/
public class MUCBlockProcessor extends AbstractRemoteRosterProcessor {
public MUCBlockProcessor() {
Log.info("Created MUCBlockProcessor");
}
/**
* At this Point we know:
* MucBlock = true,
* !incoming, !processed
* Package is IQ with Namespace disco#info,
* from equals the watched subdomain given through subdomain
*/
@Override
public void process(Packet packet, String subdomain, String to, String from) throws PacketRejectedException {
IQ iqPacket = (IQ) packet;
if (iqPacket.getType().equals(IQ.Type.result) && !to.isEmpty()) {
Element root = iqPacket.getChildElement();
List<Node> nodes = XpathHelper.findNodesInDocument(root.getDocument(), "//discoinfo:feature");
for (Node node : nodes) {
String var = node.valueOf("@var");
if (var.equals("http://jabber.org/protocol/muc"))
root.remove(node);
}
}
}
}
......@@ -24,7 +24,7 @@ public class NonPersistantRosterProcessor extends AbstractRemoteRosterProcessor
private RosterManager _rosterManager;
public NonPersistantRosterProcessor(RosterManager rostermananger) {
Log.debug("Created NonPersistantProcessor");
Log.info("Created NonPersistantProcessor");
_rosterManager = rostermananger;
}
......
......@@ -18,7 +18,7 @@ public class StatisticsProcessor extends AbstractRemoteRosterProcessor{
private DatabaseManager _db;
public StatisticsProcessor() {
Log.debug("Created StatisticsProcessor");
Log.info("Created StatisticsProcessor");
_db = DatabaseManager.getInstance();
}
......@@ -26,6 +26,7 @@ public class StatisticsProcessor extends AbstractRemoteRosterProcessor{
* At this Point we Already know:
* neither of both JIDS is malformed (Package wouldn't have been intercepted)
* Package is incoming & processed
*
* Either From or To contains the watched,passed subdomain
* From does not Equal To (This way we exclude PING sent by spectrum To spectrum
* From AND To are NOT empty (null), this way we exclude packets sent to server itself...change Maininterceptor if we want to change this
......
......@@ -28,7 +28,7 @@ public class WhitelistProcessor extends AbstractRemoteRosterProcessor {
public WhitelistProcessor(Set<String> activeTransports) {
_permissions = new PermissionManager();
watchedSubdomains = activeTransports;
Log.debug("Created WhitelistProcessor");
Log.info("Created WhitelistProcessor");
}
/**
......
......@@ -27,6 +27,9 @@
String iqLastFilterPram = request.getParameter("iqLastFilter");
boolean iqLastFilter = iqLastFilterPram == null ? false : iqLastFilterPram.equals("true");
String mucBlockParam = request.getParameter("mucBlock");
boolean mucBlock = mucBlockParam == null ? false : mucBlockParam.equals("true");
String[] componentsEnabled = request.getParameterValues("enabledComponents[]");
PermissionManager _pmanager = new PermissionManager();
DatabaseManager _db;
......@@ -48,6 +51,7 @@
JiveGlobals.setProperty("plugin.remoteroster.persistent", (persistentRoster ? "true" : "false"));
JiveGlobals.setProperty("plugin.remoteroster.sparkDiscoInfo", (sparkDiscoInfo ? "true" : "false"));
JiveGlobals.setProperty("plugin.remoteroster.iqLastFilter", (iqLastFilter ? "true" : "false"));
JiveGlobals.setProperty("plugin.remoteroster.mucBlock", (mucBlock ? "true" : "false"));
response.sendRedirect("rr-main.jsp?success=true");
return;
}
......@@ -349,6 +353,20 @@
This feature is not supported by spectrum so it won't response to this IQ stanza. To prevent the client from waiting
for a response we could answer with a service-unavailable message as described in XEP-12.</td>
</tr>
<tr>
<td><input type="checkbox" name="mucBlock" id="SDI3" value="true"
<%=JiveGlobals.getBooleanProperty("plugin.remoteroster.mucBlock", false) ? "checked=\"checked\""
: ""%> />
</td>
<td><label for="SDI">Only allow internal Jabber Conferences</label></td>
</tr>
<tr>
<td />
<td align="left" style="font-size: -3; color: grey">Spectrum might add MUC(Multi User Chat) to supported features
of some Transports. If this should not be allowed, because only internal Jabber Conferences should be used, GoJara
can remove these.</td>
</tr>
</tbody>
</table>
</td>
......
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