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

Remove serialisation logic for audit events from scrubSearchResults #2572

Merged
merged 2 commits into from
Dec 4, 2023
Merged
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 @@ -43,6 +43,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;


public class RangerDefaultAuditHandler implements RangerAccessResultProcessor {
Expand Down Expand Up @@ -135,9 +136,9 @@ public AuthzAuditEvent getAuthzEvents(RangerAccessResult result) {
ret.setClientType(request.getClientType());
ret.setSessionId(request.getSessionId());
ret.setAclEnforcer(moduleName);
Set<String> tags = getTags(request);
Set<RangerTagForEval> tags = getTags(request);
if (tags != null) {
ret.setTags(tags);
ret.setTags(tags.stream().map(tag -> (Object) tag).collect(Collectors.toSet()));
}
ret.setAdditionalInfo(getAdditionalInfo(request));
ret.setClusterName(request.getClusterName());
Expand Down Expand Up @@ -251,15 +252,15 @@ public AuthzAuditEvent createAuthzAuditEvent() {
return new AuthzAuditEvent();
}

protected final Set<String> getTags(RangerAccessRequest request) {
Set<String> ret = null;
protected final Set<RangerTagForEval> getTags(RangerAccessRequest request) {
Set<RangerTagForEval> ret = null;
Set<RangerTagForEval> tags = RangerAccessRequestUtil.getRequestTagsFromContext(request.getContext());

if (CollectionUtils.isNotEmpty(tags)) {
ret = new HashSet<>();

for (RangerTagForEval tag : tags) {
ret.add(writeObjectAsString(tag));
ret.add(tag);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,25 @@

import com.google.gson.annotations.SerializedName;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.htrace.shaded.fasterxml.jackson.databind.ObjectMapper;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

public class AuthzAuditEvent extends AuditEventBase {
protected static String FIELD_SEPARATOR = ";";

private static ObjectMapper objectMapper = new ObjectMapper();
protected static final int MAX_ACTION_FIELD_SIZE = 1800;
protected static final int MAX_REQUEST_DATA_FIELD_SIZE = 1800;

private static final Log LOG = LogFactory.getLog(AuthzAuditEvent.class);

@SerializedName("repoType")
protected int repositoryType = 0;

Expand Down Expand Up @@ -110,7 +118,7 @@ public class AuthzAuditEvent extends AuditEventBase {
protected long eventDurationMS = 0;

@SerializedName("tags")
protected Set<String> tags = new HashSet<>();
protected Set<Object> tags = new HashSet<>();

@SerializedName("additional_info")
protected String additionalInfo;
Expand Down Expand Up @@ -483,14 +491,14 @@ public long getEventDurationMS() {
}

public Set<String> getTags() {
return tags;
return tags.stream().map(tag -> writeObjectAsString((Serializable) tag)).collect(Collectors.toSet());
}

public void setEventDurationMS(long frequencyDurationMS) {
this.eventDurationMS = frequencyDurationMS;
}

public void setTags(Set<String> tags) {
public void setTags(Set<Object> tags) {
this.tags = tags;
}

Expand Down Expand Up @@ -582,4 +590,14 @@ protected StringBuilder toString(StringBuilder sb) {

return sb;
}

private String writeObjectAsString(Serializable obj) {
String jsonStr = StringUtils.EMPTY;
try {
jsonStr = objectMapper.writeValueAsString(obj);
} catch (Exception e) {
LOG.error("Cannot create JSON string for object:[" + obj + "]", e);
}
return jsonStr;
}
}
Loading