Search in sources :

Example 36 with XXTrxLog

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);
}
Also used : RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) XXTrxLog(org.apache.ranger.entity.XXTrxLog) XXServiceDao(org.apache.ranger.db.XXServiceDao) XXService(org.apache.ranger.entity.XXService) Test(org.junit.Test)

Example 37 with XXTrxLog

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);
}
Also used : XXServiceDef(org.apache.ranger.entity.XXServiceDef) XXServiceDefDao(org.apache.ranger.db.XXServiceDefDao) RangerService(org.apache.ranger.plugin.model.RangerService) XXTrxLog(org.apache.ranger.entity.XXTrxLog) Test(org.junit.Test)

Example 38 with XXTrxLog

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;
}
Also used : VTrxLogAttr(org.apache.ranger.common.view.VTrxLogAttr) SearchField(org.apache.ranger.common.SearchField) Field(java.lang.reflect.Field) SortField(org.apache.ranger.common.SortField) ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog)

Aggregations

XXTrxLog (org.apache.ranger.entity.XXTrxLog)38 ArrayList (java.util.ArrayList)21 VXString (org.apache.ranger.view.VXString)13 Field (java.lang.reflect.Field)12 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)12 RangerService (org.apache.ranger.plugin.model.RangerService)12 VTrxLogAttr (org.apache.ranger.common.view.VTrxLogAttr)10 XXUser (org.apache.ranger.entity.XXUser)9 SearchField (org.apache.ranger.common.SearchField)7 XXPortalUser (org.apache.ranger.entity.XXPortalUser)7 IOException (java.io.IOException)6 UnknownHostException (java.net.UnknownHostException)5 XXPolicy (org.apache.ranger.entity.XXPolicy)5 RangerDataMaskPolicyItem (org.apache.ranger.plugin.model.RangerPolicy.RangerDataMaskPolicyItem)5 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 XXGroup (org.apache.ranger.entity.XXGroup)4 XXService (org.apache.ranger.entity.XXService)4 XXServiceConfigMap (org.apache.ranger.entity.XXServiceConfigMap)4