use of org.apache.ranger.entity.XXTrxLog in project ranger by apache.
the class TestRangerPolicyService method test8getTransactionLog.
@Test
public void test8getTransactionLog() {
XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
RangerPolicy rangerPolicy = rangerPolicy();
XXService xService = xService();
Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
Mockito.when(xServiceDao.findByName(rangerPolicy.getService())).thenReturn(xService);
List<XXTrxLog> dbXXTrxLogList = policyService.getTransactionLog(rangerPolicy, 1);
Assert.assertNotNull(dbXXTrxLogList);
}
use of org.apache.ranger.entity.XXTrxLog in project ranger by apache.
the class TestRangerServiceService method test8GetTransactionLogDelete.
@Test
public void test8GetTransactionLogDelete() {
XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
XXServiceDef xServiceDef = Mockito.mock(XXServiceDef.class);
RangerService rangerService = rangerService();
Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
Mockito.when(xServiceDefDao.findByName(rangerService.getType())).thenReturn(xServiceDef);
List<XXTrxLog> dbXXTrxLogList = serviceService.getTransactionLog(rangerService, 3);
Assert.assertNotNull(dbXXTrxLogList);
}
use of org.apache.ranger.entity.XXTrxLog in project ranger by apache.
the class XUserService method getTransactionLog.
public List<XXTrxLog> getTransactionLog(VXUser vObj, VXPortalUser mObj, String action) {
if (vObj == null || action == null || ("update".equalsIgnoreCase(action) && mObj == null)) {
return null;
}
List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
try {
Field nameField = vObj.getClass().getDeclaredField("name");
nameField.setAccessible(true);
String objectName = "" + nameField.get(vObj);
Field[] fields = vObj.getClass().getDeclaredFields();
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;
if (vTrxLogAttr.isEnum()) {
String enumName = XXUser.getEnumName(fieldName);
int enumValue = field.get(vObj) == null ? 0 : Integer.parseInt("" + field.get(vObj));
value = xaEnumUtil.getLabel(enumName, enumValue);
} else {
value = "" + field.get(vObj);
if ((value == null || "null".equalsIgnoreCase(value)) && !"update".equalsIgnoreCase(action)) {
continue;
}
}
if ("password".equalsIgnoreCase(fieldName)) {
if (value.equalsIgnoreCase(hiddenPasswordString)) {
continue;
}
}
if ("create".equalsIgnoreCase(action)) {
if (stringUtil.isEmpty(value) || ("emailAddress".equalsIgnoreCase(fieldName) && !stringUtil.validateEmail(value))) {
continue;
}
xTrxLog.setNewValue(value);
} else if ("delete".equalsIgnoreCase(action)) {
if ("emailAddress".equalsIgnoreCase(fieldName) && !stringUtil.validateEmail(value)) {
continue;
}
xTrxLog.setPreviousValue(value);
} else if ("update".equalsIgnoreCase(action)) {
String oldValue = null;
Field[] mFields = mObj.getClass().getDeclaredFields();
for (Field mField : mFields) {
mField.setAccessible(true);
String mFieldName = mField.getName();
if ("loginId".equalsIgnoreCase(mFieldName)) {
mFieldName = "name";
}
if (fieldName.equalsIgnoreCase(mFieldName)) {
oldValue = mField.get(mObj) + "";
break;
}
}
if (oldValue == null || oldValue.equalsIgnoreCase(value)) {
continue;
}
if ("emailAddress".equalsIgnoreCase(fieldName)) {
if (stringUtil.validateEmail(oldValue)) {
xTrxLog.setPreviousValue(oldValue);
}
if (stringUtil.validateEmail(value)) {
xTrxLog.setNewValue(value);
}
} else {
xTrxLog.setPreviousValue(oldValue);
xTrxLog.setNewValue(value);
}
}
xTrxLog.setAction(action);
xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_XA_USER);
xTrxLog.setObjectId(vObj.getId());
xTrxLog.setObjectName(objectName);
trxLogList.add(xTrxLog);
}
if (trxLogList.isEmpty()) {
XXTrxLog xTrxLog = new XXTrxLog();
xTrxLog.setAction(action);
xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_XA_USER);
xTrxLog.setObjectId(vObj.getId());
xTrxLog.setObjectName(objectName);
trxLogList.add(xTrxLog);
}
} catch (IllegalArgumentException e) {
logger.error("Transaction log failure.", e);
} catch (IllegalAccessException e) {
logger.error("Transaction log failure.", e);
} catch (NoSuchFieldException e) {
logger.error("Transaction log failure.", e);
} catch (SecurityException e) {
logger.error("Transaction log failure.", e);
}
return trxLogList;
}
Aggregations