Skip to content

Commit

Permalink
RANGER-4652: Value for datasets and projects field in the access audi…
Browse files Browse the repository at this point in the history
…ts must be JSON serializable

Signed-off-by: Madhan Neethiraj <[email protected]>
  • Loading branch information
princeap173 authored and mneethiraj committed Jan 28, 2024
1 parent 6e94858 commit d1eb5af
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,8 @@ static public void writeValue(Writer writer, Object obj) throws Exception {
static public <T> T readValue(Reader reader, Class<T> tClass) throws Exception {
return getMapper().readValue(reader, tClass);
}

static public String nonSerializableObjToJson(Object obj) throws Exception {
return getMapper().writeValueAsString(obj);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.ranger.view.VXAccessAudit;
import org.apache.ranger.view.VXAccessAuditList;
import org.apache.ranger.view.VXLong;
import org.apache.ranger.plugin.util.JsonUtilsV2;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.search.SearchResponse;
Expand Down Expand Up @@ -277,11 +278,19 @@ private VXAccessAudit populateViewBean(GetResponse doc) {
}
value = source.get("datasets");
if (value != null) {
accessAudit.setDatasets(value.toString());
try {
accessAudit.setDatasets(JsonUtilsV2.nonSerializableObjToJson(value));
} catch (Exception e) {
LOGGER.warn("Failed to convert datasets to json", e);
}
}
value = source.get("projects");
if (value != null) {
accessAudit.setProjects(value.toString());
try {
accessAudit.setProjects(JsonUtilsV2.nonSerializableObjToJson(value));
} catch (Exception e) {
LOGGER.warn("Failed to convert projects to json", e);
}
}
return accessAudit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.ranger.view.VXAccessAudit;
import org.apache.ranger.view.VXAccessAuditList;
import org.apache.ranger.view.VXLong;
import org.apache.ranger.plugin.util.JsonUtilsV2;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
Expand Down Expand Up @@ -256,11 +257,19 @@ private VXAccessAudit populateViewBean(SolrDocument doc) {
}
value = doc.getFieldValue("datasets");
if (value != null) {
accessAudit.setDatasets(value.toString());
try {
accessAudit.setDatasets(JsonUtilsV2.nonSerializableObjToJson(value));
} catch (Exception e) {
LOGGER.warn("Failed to convert datasets to json", e);
}
}
value = doc.getFieldValue("projects");
if (value != null) {
accessAudit.setProjects(value.toString());
try {
accessAudit.setProjects(JsonUtilsV2.nonSerializableObjToJson(value));
} catch (Exception e) {
LOGGER.warn("Failed to convert projects to json", e);
}
}
return accessAudit;
}
Expand Down

0 comments on commit d1eb5af

Please sign in to comment.