activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1060803 - in /activemq/trunk: activemq-core/src/main/java/org/apache/activemq/broker/jmx/ activemq-core/src/main/java/org/apache/activemq/broker/util/ activemq-web/src/main/java/org/apache/activemq/web/ assembly/src/release/conf/
Date Wed, 19 Jan 2011 13:13:51 GMT
Author: dejanb
Date: Wed Jan 19 13:13:50 2011
New Revision: 1060803

URL: http://svn.apache.org/viewvc?rev=1060803&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3100 - audit logging provide more data in audit
loge event object

Added:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogEntry.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/JMXAuditLogEntry.java
      - copied, changed from r1060353, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java
    activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/HttpAuditLogEntry.java
      - copied, changed from r1060353, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
    activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java
    activemq/trunk/assembly/src/release/conf/log4j.properties

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java?rev=1060803&r1=1060802&r2=1060803&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java
Wed Jan 19 13:13:50 2011
@@ -16,9 +16,7 @@
  */
 package org.apache.activemq.broker.jmx;
 
-import org.apache.activemq.broker.util.AuditLog;
-import org.apache.activemq.broker.util.AuditLogService;
-import org.apache.activemq.broker.util.DefaultAuditLog;
+import org.apache.activemq.broker.util.*;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -179,7 +177,14 @@ public class AnnotatedMBean extends Stan
                     caller += principal.getName() + " ";
                 }
             }
-            auditLog.log(caller.trim() + " called " + this.getMBeanInfo().getClassName()
+ "." + s  + Arrays.toString(objects));
+
+            AuditLogEntry entry = new JMXAuditLogEntry();
+            entry.setUser(caller);
+            entry.setTimestamp(System.currentTimeMillis());
+            entry.setOperation(this.getMBeanInfo().getClassName() + "." + s);
+            entry.getParameters().put("arguments", objects);
+
+            auditLog.log(entry);
         }
         return super.invoke(s, objects, strings);
     }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java?rev=1060803&r1=1060802&r2=1060803&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java
Wed Jan 19 13:13:50 2011
@@ -19,6 +19,6 @@ package org.apache.activemq.broker.util;
 
 public interface AuditLog {
 
-    public void log(String message);
+    public void log(AuditLogEntry entry);
 
 }

Added: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogEntry.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogEntry.java?rev=1060803&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogEntry.java
(added)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogEntry.java
Wed Jan 19 13:13:50 2011
@@ -0,0 +1,79 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.broker.util;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+public class AuditLogEntry {
+
+    protected String user = "anonymous";
+    protected long timestamp;
+    protected String operation;
+    protected String remoteAddr;
+
+    SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss,SSS");
+
+    protected Map<String, Object> parameters = new HashMap<String, Object>();
+
+    public String getUser() {
+        return user;
+    }
+
+    public void setUser(String user) {
+        this.user = user;
+    }
+
+    public long getTimestamp() {
+        return timestamp;
+    }
+
+    public void setTimestamp(long timestamp) {
+        this.timestamp = timestamp;
+    }
+
+    public String getFormattedTime() {
+        return formatter.format(new Date(timestamp));
+    }
+
+    public String getOperation() {
+        return operation;
+    }
+
+    public void setOperation(String operation) {
+        this.operation = operation;
+    }
+
+    public String getRemoteAddr() {
+        return remoteAddr;
+    }
+
+    public void setRemoteAddr(String remoteAddr) {
+        this.remoteAddr = remoteAddr;
+    }
+
+    public Map<String, Object> getParameters() {
+        return parameters;
+    }
+
+    public void setParameters(Map<String, Object> parameters) {
+        this.parameters = parameters;
+    }
+}
\ No newline at end of file

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java?rev=1060803&r1=1060802&r2=1060803&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
Wed Jan 19 13:13:50 2011
@@ -33,9 +33,9 @@ public class AuditLogService {
         factory = new DefaultAuditLogFactory();
     }
 
