Skip to content

Commit

Permalink
RANGER-4864: Upon performing Policy Import some of Audit Admin logs a…
Browse files Browse the repository at this point in the history
…re improper

Signed-off-by: Dhaval.Rajpara <[email protected]>
  • Loading branch information
RakeshGuptaDev authored and dhavaljrajpara committed Jul 30, 2024
1 parent 7680447 commit e97f95c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4522,10 +4522,11 @@ public Map<String, Object> getMetaDataInfo() {
Map<String, Object> metaDataInfo = new LinkedHashMap<>();
UserSessionBase usb = ContextUtil.getCurrentUserSession();
String userId = usb!=null ? usb.getLoginId() : null;
DateFormat formatter = new SimpleDateFormat("MMM dd, yyyy h:mm:ss a");

metaDataInfo.put(HOSTNAME, LOCAL_HOSTNAME);
metaDataInfo.put(USER_NAME, userId);
metaDataInfo.put(TIMESTAMP, MiscUtil.getUTCDateForLocalDate(new Date()));
metaDataInfo.put(TIMESTAMP, formatter.format(MiscUtil.getUTCDateForLocalDate(new Date())));
metaDataInfo.put(RANGER_VERSION, RangerVersionInfo.getVersion());

return metaDataInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ private List<XXTrxLogV2> getTransactionLogs(V obj, V oldObj, int action) {
processFieldToCreateTrxLog(trxLog, obj, oldObj, action, objChangeInfo);
}

ret.add(new XXTrxLogV2(classType, obj.getId(), getObjectName(obj), getParentObjectType(obj, oldObj), getParentObjectId(obj, oldObj), getParentObjectName(obj, oldObj), toActionString(action), JsonUtilsV2.objToJson(objChangeInfo)));
if(objChangeInfo.getAttributes() != null && objChangeInfo.getAttributes().size() > 0) {
ret.add(new XXTrxLogV2(classType, obj.getId(), getObjectName(obj), getParentObjectType(obj, oldObj), getParentObjectId(obj, oldObj), getParentObjectName(obj, oldObj), toActionString(action), JsonUtilsV2.objToJson(objChangeInfo)));
}
} catch (Exception excp) {
LOG.warn("failed to get transaction log for object: type=" + obj.getClass().getName() + ", id=" + obj.getId(), excp);
}
Expand Down Expand Up @@ -204,6 +206,12 @@ private void processFieldToCreateTrxLog(VTrxLogAttr trxLogAttr, V obj, V oldObj,
} else if (action == OPERATION_UPDATE_CONTEXT) {
prevValue = getTrxLogAttrValue(oldObj, trxLogAttr);
newValue = value;
} else if (action == OPERATION_IMPORT_CREATE_CONTEXT) {
prevValue = null;
newValue = value;
} else if (action == OPERATION_IMPORT_DELETE_CONTEXT) {
prevValue = value;
newValue = null;
} else {
prevValue = null;
newValue = null;
Expand All @@ -224,6 +232,10 @@ private String toActionString(int action) {
return "update";
case OPERATION_DELETE_CONTEXT:
return "delete";
case OPERATION_IMPORT_CREATE_CONTEXT:
return "Import Create";
case OPERATION_IMPORT_DELETE_CONTEXT:
return "Import Delete";
}

return "unknown";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public RangerTrxLogV2Service() {
searchFields.add(new SearchField("objectClassType", "obj.objectClassType", SearchField.DATA_TYPE.INT_LIST, SearchField.SEARCH_TYPE.FULL));
searchFields.add(new SearchField("objectId", "obj.objectId", SearchField.DATA_TYPE.INT_LIST, SearchField.SEARCH_TYPE.FULL));

sortFields.add(new SortField("id", "obj.id", true, SortField.SORT_ORDER.DESC));
sortFields.add(new SortField("createDate", "obj.createTime", true, SortField.SORT_ORDER.DESC));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ function Admin() {
const getDefaultSort = React.useMemo(
() => [
{
id: "createDate",
id: "id",
desc: true
}
],
Expand Down

0 comments on commit e97f95c

Please sign in to comment.