use of org.apache.ranger.common.view.VTrxLogAttr in project ranger by apache.
the class XAuditMapService method getTransactionLog.
public List<XXTrxLog> getTransactionLog(VXAuditMap vObj, VXAuditMap mObj, String action) {
if (vObj == null || action == null || ("update".equalsIgnoreCase(action) && mObj == null)) {
return null;
}
List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
Field[] fields = vObj.getClass().getDeclaredFields();
try {
for (Field field : fields) {
field.setAccessible(true);
String fieldName = field.getName();
if (!trxLogAttrs.containsKey(fieldName)) {
continue;
}
VTrxLogAttr vTrxLogAttr = trxLogAttrs.get(fieldName);
XXTrxLog xTrxLog = new XXTrxLog();
xTrxLog.setAttributeName(vTrxLogAttr.getAttribUserFriendlyName());
String value = null;
boolean isEnum = vTrxLogAttr.isEnum();
if (isEnum) {
String enumName = XXAuditMap.getEnumName(fieldName);
int enumValue = field.get(vObj) == null ? 0 : Integer.parseInt("" + field.get(vObj));
value = xaEnumUtil.getLabel(enumName, enumValue);
} else {
value = "" + field.get(vObj);
XXUser xUser = daoManager.getXXUser().getById(Long.parseLong(value));
value = xUser.getName();
}
if ("create".equalsIgnoreCase(action)) {
xTrxLog.setNewValue(value);
} else if ("delete".equalsIgnoreCase(action)) {
xTrxLog.setPreviousValue(value);
} else if ("update".equalsIgnoreCase(action)) {
// Not Changed.
xTrxLog.setNewValue(value);
xTrxLog.setPreviousValue(value);
}
xTrxLog.setAction(action);
xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_XA_AUDIT_MAP);
xTrxLog.setObjectId(vObj.getId());
xTrxLog.setParentObjectClassType(AppConstants.CLASS_TYPE_XA_RESOURCE);
xTrxLog.setParentObjectId(vObj.getResourceId());
// xTrxLog.setParentObjectName(vObj.get);
// xTrxLog.setObjectName(objectName);
trxLogList.add(xTrxLog);
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
}
return trxLogList;
}
use of org.apache.ranger.common.view.VTrxLogAttr in project ranger by apache.
the class RangerSecurityZoneServiceService method getTransactionLog.
public List<XXTrxLog> getTransactionLog(RangerSecurityZone vSecurityZone, RangerSecurityZone securityZoneDB, String action) {
if (vSecurityZone == null || action == null || ("update".equalsIgnoreCase(action) && securityZoneDB == null)) {
return null;
}
List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
Field[] fields = vSecurityZone.getClass().getDeclaredFields();
try {
Field nameField = vSecurityZone.getClass().getDeclaredField("name");
nameField.setAccessible(true);
String objectName = "" + nameField.get(vSecurityZone);
for (Field field : fields) {
String fieldName = field.getName();
if (!trxLogAttrs.containsKey(fieldName)) {
continue;
}
field.setAccessible(true);
VTrxLogAttr vTrxLogAttr = trxLogAttrs.get(fieldName);
XXTrxLog xTrxLog = new XXTrxLog();
xTrxLog.setAttributeName(vTrxLogAttr.getAttribUserFriendlyName());
xTrxLog.setAction(action);
xTrxLog.setObjectId(vSecurityZone.getId());
xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_RANGER_SECURITY_ZONE);
xTrxLog.setObjectName(objectName);
String value = null;
if (vTrxLogAttr.isEnum()) {
String enumName = XXUser.getEnumName(fieldName);
int enumValue = field.get(vSecurityZone) == null ? 0 : Integer.parseInt("" + field.get(vSecurityZone));
value = xaEnumUtil.getLabel(enumName, enumValue);
} else {
value = "" + field.get(vSecurityZone);
if ((value == null || "null".equalsIgnoreCase(value)) && !"update".equalsIgnoreCase(action)) {
continue;
}
}
if ("services".equalsIgnoreCase(fieldName)) {
Gson gson = new Gson();
value = gson.toJson(vSecurityZone.getServices(), HashMap.class);
}
if ("create".equalsIgnoreCase(action)) {
xTrxLog.setNewValue(value);
trxLogList.add(xTrxLog);
} else if ("delete".equalsIgnoreCase(action)) {
xTrxLog.setPreviousValue(value);
trxLogList.add(xTrxLog);
} else if ("update".equalsIgnoreCase(action)) {
String oldValue = null;
Field[] mFields = vSecurityZone.getClass().getDeclaredFields();
for (Field mField : mFields) {
mField.setAccessible(true);
String mFieldName = mField.getName();
if (fieldName.equalsIgnoreCase(mFieldName)) {
if ("services".equalsIgnoreCase(mFieldName)) {
Gson gson = new Gson();
oldValue = gson.toJson(securityZoneDB.getServices(), HashMap.class);
} else {
oldValue = mField.get(securityZoneDB) + "";
}
break;
}
}
if (oldValue == null || oldValue.equalsIgnoreCase(value)) {
continue;
}
xTrxLog.setPreviousValue(oldValue);
xTrxLog.setNewValue(value);
trxLogList.add(xTrxLog);
}
}
if (trxLogList.isEmpty()) {
XXTrxLog xTrxLog = new XXTrxLog();
xTrxLog.setAction(action);
xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_RANGER_SECURITY_ZONE);
xTrxLog.setObjectId(vSecurityZone.getId());
xTrxLog.setObjectName(objectName);
trxLogList.add(xTrxLog);
}
} catch (IllegalAccessException e) {
logger.error("Transaction log failure.", e);
} catch (NoSuchFieldException e) {
logger.error("Transaction log failure.", e);
}
return trxLogList;
}
Aggregations