Skip to content

Commit

Permalink
Event generation pipeline changes for JCache
Browse files Browse the repository at this point in the history
  • Loading branch information
monu-k2io committed Nov 16, 2023
1 parent 147470f commit 60e97fa
Showing 1 changed file with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.newrelic.agent.security.instrumentator.dispatcher;

import com.google.gson.Gson;
import com.newrelic.agent.security.AgentInfo;
import com.newrelic.agent.security.instrumentator.helper.DynamoDBRequestConverter;
import com.newrelic.agent.security.instrumentator.utils.AgentUtils;
Expand Down Expand Up @@ -71,6 +72,8 @@ public SecurityMetaData getSecurityMetaData() {
return securityMetaData;
}

private static Gson GsonUtil = new Gson();

public Dispatcher(AbstractOperation operation, SecurityMetaData securityMetaData) {
this.securityMetaData = securityMetaData;
this.operation = operation;
Expand Down Expand Up @@ -202,8 +205,13 @@ public Object call() throws Exception {
eventBean = prepareXQueryInjectionEvent(eventBean, xQueryOperationalBean);
break;
case CACHING_DATA_STORE:
RedisOperation redisOperation = (RedisOperation) operation;
eventBean = prepareCachingDataStoreEvent(eventBean, redisOperation);
if(operation instanceof RedisOperation) {
RedisOperation redisOperation = (RedisOperation) operation;
eventBean = prepareCachingDataStoreEvent(eventBean, redisOperation);
} else if (operation instanceof JCacheOperation) {
JCacheOperation jCacheOperation = (JCacheOperation) operation;
eventBean = prepareJCacheCachingDataStoreEvent(eventBean, jCacheOperation);
}
break;
default:

Expand Down Expand Up @@ -248,6 +256,33 @@ private JavaAgentEventBean prepareCachingDataStoreEvent(JavaAgentEventBean event
return eventBean;
}

private JavaAgentEventBean prepareJCacheCachingDataStoreEvent(JavaAgentEventBean eventBean, JCacheOperation jCacheOperation) {
JSONArray params = new JSONArray();
for (Object data : jCacheOperation.getArguments()) {
if (isPrimitiveType(data.getClass())) {
params.add(data);
} else {
params.add(GsonUtil.toJson(data));
}
}

JSONObject command = new JSONObject();
command.put(REDIS_ARGUMENTS, params);
command.put(REDIS_TYPE, jCacheOperation.getType());

JSONArray parameter = new JSONArray();
parameter.add(command);
eventBean.setParameters(parameter);
eventBean.setEventCategory(jCacheOperation.getCategory());
return eventBean;
}

public boolean isPrimitiveType(Class<?> clazz) {
return (clazz.isPrimitive() && clazz != void.class) || clazz == Double.class || clazz == Float.class || clazz == Long.class ||
clazz == Integer.class || clazz == Short.class || clazz == Character.class || clazz == Byte.class || clazz == Boolean.class ||
clazz == String.class;
}

@Nullable
private JavaAgentEventBean processFileOperationEvent(JavaAgentEventBean eventBean, FileOperation fileOperationalBean) {
prepareFileEvent(eventBean, fileOperationalBean);
Expand Down

0 comments on commit 60e97fa

Please sign in to comment.