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 ...@@ -52,6 +52,7 @@ GoJara Plugin Changelog
<li>We completely ignore Packets with malformed JIDs now, this should cause less Warnings/Errors</li> <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>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>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> </ul>
......
...@@ -27,7 +27,7 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -27,7 +27,7 @@ public class MainInterceptor implements PacketInterceptor {
private Boolean frozen; private Boolean frozen;
public MainInterceptor() { public MainInterceptor() {
Log.debug("Started MainInterceptor for GoJara Plugin."); Log.info("Started MainInterceptor for GoJara Plugin.");
XMPPServer server = XMPPServer.getInstance(); XMPPServer server = XMPPServer.getInstance();
RosterManager rosterMananger = server.getRosterManager(); RosterManager rosterMananger = server.getRosterManager();
...@@ -38,6 +38,8 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -38,6 +38,8 @@ public class MainInterceptor implements PacketInterceptor {
AbstractRemoteRosterProcessor iqLastProcessor = new IQLastProcessor(); AbstractRemoteRosterProcessor iqLastProcessor = new IQLastProcessor();
AbstractRemoteRosterProcessor updateToComponent = new ClientToComponentUpdateProcessor(activeTransports); AbstractRemoteRosterProcessor updateToComponent = new ClientToComponentUpdateProcessor(activeTransports);
AbstractRemoteRosterProcessor whitelistProcessor = new WhitelistProcessor(activeTransports); AbstractRemoteRosterProcessor whitelistProcessor = new WhitelistProcessor(activeTransports);
// AbstractRemoteRosterProcessor mucblockProcessor = new
// MUCBlockProcessor();
packetProcessors.put("sparkIQRegistered", iqRegistered); packetProcessors.put("sparkIQRegistered", iqRegistered);
packetProcessors.put("iqRosterPayload", iqRosterPayload); packetProcessors.put("iqRosterPayload", iqRosterPayload);
packetProcessors.put("handleNonPersistant", nonPersistant); packetProcessors.put("handleNonPersistant", nonPersistant);
...@@ -45,18 +47,19 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -45,18 +47,19 @@ public class MainInterceptor implements PacketInterceptor {
packetProcessors.put("iqLastProcessor", iqLastProcessor); packetProcessors.put("iqLastProcessor", iqLastProcessor);
packetProcessors.put("clientToComponentUpdate", updateToComponent); packetProcessors.put("clientToComponentUpdate", updateToComponent);
packetProcessors.put("whitelistProcessor", whitelistProcessor); packetProcessors.put("whitelistProcessor", whitelistProcessor);
// packetProcessors.put("mucblockProcessor", mucblockProcessor);
frozen = false; frozen = false;
} }
// These get called from our RemoteRosterPlugin // These get called from our RemoteRosterPlugin
public boolean addTransport(String subDomain) { 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); return this.activeTransports.add(subDomain);
} }
public boolean removeTransport(String 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); return this.activeTransports.remove(subDomain);
// if (this.activeTransports.contains(subDomain)) { // if (this.activeTransports.contains(subDomain)) {
// this.activeTransports.remove(subDomain); // this.activeTransports.remove(subDomain);
...@@ -65,9 +68,8 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -65,9 +68,8 @@ public class MainInterceptor implements PacketInterceptor {
// return false; // 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() { public void freeze() {
Log.info("Freezing GoJara Maininterceptor.");
frozen = true; frozen = true;
} }
...@@ -78,10 +80,12 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -78,10 +80,12 @@ public class MainInterceptor implements PacketInterceptor {
* if we find it. * if we find it.
*/ */
private String searchJIDforSubdomain(String jid) { private String searchJIDforSubdomain(String jid) {
if (!jid.isEmpty()) {
for (String subdomain : activeTransports) { for (String subdomain : activeTransports) {
if (subdomain.contains(jid)) if (subdomain.contains(jid))
return subdomain; return subdomain;
} }
}
return ""; return "";
} }
...@@ -101,7 +105,7 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -101,7 +105,7 @@ public class MainInterceptor implements PacketInterceptor {
String from = ""; String from = "";
String to = ""; String to = "";
if (!processed || (incoming && processed)){ if (!processed || (incoming && processed)) {
try { try {
if (packet.getFrom() != null) if (packet.getFrom() != null)
...@@ -114,74 +118,72 @@ public class MainInterceptor implements PacketInterceptor { ...@@ -114,74 +118,72 @@ public class MainInterceptor implements PacketInterceptor {
} }
} }
if (incoming && !processed) { 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) { if (packet instanceof IQ) {
IQ myPacket = (IQ) packet; IQ iqPacket = (IQ) packet;
Element query = myPacket.getChildElement(); Element query = iqPacket.getChildElement();
if (query == null) if (query == null)
return; 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")) { else if (query.getNamespaceURI().equals("jabber:iq:roster")) {
Log.debug("Incoming RosterPackage i might be interested in. I'm " + this.hashCode() + "\n Package: \n " if (to.isEmpty() && iqPacket.getType().equals(IQ.Type.set))
+ packet.toString() + "\n");
if (to.isEmpty())
packetProcessors.get("clientToComponentUpdate").process(packet, "", to, from); packetProcessors.get("clientToComponentUpdate").process(packet, "", to, from);
else if (!from.isEmpty() && activeTransports.contains(from)) else if (!from.isEmpty() && activeTransports.contains(from))
packetProcessors.get("iqRosterPayload").process(packet, from, to, from); packetProcessors.get("iqRosterPayload").process(packet, from, to, from);
} }
// Disco#Info - check for register processing // Disco#Info - check for register processing
else if (query.getNamespaceURI().equals("http://jabber.org/protocol/disco#info") && !to.isEmpty() else if (query.getNamespaceURI().equals("http://jabber.org/protocol/disco#info") && !to.isEmpty() && activeTransports.contains(to)
&& activeTransports.contains(to)) { && iqPacket.getType().equals(IQ.Type.get)) {
Log.debug("Incoming Disco#info might be interested in. I'm " + this.hashCode() + "\n Package: \n " + packet.toString()
+ "\n");
packetProcessors.get("sparkIQRegistered").process(packet, to, to, from); packetProcessors.get("sparkIQRegistered").process(packet, to, to, from);
} }
// Check for Rostercleanup in Nonpersistant-mode // 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)) if (activeTransports.contains(from))
packetProcessors.get("handleNonPersistant").process(packet, from, to, from); packetProcessors.get("handleNonPersistant").process(packet, from, to, from);
} }
} else if (incoming && processed && JiveGlobals.getBooleanProperty("plugin.remoteroster.iqLastFilter", false)) { } else if (incoming && processed) {
// JABBER:IQ:LAST // We ignore Pings from S2 to S2 itself. We test for Log first so
if (packet instanceof IQ) { // that we can return in case
IQ myPacket = (IQ) packet; // The packet doesnt have any watched namespace, but we still may
Element query = myPacket.getChildElement(); // want to log it.
if (query != null && query.getNamespaceURI().equals("jabber:iq:last")) { String from_s = searchJIDforSubdomain(from);
String subdomain = searchJIDforSubdomain(to); String to_s = searchJIDforSubdomain(to);
if (!subdomain.isEmpty()) { String subdomain = from_s.isEmpty() ? to_s : from_s;
Log.debug("Incoming unprocessed Package i might be interested in. I'm " + this.hashCode() + "\n Package: \n " if (!from.equals(to) && !subdomain.isEmpty())
+ packet.toString() + "\n"); packetProcessors.get("statisticsProcessor").process(packet, subdomain, to, from);
packetProcessors.get("iqLastProcessor").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) { } else if (!incoming && !processed) {
// DISCO#ITEMS - Whitelisting Feature
if (packet instanceof IQ) { if (packet instanceof IQ) {
IQ myPacket = (IQ) packet; IQ iqPacket = (IQ) packet;
Element query = myPacket.getChildElement(); Element query = iqPacket.getChildElement();
if (query != null && query.getNamespaceURI().equals("http://jabber.org/protocol/disco#items")) { if (query == null)
Log.debug("Outgoing processed Package i might be interested in. I'm " + this.hashCode() + " Package: \n " return;
+ packet.toString() + "\n");
packetProcessors.get("whiteListProcessor").process(packet, "", to, from);
}
}
// If we want the StatisticsProcessor to diff between Outgoing and // DISCO#ITEMS - Whitelisting Feature
// Incoming, it would go here 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 ...@@ -27,7 +27,7 @@ public class ClientToComponentUpdateProcessor extends AbstractRemoteRosterProces
public ClientToComponentUpdateProcessor(Set<String> activeTransports) { public ClientToComponentUpdateProcessor(Set<String> activeTransports) {
watchedSubdomains = activeTransports; watchedSubdomains = activeTransports;
Log.debug("Created ClientToComponentUpdateProcessor"); Log.info("Created ClientToComponentUpdateProcessor");
} }
private String searchJIDforSubdomain(String jid) { private String searchJIDforSubdomain(String jid) {
......
...@@ -29,7 +29,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor { ...@@ -29,7 +29,7 @@ public class DiscoIQRegisteredProcessor extends AbstractRemoteRosterProcessor {
private boolean _isRegistered = false; private boolean _isRegistered = false;
public DiscoIQRegisteredProcessor() { public DiscoIQRegisteredProcessor() {
Log.debug("Created DiscoIQRegisteredProcessor"); Log.info("Created DiscoIQRegisteredProcessor");
} }
@Override @Override
......
...@@ -20,7 +20,7 @@ import org.xmpp.packet.Packet; ...@@ -20,7 +20,7 @@ import org.xmpp.packet.Packet;
public class IQLastProcessor extends AbstractRemoteRosterProcessor{ public class IQLastProcessor extends AbstractRemoteRosterProcessor{
public IQLastProcessor() { public IQLastProcessor() {
Log.debug("Created IQLastProcessor"); Log.info("Created IQLastProcessor");
} }
/** /**
......
...@@ -36,7 +36,7 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor { ...@@ -36,7 +36,7 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
private RosterManager _rosterManager; private RosterManager _rosterManager;
public IQRosterPayloadProcessor(RosterManager rosterMananger) { public IQRosterPayloadProcessor(RosterManager rosterMananger) {
Log.debug("Created IQRosterPayloadProcessor"); Log.info("Created IQRosterPayloadProcessor");
_rosterManager = rosterMananger; _rosterManager = rosterMananger;
} }
...@@ -108,7 +108,7 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor { ...@@ -108,7 +108,7 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
dispatchPacket(response); 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); IQ response = IQ.createResultIQ(myPacket);
List<Node> nodes = findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item"); List<Node> nodes = findNodesInDocument(myPacket.getElement().getDocument(), "//roster:item");
...@@ -118,9 +118,10 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor { ...@@ -118,9 +118,10 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
String jid = n.valueOf("@jid"); String jid = n.valueOf("@jid");
String name = n.valueOf("@name"); String name = n.valueOf("@name");
String subvalue = n.valueOf("@subscription"); 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)) if (jid.equals(subdomain))
continue; throw new PacketRejectedException();
if (subvalue.equals("both")) { if (subvalue.equals("both")) {
try { try {
...@@ -132,7 +133,7 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor { ...@@ -132,7 +133,7 @@ public class IQRosterPayloadProcessor extends AbstractRemoteRosterProcessor {
grouplist.add(groupName); grouplist.add(groupName);
} }
boolean rosterPersistent = JiveGlobals.getBooleanProperty("plugin.remoteroster.persistent", true); 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 { try {
RosterItem item = roster.getRosterItem(new JID(jid)); RosterItem item = roster.getRosterItem(new JID(jid));
item.setGroups(grouplist); 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 ...@@ -24,7 +24,7 @@ public class NonPersistantRosterProcessor extends AbstractRemoteRosterProcessor
private RosterManager _rosterManager; private RosterManager _rosterManager;
public NonPersistantRosterProcessor(RosterManager rostermananger) { public NonPersistantRosterProcessor(RosterManager rostermananger) {
Log.debug("Created NonPersistantProcessor"); Log.info("Created NonPersistantProcessor");
_rosterManager = rostermananger; _rosterManager = rostermananger;
} }
......
...@@ -18,7 +18,7 @@ public class StatisticsProcessor extends AbstractRemoteRosterProcessor{ ...@@ -18,7 +18,7 @@ public class StatisticsProcessor extends AbstractRemoteRosterProcessor{
private DatabaseManager _db; private DatabaseManager _db;
public StatisticsProcessor() { public StatisticsProcessor() {
Log.debug("Created StatisticsProcessor"); Log.info("Created StatisticsProcessor");
_db = DatabaseManager.getInstance(); _db = DatabaseManager.getInstance();
} }
...@@ -26,6 +26,7 @@ public class StatisticsProcessor extends AbstractRemoteRosterProcessor{ ...@@ -26,6 +26,7 @@ public class StatisticsProcessor extends AbstractRemoteRosterProcessor{
* At this Point we Already know: * At this Point we Already know:
* neither of both JIDS is malformed (Package wouldn't have been intercepted) * neither of both JIDS is malformed (Package wouldn't have been intercepted)
* Package is incoming & processed * Package is incoming & processed
*
* Either From or To contains the watched,passed subdomain * 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 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 * 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 { ...@@ -28,7 +28,7 @@ public class WhitelistProcessor extends AbstractRemoteRosterProcessor {
public WhitelistProcessor(Set<String> activeTransports) { public WhitelistProcessor(Set<String> activeTransports) {
_permissions = new PermissionManager(); _permissions = new PermissionManager();
watchedSubdomains = activeTransports; watchedSubdomains = activeTransports;
Log.debug("Created WhitelistProcessor"); Log.info("Created WhitelistProcessor");
} }
/** /**
......
...@@ -27,6 +27,9 @@ ...@@ -27,6 +27,9 @@
String iqLastFilterPram = request.getParameter("iqLastFilter"); String iqLastFilterPram = request.getParameter("iqLastFilter");
boolean iqLastFilter = iqLastFilterPram == null ? false : iqLastFilterPram.equals("true"); 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[]"); String[] componentsEnabled = request.getParameterValues("enabledComponents[]");
PermissionManager _pmanager = new PermissionManager(); PermissionManager _pmanager = new PermissionManager();
DatabaseManager _db; DatabaseManager _db;
...@@ -48,6 +51,7 @@ ...@@ -48,6 +51,7 @@
JiveGlobals.setProperty("plugin.remoteroster.persistent", (persistentRoster ? "true" : "false")); JiveGlobals.setProperty("plugin.remoteroster.persistent", (persistentRoster ? "true" : "false"));
JiveGlobals.setProperty("plugin.remoteroster.sparkDiscoInfo", (sparkDiscoInfo ? "true" : "false")); JiveGlobals.setProperty("plugin.remoteroster.sparkDiscoInfo", (sparkDiscoInfo ? "true" : "false"));
JiveGlobals.setProperty("plugin.remoteroster.iqLastFilter", (iqLastFilter ? "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"); response.sendRedirect("rr-main.jsp?success=true");
return; return;
} }
...@@ -349,6 +353,20 @@ ...@@ -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 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> for a response we could answer with a service-unavailable message as described in XEP-12.</td>
</tr> </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> </tbody>
</table> </table>
</td> </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