001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.apache.activemq.broker.util; 019 020import java.lang.annotation.Annotation; 021import java.lang.reflect.Method; 022import java.text.SimpleDateFormat; 023import java.util.Date; 024import java.util.HashMap; 025import java.util.Map; 026 027import org.apache.activemq.broker.jmx.Sensitive; 028 029public class AuditLogEntry { 030 031 protected String user = "anonymous"; 032 protected long timestamp; 033 protected String operation; 034 protected String remoteAddr; 035 036 SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss,SSS"); 037 038 protected Map<String, Object> parameters = new HashMap<String, Object>(); 039 040 public String getUser() { 041 return user; 042 } 043 044 public void setUser(String user) { 045 this.user = user; 046 } 047 048 public long getTimestamp() { 049 return timestamp; 050 } 051 052 public void setTimestamp(long timestamp) { 053 this.timestamp = timestamp; 054 } 055 056 public String getFormattedTime() { 057 return formatter.format(new Date(timestamp)); 058 } 059 060 public String getOperation() { 061 return operation; 062 } 063 064 public void setOperation(String operation) { 065 this.operation = operation; 066 } 067 068 public String getRemoteAddr() { 069 return remoteAddr; 070 } 071 072 public void setRemoteAddr(String remoteAddr) { 073 this.remoteAddr = remoteAddr; 074 } 075 076 public Map<String, Object> getParameters() { 077 return parameters; 078 } 079 080 public void setParameters(Map<String, Object> parameters) { 081 this.parameters = parameters; 082 } 083 084 /** 085 * Method to remove any sensitive parameters before logging. Replaces any sensitive value with ****. Sensitive 086 * values are defined on MBean interface implementation method parameters using the @Sensitive annotation. 087 * 088 * @param arguments A array of arguments to test against method signature 089 * @param method The method to test the arguments against. 090 */ 091 public static Object[] sanitizeArguments(Object[] arguments, Method method) 092 { 093 Object[] sanitizedArguments = arguments.clone(); 094 Annotation[][] parameterAnnotations = method.getParameterAnnotations(); 095 096 for (int i = 0; i < arguments.length; i++) 097 { 098 for (Annotation annotation : parameterAnnotations[i]) 099 { 100 if (annotation instanceof Sensitive) 101 { 102 sanitizedArguments[i] = "****"; 103 break; 104 } 105 } 106 } 107 return sanitizedArguments; 108 } 109}