Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a little contribution #83

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -133,6 +133,7 @@ private List<Field> 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;
Expand Down
24 changes: 14 additions & 10 deletions src/main/java/org/audit4j/core/ObjectToFieldsSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -52,33 +56,33 @@ public final class ObjectToFieldsSerializer implements ObjectSerializer {
* @param deidentify the de-identify
*/
public final void toFields(List<Field> 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);
if (deidentify != null) {
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
Expand All @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
}
Expand Down