-    public void log(String message) {
+    public void log(AuditLogEntry entry) {
         for (AuditLog log : factory.getAuditLogs()) {
-            log.log(message);
+            log.log(entry);
         }
     }
 

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java?rev=1060803&r1=1060802&r2=1060803&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/DefaultAuditLog.java
Wed Jan 19 13:13:50 2011
@@ -23,7 +23,7 @@ public class DefaultAuditLog implements 
 
     private static final Log LOG = LogFactory.getLog("org.apache.activemq.audit");
 
-    public void log(String message) {
-         LOG.info(message);
+    public void log(AuditLogEntry entry) {
+         LOG.info(entry.toString());
     }
 }

Copied: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/JMXAuditLogEntry.java
(from r1060353, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java)
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/JMXAuditLogEntry.java?p2=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/JMXAuditLogEntry.java&p1=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java&r1=1060353&r2=1060803&rev=1060803&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLog.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/JMXAuditLogEntry.java
Wed Jan 19 13:13:50 2011
@@ -14,11 +14,14 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.activemq.broker.util;
 
-public interface AuditLog {
+import java.util.Arrays;
 
-    public void log(String message);
+public class JMXAuditLogEntry extends AuditLogEntry {
 
+    @Override
+    public String toString() {
+        return user.trim() + " called " + operation + Arrays.toString((Object[])parameters.get("arguments"))
+ " at " + getFormattedTime();
+    }
 }

Modified: activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java?rev=1060803&r1=1060802&r2=1060803&view=diff
==============================================================================
--- activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java (original)
+++ activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/AuditFilter.java Wed
Jan 19 13:13:50 2011
@@ -16,16 +16,14 @@
  */
 package org.apache.activemq.web;
 
-import org.apache.activemq.broker.util.AuditLog;
+import org.apache.activemq.broker.util.AuditLogEntry;
 import org.apache.activemq.broker.util.AuditLogService;
-import org.apache.activemq.broker.util.DefaultAuditLog;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import javax.servlet.*;
 import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
-import java.util.Enumeration;
 
 public class AuditFilter implements Filter {
 
@@ -48,18 +46,15 @@ public class AuditFilter implements Filt
         if (audit && request instanceof HttpServletRequest) {
 
             HttpServletRequest http = (HttpServletRequest)request;
-            Enumeration params = http.getParameterNames();
-            String formattedParams = "";
-            while (params.hasMoreElements()) {
-                String paramName = (String)params.nextElement();
-                String paramValue = http.getParameter(paramName);
-                formattedParams += paramName + "='" + paramValue + "' ";
-            }
-            String user = "anonymous";
+            AuditLogEntry entry = new HttpAuditLogEntry();
             if (http.getRemoteUser() != null) {
-                user = http.getRemoteUser();
+                entry.setUser(http.getRemoteUser());
             }
-            auditLog.log(user + " requested " + http.getRequestURI() + " [" + formattedParams
+ "] from " + http.getRemoteAddr());
+            entry.setTimestamp(System.currentTimeMillis());
+            entry.setOperation(http.getRequestURI());
+            entry.setRemoteAddr(http.getRemoteAddr());
+            entry.getParameters().put("params", http.getParameterMap());
+            auditLog.log(entry);
         }
         chain.doFilter(request, response);
     }

Copied: activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/HttpAuditLogEntry.java
(from r1060353, activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java)
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/HttpAuditLogEntry.java?p2=activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/HttpAuditLogEntry.java&p1=activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java&r1=1060353&r2=1060803&rev=1060803&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/util/AuditLogService.java
(original)
+++ activemq/trunk/activemq-web/src/main/java/org/apache/activemq/web/HttpAuditLogEntry.java
Wed Jan 19 13:13:50 2011
@@ -14,32 +14,24 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.activemq.broker.util;
+package org.apache.activemq.web;
 
-public class AuditLogService {
+import org.apache.activemq.broker.util.AuditLogEntry;
 
-    private AuditLogFactory factory;
+import java.util.Arrays;
+import java.util.Map;
 
-    private static AuditLogService auditLog;
-
-    public static AuditLogService getAuditLog() {
-        if (auditLog == null) {
-            auditLog = new AuditLogService();
+public class HttpAuditLogEntry extends AuditLogEntry {
+    @Override
+    public String toString() {
+        String formattedParams = "";
+        Map<String, String[]> params = (Map<String, String[]>)parameters.get("params");
+        if (params != null) {
+            for (String paramName : params.keySet()) {
+                formattedParams += paramName + "='" + Arrays.toString(params.get(paramName))
+ "' ";
+            }
         }
-        return auditLog;
-    }
-
-    private AuditLogService() {
-        factory = new DefaultAuditLogFactory();
-    }
-
-    public void log(String message) {
-        for (AuditLog log : factory.getAuditLogs()) {
-            log.log(message);
-        }
-    }
 
-    public void setFactory(AuditLogFactory factory) {
-        this.factory = factory;
+        return user + " requested " + operation + " [" + formattedParams + "] from  " + remoteAddr
+" at " + getFormattedTime();
     }
-}
\ No newline at end of file
+}

Modified: activemq/trunk/assembly/src/release/conf/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/trunk/assembly/src/release/conf/log4j.properties?rev=1060803&r1=1060802&r2=1060803&view=diff
==============================================================================
--- activemq/trunk/assembly/src/release/conf/log4j.properties (original)
+++ activemq/trunk/assembly/src/release/conf/log4j.properties Wed Jan 19 13:13:50 2011
@@ -63,4 +63,4 @@ log4j.appender.audit.maxFileSize=1024KB
 log4j.appender.audit.maxBackupIndex=5
 log4j.appender.audit.append=true
 log4j.appender.audit.layout=org.apache.log4j.PatternLayout
-log4j.appender.audit.layout.ConversionPattern=%d | %-5p | %m | %t%n
\ No newline at end of file
+log4j.appender.audit.layout.ConversionPattern=%-5p | %m | %t%n
\ No newline at end of file



Mime
View raw message