Search in sources :

Example 16 with XXTrxLog

use of org.apache.ranger.entity.XXTrxLog in project ranger by apache.

the class RangerServiceService method getTransactionLog.

public List<XXTrxLog> getTransactionLog(RangerService vObj, XXService mObj, int action) {
    if (vObj == null || action == 0 || (action == OPERATION_UPDATE_CONTEXT && mObj == null)) {
        return null;
    }
    List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
    Field[] fields = vObj.getClass().getDeclaredFields();
    try {
        Field nameField = vObj.getClass().getDeclaredField("name");
        nameField.setAccessible(true);
        String objectName = "" + nameField.get(vObj);
        for (Field field : fields) {
            if (!trxLogAttrs.containsKey(field.getName())) {
                continue;
            }
            XXTrxLog xTrxLog = processFieldToCreateTrxLog(field, objectName, nameField, vObj, mObj, action);
            if (xTrxLog != null) {
                trxLogList.add(xTrxLog);
            }
        }
        Field[] superClassFields = vObj.getClass().getSuperclass().getDeclaredFields();
        for (Field field : superClassFields) {
            if ("isEnabled".equalsIgnoreCase(field.getName())) {
                XXTrxLog xTrx = processFieldToCreateTrxLog(field, objectName, nameField, vObj, mObj, action);
                if (xTrx != null) {
                    trxLogList.add(xTrx);
                }
                break;
            }
        }
    } catch (IllegalAccessException e) {
        LOG.error("Transaction log failure.", e);
    } catch (NoSuchFieldException e) {
        LOG.error("Transaction log failure.", e);
    }
    return trxLogList;
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog)

Example 17 with XXTrxLog

use of org.apache.ranger.entity.XXTrxLog in project ranger by apache.

the class XGroupService method getTransactionLog.

public List<XXTrxLog> getTransactionLog(VXGroup vObj, XXGroup 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;
            boolean isEnum = vTrxLogAttr.isEnum();
            if (isEnum) {
                String enumName = XXGroup.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 ("create".equalsIgnoreCase(action)) {
                if (stringUtil.isEmpty(value)) {
                    continue;
                }
                xTrxLog.setNewValue(value);
            } else if ("delete".equalsIgnoreCase(action)) {
                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 (fieldName.equalsIgnoreCase(mFieldName)) {
                        if (isEnum) {
                            String enumName = XXAsset.getEnumName(mFieldName);
                            int enumValue = mField.get(mObj) == null ? 0 : Integer.parseInt("" + mField.get(mObj));
                            oldValue = xaEnumUtil.getLabel(enumName, enumValue);
                        } else {
                            oldValue = mField.get(mObj) + "";
                        }
                        break;
                    }
                }
                if (value.equalsIgnoreCase(oldValue)) {
                    continue;
                }
                xTrxLog.setPreviousValue(oldValue);
                xTrxLog.setNewValue(value);
            }
            xTrxLog.setAction(action);
            xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_XA_GROUP);
            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 : ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog) VTrxLogAttr(org.apache.ranger.common.view.VTrxLogAttr) Field(java.lang.reflect.Field) SearchField(org.apache.ranger.common.SearchField) SortField(org.apache.ranger.common.SortField)

Example 18 with XXTrxLog

use of org.apache.ranger.entity.XXTrxLog in project ranger by apache.

the class XGroupUserService method getTransactionLog.

