diff --git a/src/main/java/org/audit4j/core/DefaultAnnotationTransformer.java b/src/main/java/org/audit4j/core/DefaultAnnotationTransformer.java index 315cd84..614f0c7 100644 --- a/src/main/java/org/audit4j/core/DefaultAnnotationTransformer.java +++ b/src/main/java/org/audit4j/core/DefaultAnnotationTransformer.java @@ -77,7 +77,7 @@ public AuditEvent transformToEvent(AnnotationAuditEvent annotationEvent) { // Extract Actor String annotationAction = audit.action(); if (ACTION.equals(annotationAction)) { - event.setAction(annotationEvent.getMethod().getName()); + event.setAction(annotationEvent.getMethod().getDeclaringClass().getName() + "." +annotationEvent.getMethod().getName()); } else { event.setAction(annotationAction); } @@ -133,6 +133,7 @@ private List getFields(final Method method, final Object[] params) { int i = 0; String paramName = null; for (final Annotation[] annotations : parameterAnnotations) { + paramName = method.getParameters()[i].getName(); final Object object = params[i++]; boolean ignoreFlag = false; DeIdentify deidentify = null; diff --git a/src/main/java/org/audit4j/core/ObjectToFieldsSerializer.java b/src/main/java/org/audit4j/core/ObjectToFieldsSerializer.java index 3141620..48a5df5 100644 --- a/src/main/java/org/audit4j/core/ObjectToFieldsSerializer.java +++ b/src/main/java/org/audit4j/core/ObjectToFieldsSerializer.java @@ -31,6 +31,10 @@ import org.audit4j.core.dto.Field; import org.audit4j.core.exception.Audit4jRuntimeException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + /** * The Class ToStringGen. * @@ -52,14 +56,14 @@ public final class ObjectToFieldsSerializer implements ObjectSerializer { * @param deidentify the de-identify */ public final void toFields(List auditFields, Object object, String objectName, DeIdentify deidentify) { - String localOjectName = objectName; - if (object == null) { - auditFields.add(new Field(localOjectName, CoreConstants.NULL)); + String localObjectName = objectName; + if (object == null || object instanceof HttpServletRequest || object instanceof HttpServletResponse || object instanceof HttpSession) { + auditFields.add(new Field(localObjectName, CoreConstants.NULL)); return; } Class clazz = object.getClass(); - if (!visited.contains(object)) { + if (visited.size() < 1000 && !visited.contains(object)) { //size check to avoid infinite recursion visited.add(object); if (isPrimitive(object)) { String primitiveValue = String.valueOf(object); @@ -67,18 +71,18 @@ public final void toFields(List auditFields, Object object, String object primitiveValue = DeIdentifyUtil.deidentify(primitiveValue, deidentify.left(), deidentify.right(), deidentify.fromLeft(), deidentify.fromRight()); } - auditFields.add(new Field(localOjectName, primitiveValue, object.getClass() + auditFields.add(new Field(localObjectName, primitiveValue, object.getClass() .getName())); } else if (clazz.isArray()) { if (Array.getLength(object) == 0) { - auditFields.add(new Field(localOjectName + CoreConstants.DOLLAR_CHAR + clazz.getName(), + auditFields.add(new Field(localObjectName + CoreConstants.DOLLAR_CHAR + clazz.getName(), CoreConstants.EMPTY)); } else { // String internalLocalOjectName = localOjectName + CoreConstants.DOLLAR_CHAR + // clazz.getName(); for (int i = 0; i < Array.getLength(object); i++) { Object objVal = Array.get(object, i); - String internalLocalOjectName = localOjectName + CoreConstants.OPEN_BRACES_CHAR + "arg" + String internalLocalOjectName = localObjectName + CoreConstants.OPEN_BRACES_CHAR + "arg" + i + CoreConstants.CLOSE_BRACES_CHAR; if (clazz.getComponentType().isPrimitive()) auditFields.add(new Field(internalLocalOjectName, String @@ -91,10 +95,10 @@ else if (objVal != null) { } else if (object instanceof Collection) { Collection collection = (Collection) object; if (collection.isEmpty()) { - auditFields.add(new Field(localOjectName + CoreConstants.DOLLAR_CHAR + clazz.getName(), + auditFields.add(new Field(localObjectName + CoreConstants.DOLLAR_CHAR + clazz.getName(), CoreConstants.EMPTY)); } else { - String internalLocalOjectName = localOjectName + CoreConstants.DOLLAR_CHAR + object.getClass().getName(); + String internalLocalOjectName = localObjectName + CoreConstants.DOLLAR_CHAR + object.getClass().getName(); int i = 0; for (Object collectionObject : collection) { String internalLocalOjectName2 = internalLocalOjectName + CoreConstants.OPEN_BRACES_CHAR + "arg" + i @@ -109,7 +113,7 @@ else if (objVal != null) { } } } else { - String internalLocalOjectName = localOjectName + CoreConstants.DOLLAR_CHAR + clazz.getName(); + String internalLocalOjectName = localObjectName + CoreConstants.DOLLAR_CHAR + clazz.getName(); do { java.lang.reflect.Field[] fields = clazz.getDeclaredFields(); AccessibleObject.setAccessible(fields, true); diff --git a/src/main/java/org/audit4j/core/handler/file/ZeroCopyFileWriter.java b/src/main/java/org/audit4j/core/handler/file/ZeroCopyFileWriter.java index b0bdaa9..63c4d21 100644 --- a/src/main/java/org/audit4j/core/handler/file/ZeroCopyFileWriter.java +++ b/src/main/java/org/audit4j/core/handler/file/ZeroCopyFileWriter.java @@ -30,6 +30,7 @@ import java.nio.channels.ReadableByteChannel; import java.nio.charset.Charset; +import org.apache.commons.io.IOUtils; import org.audit4j.core.CoreConstants; /** @@ -128,6 +129,18 @@ public ZeroCopyFileWriter write(String event) { } catch (IOException e) { e.printStackTrace(); + } finally { + IOUtils.closeQuietly(inputStream); + try { + fileChannel.close(); + } catch (IOException e) { + e.printStackTrace(); + } + try { + randomAccessFile.close(); + } catch (IOException e) { + e.printStackTrace(); + } } return this; }