Commit 5d94a9ef authored by guus's avatar guus

* Updating 'packetFilter' plugin to make use of SLF4J instead of custom logging (OF-53).

* Applied java generics.
* Removed unused code.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@11443 b35dd754-fafc-0310-a699-88a17e54d16e
parent f9038218
......@@ -44,6 +44,15 @@
Packet Filter Plugin Changelog
</h1>
<p><b>3.0</b> -- Dec 2, 2009</p>
<ul>
<li>Now requires Openfire 3.6.5.</li>
<li>Applied Java generics.</li>
<li>Removed unused code.</li>
<li>[<a href='http://www.igniterealtime.org/issues/browse/OF-53'>OF-53</a>] - Replace custom logging implementation with a third party library.</li>
</ul>
<p><b>2.0</b> -- Dec 8, 2007</p>
<ul>
......
......@@ -7,9 +7,9 @@
<name>Packet Filter</name>
<description>Rules to enforce ethical communication</description>
<author>Nate Putnam</author>
<version>2.0.2</version>
<date>12/8/2007</date>
<minServerVersion>3.6.0</minServerVersion>
<version>3.0.0</version>
<date>12/2/2009</date>
<minServerVersion>3.6.5</minServerVersion>
<databaseKey>packetfilter</databaseKey>
<databaseVersion>2</databaseVersion>
......
......@@ -5,7 +5,6 @@ import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.jivesoftware.openfire.plugin.rules.Rule;
import org.jivesoftware.openfire.plugin.rules.RuleManager;
import org.jivesoftware.util.Log;
import org.xmpp.packet.*;
public class PacketFilter {
......
package org.jivesoftware.openfire.plugin;
import org.jivesoftware.openfire.XMPPServer;
import java.io.File;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.interceptor.InterceptorManager;
......@@ -10,13 +11,14 @@ import org.jivesoftware.openfire.plugin.rules.Rule;
import org.jivesoftware.openfire.plugin.rules.RuleManager;
import org.jivesoftware.openfire.plugin.rules.RuleManagerProxy;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.Packet;
import java.io.File;
public class PacketFilterPlugin implements Plugin, PacketInterceptor {
private static final Logger Log = LoggerFactory.getLogger(PacketFilterPlugin.class);
private static PluginManager pluginManager;
public PacketFilterPlugin() {
......@@ -34,7 +36,7 @@ public class PacketFilterPlugin implements Plugin, PacketInterceptor {
// register with interceptor manager
Log.info("Packet Filter loaded...");
interceptorManager.addInterceptor(this);
this.pluginManager = manager;
pluginManager = manager;
pf = PacketFilter.getInstance();
RuleManager ruleManager = new RuleManagerProxy();
pf.setRuleManager(ruleManager);
......
package org.jivesoftware.openfire.plugin;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.group.GroupManager;
import org.jivesoftware.openfire.group.GroupNotFoundException;
import org.jivesoftware.openfire.user.UserManager;
import org.xmpp.packet.JID;
import java.util.Collection;
/*
Static util methods.
*/
......
package org.jivesoftware.openfire.plugin.component;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.dom4j.Element;
import org.xmpp.component.IQResultListener;
import org.jivesoftware.openfire.IQRouter;
import org.jivesoftware.openfire.RoutingTable;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.util.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.component.IQResultListener;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class ComponentList implements IQResultListener {
private static final Logger Log = LoggerFactory.getLogger(ComponentList.class);
private static ComponentList instance = new ComponentList();
private XMPPServer server = XMPPServer.getInstance();
private RoutingTable routingTable = server.getRoutingTable();
......@@ -48,8 +50,8 @@ public class ComponentList implements IQResultListener {
Element child = packet.getChildElement();
if (child != null) {
for (Iterator it = child.elementIterator("identity"); it.hasNext();) {
Element identity = (Element) it.next();
for (Iterator<Element> it = child.elementIterator("identity"); it.hasNext();) {
Element identity = it.next();
String name = identity.attributeValue("name");
componentMap.put(packet.getFrom().toString(), name);
}
......
......@@ -3,8 +3,6 @@ package org.jivesoftware.openfire.plugin.rules;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.xmpp.packet.Packet;
import java.util.List;
public abstract class AbstractRule implements Rule {
......
package org.jivesoftware.openfire.plugin.rules;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.plugin.cluster.RulesUpdatedEvent;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.cache.CacheFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.plugin.cluster.RulesUpdatedEvent;
import org.jivesoftware.util.cache.CacheFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DbRuleManager {
//SQL Statments
private static final Logger Log = LoggerFactory.getLogger(DbRuleManager.class);
//SQL Statements
private static final String UPDATE_RULE =
"UPDATE ofPfRules" +
......@@ -33,8 +36,8 @@ public class DbRuleManager {
private static final String GET_RULES =
"SELECT rulef,id,type,tojid,fromjid,disabled,log,description,ruleorder,sourcetype,desttype from ofPfRules order by ruleorder";
private static final String RULE_OPTIONS =
"SELECT optionKey, optionValue, optionRequired, classType from ofPfRulesOptions where ruleId = ?";
/*private static final String RULE_OPTIONS =
"SELECT optionKey, optionValue, optionRequired, classType from ofPfRulesOptions where ruleId = ?";*/
/*private static final String GET_RULE_BY_ID =
"SELECT rule,id,type,tojid,fromjid,disabled,log,description,ruleorder from ofPfRules where id=?";*/
......@@ -100,7 +103,7 @@ public class DbRuleManager {
} catch (SQLException sqle) {
Log.error(sqle);
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
......@@ -112,46 +115,46 @@ public class DbRuleManager {
return rules;
}
private void getSavedOptions() {
if (rules != null) {
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
for (Rule rule : rules) {
Log.info("getting options for rule " + rule.getRuleId());
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(RULE_OPTIONS);
pstmt.setInt(1, Integer.parseInt(rule.getRuleId()));
rs = pstmt.executeQuery();
List<RuleOption> savedOptions = new ArrayList<RuleOption>();
while (rs.next()) {
RuleOption option = new RuleOption();
option.setName(rs.getString(1));
Log.info("Name " + option.getName());
option.setValue(rs.getString(2));
option.setRequired(rs.getBoolean(3));
option.setType(rs.getString(4));
savedOptions.add(option);
}
//rule.setSavedOptions(savedOptions);
pstmt.close();
rs.close();
}
} catch (SQLException sqle) {
Log.error(sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
}
// private void getSavedOptions() {
// if (rules != null) {
// Connection con = null;
// PreparedStatement pstmt = null;
// ResultSet rs = null;
// try {
// for (Rule rule : rules) {
// Log.info("getting options for rule " + rule.getRuleId());
// con = DbConnectionManager.getConnection();
// pstmt = con.prepareStatement(RULE_OPTIONS);
// pstmt.setInt(1, Integer.parseInt(rule.getRuleId()));
//
// rs = pstmt.executeQuery();
// List<RuleOption> savedOptions = new ArrayList<RuleOption>();
// while (rs.next()) {
// RuleOption option = new RuleOption();
// option.setName(rs.getString(1));
// Log.info("Name " + option.getName());
// option.setValue(rs.getString(2));
// option.setRequired(rs.getBoolean(3));
// option.setType(rs.getString(4));
// savedOptions.add(option);
// }
// //rule.setSavedOptions(savedOptions);
// pstmt.close();
// rs.close();
//
//
// }
//
//
// } catch (SQLException sqle) {
// Log.error(sqle.getMessage(), sqle);
// }
// finally {
// DbConnectionManager.closeConnection(pstmt, con);
// }
//
// }
// }
public int getLastOrderId() {
Connection con = null;
......@@ -170,7 +173,7 @@ public class DbRuleManager {
count = 0;
}
} catch (SQLException sqle) {
Log.error(sqle);
Log.error(sqle.getMessage(), sqle);
// Result set probably empty
return 0;
}
......@@ -194,7 +197,7 @@ public class DbRuleManager {
count = rs.getInt(1);
} catch (SQLException sqle) {
Log.error(sqle);
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
......@@ -246,7 +249,7 @@ public class DbRuleManager {
rules.clear();
} catch (SQLException sqle) {
Log.error(sqle);
Log.error(sqle.getMessage(), sqle);
return false;
}
finally {
......@@ -271,7 +274,7 @@ public class DbRuleManager {
rules.remove(getRuleById(new Integer(ruleId)));
} catch (SQLException sqle) {
Log.error(sqle);
Log.error(sqle.getMessage(), sqle);
return false;
}
finally {
......@@ -341,7 +344,7 @@ public class DbRuleManager {
} catch (SQLException sqle) {
Log.error(sqle);
Log.error(sqle.getMessage(), sqle);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
......@@ -398,7 +401,7 @@ public class DbRuleManager {
rules.clear();
} catch (SQLException sqle) {
Log.error(sqle);
Log.error(sqle.getMessage(), sqle);
return false;
}
finally {
......
package org.jivesoftware.openfire.plugin.rules;
import org.xmpp.packet.Packet;
import org.jivesoftware.util.Log;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.Packet;
public class Drop extends AbstractRule implements Rule {
private static final Logger Log = LoggerFactory.getLogger(Drop.class);
public String getDisplayName() {
return "Drop";
}
......
package org.jivesoftware.openfire.plugin.rules;
import org.xmpp.packet.Packet;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.util.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.Packet;
public class Pass extends AbstractRule implements Rule {
private static final Logger Log = LoggerFactory.getLogger(Pass.class);
public String getDisplayName() {
return "Pass";
}
......
......@@ -4,14 +4,19 @@ import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.xmpp.packet.*;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence;
public class Reject extends AbstractRule implements Rule {
private static final Logger Log = LoggerFactory.getLogger(Reject.class);
public String getDisplayName() {
return "Reject";
}
......
......@@ -3,8 +3,6 @@ package org.jivesoftware.openfire.plugin.rules;
import org.jivesoftware.openfire.interceptor.PacketRejectedException;
import org.xmpp.packet.Packet;
import java.util.List;
public interface Rule {
enum Action {
Pass,
......
......@@ -6,7 +6,7 @@ import java.util.List;
public class RuleManagerProxy implements RuleManager {
private DbRuleManager dbRuleManager = DbRuleManager.getInstance();
private List<Rule> rules = null;
//private List<Rule> rules = null;
public RuleManagerProxy() {
// rules = dbRuleManager.getRules();
......
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