public List<XXTrxLog> getTransactionLog(VXGroupUser vObj, XXGroupUser mObj, String action) {
    // if(vObj == null && (action == null || !action.equalsIgnoreCase("update"))){
    // return null;
    // }
    Long groupId = vObj.getParentGroupId();
    XXGroup xGroup = daoManager.getXXGroup().getById(groupId);
    String groupName = xGroup.getName();
    Long userId = vObj.getUserId();
    XXUser xUser = daoManager.getXXUser().getById(userId);
    String userName = xUser.getName();
    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 = XXAsset.getEnumName(fieldName);
                int enumValue = field.get(vObj) == null ? 0 : Integer.parseInt("" + field.get(vObj));
                value = xaEnumUtil.getLabel(enumName, enumValue);
            } else {
                value = "" + field.get(vObj);
                XXGroup xXGroup = daoManager.getXXGroup().getById(Long.parseLong(value));
                value = xXGroup.getName();
            }
            if ("create".equalsIgnoreCase(action)) {
                xTrxLog.setNewValue(value);
            } else if ("delete".equalsIgnoreCase(action)) {
                xTrxLog.setPreviousValue(value);
            } else if ("update".equalsIgnoreCase(action)) {
                // No Change.
                xTrxLog.setNewValue(value);
                xTrxLog.setPreviousValue(value);
            }
            xTrxLog.setAction(action);
            xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_XA_GROUP_USER);
            xTrxLog.setObjectId(vObj.getId());
            xTrxLog.setObjectName(userName);
            xTrxLog.setParentObjectClassType(AppConstants.CLASS_TYPE_XA_GROUP);
            xTrxLog.setParentObjectId(groupId);
            xTrxLog.setParentObjectName(groupName);
            trxLogList.add(xTrxLog);
        }
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    }
    return trxLogList;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog) VTrxLogAttr(org.apache.ranger.common.view.VTrxLogAttr) Field(java.lang.reflect.Field) SearchField(org.apache.ranger.common.SearchField) XXGroup(org.apache.ranger.entity.XXGroup)

Example 19 with XXTrxLog

use of org.apache.ranger.entity.XXTrxLog in project ranger by apache.

the class XPermMapService method getTransactionLog.

public List<XXTrxLog> getTransactionLog(VXPermMap vObj, VXPermMap mObj, String action) {
    if (vObj == null || action == null || ("update".equalsIgnoreCase(action) && mObj == null)) {
        return null;
    }
    boolean isGroupPolicy = true;
    if (vObj.getGroupId() == null) {
        isGroupPolicy = false;
    }
    Long groupId = null;
    Long userId = null;
    String groupName = null;
    String userName = null;
    if (isGroupPolicy) {
        groupId = vObj.getGroupId();
        XXGroup xGroup = daoManager.getXXGroup().getById(groupId);
        groupName = xGroup.getName();
    } else {
        userId = vObj.getUserId();
        XXUser xUser = daoManager.getXXUser().getById(userId);
        userName = xUser.getName();
    }
    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;
            // int policyType = vObj.getIpAddress();
            /*if(policyType == AppConstants.ASSET_HDFS){
					String[] ignoredAttribs = {"ipAddress"};
					if(ArrayUtils.contains(ignoredAttribs, fieldName)){
						continue;
					}
				}*/
            // } else {
            // if(isGroupPolicy){
            // if(fieldName.equalsIgnoreCase("userId")){
            // continue;
            // }
            // } else {
            // if (fieldName.equalsIgnoreCase("groupId")){
            // continue;
            // }
            // }
            }
            Long assetId = daoManager.getXXResource().getById(vObj.getResourceId()).getAssetId();
            int policyType = daoManager.getXXAsset().getById(assetId).getAssetType();
            if (policyType != AppConstants.ASSET_KNOX) {
                if ("ipAddress".equals(fieldName))
                    continue;
            }
            VTrxLogAttr vTrxLogAttr = trxLogAttrs.get(fieldName);
            XXTrxLog xTrxLog = new XXTrxLog();
            xTrxLog.setAttributeName(vTrxLogAttr.getAttribUserFriendlyName());
            String value = null, prevValue = "";
            boolean isEnum = vTrxLogAttr.isEnum();
            if (isEnum) {
                String enumName = XXPermMap.getEnumName(fieldName);
                int enumValue = field.get(vObj) == null ? 0 : Integer.parseInt("" + field.get(vObj));
                value = xaEnumUtil.getLabel(enumName, enumValue);
            } else {
                value = "" + field.get(vObj);
                // value = xUser.getName();
                if ("ipAddress".equals(fieldName) && "update".equalsIgnoreCase(action)) {
                    prevValue = "" + field.get(mObj);
                    value = "null".equalsIgnoreCase(value) ? "" : value;
                } else if (value == null || "null".equalsIgnoreCase(value) || stringUtil.isEmpty(value)) {
                    continue;
                }
            }
            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);
                if ("ipAddress".equals(fieldName)) {
                    xTrxLog.setPreviousValue(prevValue);
                }
            }
            xTrxLog.setAction(action);
            xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_XA_PERM_MAP);
            xTrxLog.setObjectId(vObj.getId());
            if (isGroupPolicy) {
                xTrxLog.setParentObjectClassType(AppConstants.CLASS_TYPE_XA_GROUP);
                xTrxLog.setParentObjectId(groupId);
                xTrxLog.setParentObjectName(groupName);
            } else {
                xTrxLog.setParentObjectClassType(AppConstants.CLASS_TYPE_XA_USER);
                xTrxLog.setParentObjectId(userId);
                xTrxLog.setParentObjectName(userName);
            }
            // xTrxLog.setObjectName(objectName);
            trxLogList.add(xTrxLog);
        }
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    }
    return trxLogList;
}
Also used : XXUser(org.apache.ranger.entity.XXUser) ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog) VTrxLogAttr(org.apache.ranger.common.view.VTrxLogAttr) Field(java.lang.reflect.Field) SearchField(org.apache.ranger.common.SearchField) XXGroup(org.apache.ranger.entity.XXGroup)

