Commit 95443385 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Added ignore list. JM-330


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1632 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9e9c71f2
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
package org.jivesoftware.messenger.audit; package org.jivesoftware.messenger.audit;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
/** /**
...@@ -221,5 +222,20 @@ public interface AuditManager { ...@@ -221,5 +222,20 @@ public interface AuditManager {
* @return An iterator of all XPath expressions the audit manager is using * @return An iterator of all XPath expressions the audit manager is using
*/ */
Iterator getXPathFilters(); Iterator getXPathFilters();
/**
* Sets the list of usernames that won't be audited. Packets sent or received by any of
* these users will be ignored by the auditor.
*
* @param usernames the list of usernames that won't be audited.
*/
void setIgnoreList(Collection<String> usernames);
/**
* Returns the list of usernames that won't be audited. Packets sent or received by any of
* these users will be ignored by the auditor.
*
* @return the list of usernames that won't be audited.
*/
Collection<String> getIgnoreList();
} }
\ No newline at end of file
...@@ -20,11 +20,10 @@ import org.jivesoftware.messenger.interceptor.InterceptorManager; ...@@ -20,11 +20,10 @@ import org.jivesoftware.messenger.interceptor.InterceptorManager;
import org.jivesoftware.messenger.interceptor.PacketInterceptor; import org.jivesoftware.messenger.interceptor.PacketInterceptor;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.xmpp.packet.JID;
import java.io.File; import java.io.File;
import java.util.Iterator; import java.util.*;
import java.util.LinkedList;
import java.util.List;
/** /**
* Implementation of the AuditManager interface. * Implementation of the AuditManager interface.
...@@ -42,6 +41,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -42,6 +41,7 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
private int maxCount; private int maxCount;
private int logTimeout; private int logTimeout;
private String logDir; private String logDir;
private Collection<String> ignoreList = new ArrayList<String>();
private static final int MAX_FILE_SIZE = 10; private static final int MAX_FILE_SIZE = 10;
private static final int MAX_FILE_COUNT = 10; private static final int MAX_FILE_COUNT = 10;
private static final int DEFAULT_LOG_TIMEOUT = 120000; private static final int DEFAULT_LOG_TIMEOUT = 120000;
...@@ -170,6 +170,28 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -170,6 +170,28 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
return xpath.iterator(); return xpath.iterator();
} }
public void setIgnoreList(Collection<String> usernames) {
if (ignoreList.equals(usernames)) {
return;
}
ignoreList = usernames;
// Encode the collection
StringBuilder ignoreString = new StringBuilder();
for (String username : ignoreList) {
if (ignoreString.length() == 0) {
ignoreString.append(username);
}
else {
ignoreString.append(",").append(username);
}
}
JiveGlobals.setProperty("xmpp.audit.ignore", ignoreString.toString());
}
public Collection<String> getIgnoreList() {
return Collections.unmodifiableCollection(ignoreList);
}
// ######################################################################### // #########################################################################
// Basic module methods // Basic module methods
// ######################################################################### // #########################################################################
...@@ -191,6 +213,14 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -191,6 +213,14 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
logTimeout = JiveGlobals.getIntProperty("xmpp.audit.logtimeout", DEFAULT_LOG_TIMEOUT); logTimeout = JiveGlobals.getIntProperty("xmpp.audit.logtimeout", DEFAULT_LOG_TIMEOUT);
logDir = JiveGlobals.getProperty("xmpp.audit.logdir", JiveGlobals.getHomeDirectory() + logDir = JiveGlobals.getProperty("xmpp.audit.logdir", JiveGlobals.getHomeDirectory() +
File.separator + "logs"); File.separator + "logs");
String ignoreString = JiveGlobals.getProperty("xmpp.audit.ignore", "");
// Decode the ignore list
StringTokenizer tokenizer = new StringTokenizer(ignoreString, ", ");
while (tokenizer.hasMoreTokens()) {
String username = tokenizer.nextToken();
ignoreList.add(username);
}
auditor = new AuditorImpl(this); auditor = new AuditorImpl(this);
auditor.setMaxValues(maxSize, maxCount); auditor.setMaxValues(maxSize, maxCount);
auditor.setLogTimeout(logTimeout); auditor.setLogTimeout(logTimeout);
...@@ -212,7 +242,13 @@ public class AuditManagerImpl extends BasicModule implements AuditManager { ...@@ -212,7 +242,13 @@ public class AuditManagerImpl extends BasicModule implements AuditManager {
public void interceptPacket(Packet packet, Session session, boolean read, boolean processed) { public void interceptPacket(Packet packet, Session session, boolean read, boolean processed) {
if (!processed) { if (!processed) {
auditor.audit(packet, session); // Ignore packets sent or received by users that are present in the ignore list
JID from = packet.getFrom();
JID to = packet.getTo();
if ((from == null || !ignoreList.contains(from.getNode())) &&
(to == null || !ignoreList.contains(to.getNode()))) {
auditor.audit(packet, session);
}
} }
} }
} }
......
...@@ -13,7 +13,11 @@ ...@@ -13,7 +13,11 @@
org.jivesoftware.admin.*, org.jivesoftware.admin.*,
org.jivesoftware.util.*, org.jivesoftware.util.*,
java.util.*, java.util.*,
java.io.File" java.io.File,
org.xmpp.component.ComponentManagerFactory,
org.xmpp.packet.JID,
java.util.LinkedList,
org.jivesoftware.messenger.user.UserNotFoundException"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
...@@ -32,6 +36,11 @@ ...@@ -32,6 +36,11 @@
%> %>
<jsp:include page="top.jsp" flush="true" /> <jsp:include page="top.jsp" flush="true" />
<jsp:include page="title.jsp" flush="true" /> <jsp:include page="title.jsp" flush="true" />
<script language="JavaScript" type="text/javascript">
function openWin(el) {
var win = window.open('user-browser.jsp?formName=f&elName=ignore','newWin','width=500,height=550,menubar=yes,location=no,personalbar=no,scrollbars=yes,resize=yes');
}
</script>
<% // Get parameters: <% // Get parameters:
boolean update = request.getParameter("update") != null; boolean update = request.getParameter("update") != null;
...@@ -46,6 +55,8 @@ ...@@ -46,6 +55,8 @@
String maxSize = ParamUtils.getParameter(request,"maxSize"); String maxSize = ParamUtils.getParameter(request,"maxSize");
String logTimeout = ParamUtils.getParameter(request,"logTimeout"); String logTimeout = ParamUtils.getParameter(request,"logTimeout");
String logDir = ParamUtils.getParameter(request,"logDir"); String logDir = ParamUtils.getParameter(request,"logDir");
String ignore = ParamUtils.getParameter(request,"ignore");
// Get an audit manager: // Get an audit manager:
AuditManager auditManager = admin.getXMPPServer().getAuditManager(); AuditManager auditManager = admin.getXMPPServer().getAuditManager();
...@@ -91,8 +102,37 @@ ...@@ -91,8 +102,37 @@
errors.put("logDir","logDir"); errors.put("logDir","logDir");
} }
} }
// All done, redirect
if (errors.size() == 0){ if (errors.size() == 0){
if (ignore == null){
// remove all ignored users
auditManager.setIgnoreList(new ArrayList<String>());
}
else {
// Set the new ignore list
Collection<String> newIgnoreList = new HashSet<String>(ignore.length());
StringTokenizer tokenizer = new StringTokenizer(ignore, ", \t\n\r\f");
while (tokenizer.hasMoreTokens()) {
String tok = tokenizer.nextToken();
String username = tok;
if (tok.contains("@")) {
if (tok.contains("@" + admin.getServerInfo().getName())) {
username = new JID(tok).getNode();
}
else {
// Skip this JID since it belongs to a remote server
continue;
}
}
try {
admin.getUserManager().getUser(username);
newIgnoreList.add(username);
}
catch (UserNotFoundException e){
}
}
auditManager.setIgnoreList(newIgnoreList);
}
// All done, redirect
%> %>
<div class="jive-success"> <div class="jive-success">
...@@ -121,6 +161,16 @@ ...@@ -121,6 +161,16 @@
maxSize = Integer.toString(auditManager.getMaxFileSize()); maxSize = Integer.toString(auditManager.getMaxFileSize());
logTimeout = Integer.toString(auditManager.getLogTimeout() / 1000); logTimeout = Integer.toString(auditManager.getLogTimeout() / 1000);
logDir = auditManager.getLogDir(); logDir = auditManager.getLogDir();
StringBuilder ignoreList = new StringBuilder();
for (String username : auditManager.getIgnoreList()) {
if (ignoreList.length() == 0) {
ignoreList.append(username);
}
else {
ignoreList.append(", ").append(username);
}
}
ignore = ignoreList.toString();
} }
%> %>
...@@ -129,7 +179,7 @@ ...@@ -129,7 +179,7 @@
<fmt:message key="audit.policy.title_info" /> <fmt:message key="audit.policy.title_info" />
</p> </p>
<form action="audit-policy.jsp"> <form action="audit-policy.jsp" name="f">
<fieldset> <fieldset>
<legend><fmt:message key="audit.policy.policytitle" /></legend> <legend><fmt:message key="audit.policy.policytitle" /></legend>
...@@ -282,6 +332,30 @@ ...@@ -282,6 +332,30 @@
</table> </table>
</td> </td>
</tr> </tr>
<tr valign="top">
<td width="1%" nowrap class="c1">
<fmt:message key="audit.policy.ignore" />
</td>
<td width="99%">
<table>
<td>
<textarea name="ignore" cols="40" rows="3" wrap="virtual"><%= ((ignore != null) ? ignore : "") %></textarea>
<% if (errors.get("ignore") != null) { %>
<span class="jive-error-text">
<fmt:message key="audit.policy.validignore" />
</span>
<% } %>
</td>
<td nowrap valign="top">
<a href="#" onclick="openWin(document.f.ignore);return false;"
title="Click to browse available users..."
><img src="images/user.gif" border="0"/> Browse Users</a>
</td>
</table>
</td>
</tr>
</table> </table>
</td> </td>
</tr> </tr>
......
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