mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-3100 - audit logging provide more data in audit loge event object
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1060803 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a0a1e643e4
commit
b026971933
|
@ -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 StandardMBean {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -19,6 +19,6 @@ package org.apache.activemq.broker.util;
|
|||
|
||||
public interface AuditLog {
|
||||
|
||||
public void log(String message);
|
||||
public void log(AuditLogEntry entry);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ public class DefaultAuditLog implements AuditLog {
|
|||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* 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.util.Arrays;
|
||||
|
||||
public class JMXAuditLogEntry extends AuditLogEntry {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return user.trim() + " called " + operation + Arrays.toString((Object[])parameters.get("arguments")) + " at " + getFormattedTime();
|
||||
}
|
||||
}
|
|
@ -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 Filter {
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* 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.web;
|
||||
|
||||
import org.apache.activemq.broker.util.AuditLogEntry;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
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 user + " requested " + operation + " [" + formattedParams + "] from " + remoteAddr +" at " + getFormattedTime();
|
||||
}
|
||||
}
|
|
@ -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
|
||||
log4j.appender.audit.layout.ConversionPattern=%-5p | %m | %t%n
|
Loading…
Reference in New Issue