Example 20 with XXTrxLog

use of org.apache.ranger.entity.XXTrxLog in project ranger by apache.

the class XPortalUserService method getTransactionLog.

public List<XXTrxLog> getTransactionLog(VXPortalUser vObj, XXPortalUser xObj, String action) {
    if (vObj == null || action == null || ("update".equalsIgnoreCase(action) && xObj == null)) {
        return null;
    }
    List<XXTrxLog> trxLogList = new ArrayList<XXTrxLog>();
    Field[] fields = vObj.getClass().getDeclaredFields();
    try {
        Field nameField = vObj.getClass().getDeclaredField("loginId");
        nameField.setAccessible(true);
        String objectName = "" + nameField.get(vObj);
        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 = XXAsset.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 ("create".equalsIgnoreCase(action)) {
                if (stringUtil.isEmpty(value)) {
                    continue;
                }
                xTrxLog.setNewValue(value);
            } else if ("delete".equalsIgnoreCase(action)) {
                xTrxLog.setPreviousValue(value);
            } else if ("update".equalsIgnoreCase(action)) {
                String oldValue = null;
                Field[] xFields = xObj.getClass().getDeclaredFields();
                for (Field xField : xFields) {
                    xField.setAccessible(true);
                    String xFieldName = xField.getName();
                    if (fieldName.equalsIgnoreCase(xFieldName)) {
                        if (isEnum) {
                            String enumName = XXAsset.getEnumName(xFieldName);
                            int enumValue = xField.get(xObj) == null ? 0 : Integer.parseInt("" + xField.get(xObj));
                            oldValue = xaEnumUtil.getLabel(enumName, enumValue);
                        } else {
                            oldValue = xField.get(xObj) + "";
                        }
                        break;
                    }
                }
                if ("emailAddress".equalsIgnoreCase(fieldName)) {
                    if (!stringUtil.validateEmail(oldValue)) {
                        oldValue = "";
                    }
                    if (!stringUtil.validateEmail(value)) {
                        value = "";
                    }
                }
                if (value.equalsIgnoreCase(oldValue)) {
                    continue;
                }
                xTrxLog.setPreviousValue(oldValue);
                xTrxLog.setNewValue(value);
            }
            xTrxLog.setAction(action);
            xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_USER_PROFILE);
            xTrxLog.setObjectId(vObj.getId());
            xTrxLog.setObjectName(objectName);
            trxLogList.add(xTrxLog);
        }
    } catch (IllegalArgumentException e) {
        logger.info("Caught IllegalArgumentException while" + " getting Transaction log for user : " + vObj.getLoginId(), e);
    } catch (NoSuchFieldException e) {
        logger.info("Caught NoSuchFieldException while" + " getting Transaction log for user : " + vObj.getLoginId(), e);
    } catch (SecurityException e) {
        logger.info("Caught SecurityException while" + " getting Transaction log for user : " + vObj.getLoginId(), e);
    } catch (IllegalAccessException e) {
        logger.info("Caught IllegalAccessException while" + " getting Transaction log for user : " + vObj.getLoginId(), e);
    }
    return trxLogList;
}
Also used : ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog) VTrxLogAttr(org.apache.ranger.common.view.VTrxLogAttr) Field(java.lang.reflect.Field)

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