Search in sources :

Example 91 with XXPortalUser

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

the class AbstractBaseResourceService method mapBaseAttributesToViewBean.

protected void mapBaseAttributesToViewBean(T resource, V viewBean) {
    viewBean.setId(resource.getId());
    // TBD: Need to review this change later
    viewBean.setMObj(resource);
    viewBean.setCreateDate(resource.getCreateTime());
    viewBean.setUpdateDate(resource.getUpdateTime());
    Long ownerId = resource.getAddedByUserId();
    UserSessionBase currentUserSession = ContextUtil.getCurrentUserSession();
    if (currentUserSession == null) {
        return;
    }
    if (ownerId != null) {
        XXPortalUser tUser = daoManager.getXXPortalUser().getById(resource.getAddedByUserId());
        if (tUser != null) {
            if (tUser.getPublicScreenName() != null && !tUser.getPublicScreenName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getPublicScreenName().trim())) {
                viewBean.setOwner(tUser.getPublicScreenName());
            } else {
                if (tUser.getFirstName() != null && !tUser.getFirstName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getFirstName().trim())) {
                    if (tUser.getLastName() != null && !tUser.getLastName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getLastName().trim())) {
                        viewBean.setOwner(tUser.getFirstName() + " " + tUser.getLastName());
                    } else {
                        viewBean.setOwner(tUser.getFirstName());
                    }
                } else {
                    viewBean.setOwner(tUser.getLoginId());
                }
            }
        }
    }
    if (resource.getUpdatedByUserId() != null) {
        XXPortalUser tUser = daoManager.getXXPortalUser().getById(resource.getUpdatedByUserId());
        if (tUser != null) {
            if (tUser.getPublicScreenName() != null && !tUser.getPublicScreenName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getPublicScreenName().trim())) {
                viewBean.setUpdatedBy(tUser.getPublicScreenName());
            } else {
                if (tUser.getFirstName() != null && !tUser.getFirstName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getFirstName().trim())) {
                    if (tUser.getLastName() != null && !tUser.getLastName().trim().isEmpty() && !"null".equalsIgnoreCase(tUser.getLastName().trim())) {
                        viewBean.setUpdatedBy(tUser.getFirstName() + " " + tUser.getLastName());
                    } else {
                        viewBean.setUpdatedBy(tUser.getFirstName());
                    }
                } else {
                    viewBean.setUpdatedBy(tUser.getLoginId());
                }
            }
        }
    }
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXLong(org.apache.ranger.view.VXLong) UserSessionBase(org.apache.ranger.common.UserSessionBase)

Example 92 with XXPortalUser

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

the class XAuditMapService method mapViewToEntityBean.

@Override
protected XXAuditMap mapViewToEntityBean(VXAuditMap vObj, XXAuditMap mObj, int OPERATION_CONTEXT) {
    XXAuditMap ret = null;
    if (vObj != null && mObj != null) {
        ret = super.mapViewToEntityBean(vObj, mObj, OPERATION_CONTEXT);
        XXPortalUser xXPortalUser = null;
        if (ret.getAddedByUserId() == null || ret.getAddedByUserId() == 0) {
            if (!stringUtil.isEmpty(vObj.getOwner())) {
                xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getOwner());
                if (xXPortalUser != null) {
                    ret.setAddedByUserId(xXPortalUser.getId());
                }
            }
        }
        if (ret.getUpdatedByUserId() == null || ret.getUpdatedByUserId() == 0) {
            if (!stringUtil.isEmpty(vObj.getUpdatedBy())) {
                xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getUpdatedBy());
                if (xXPortalUser != null) {
                    ret.setUpdatedByUserId(xXPortalUser.getId());
                }
            }
        }
    }
    return ret;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXAuditMap(org.apache.ranger.entity.XXAuditMap)

Example 93 with XXPortalUser

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

the class XAuditMapService method mapEntityToViewBean.

@Override
protected VXAuditMap mapEntityToViewBean(VXAuditMap vObj, XXAuditMap mObj) {
    VXAuditMap ret = null;
    if (mObj != null && vObj != null) {
        ret = super.mapEntityToViewBean(vObj, mObj);
        XXPortalUser xXPortalUser = null;
        if (stringUtil.isEmpty(ret.getOwner())) {
            xXPortalUser = daoManager.getXXPortalUser().getById(mObj.getAddedByUserId());
            if (xXPortalUser != null) {
                ret.setOwner(xXPortalUser.getLoginId());
            }
        }
        if (stringUtil.isEmpty(ret.getUpdatedBy())) {
            xXPortalUser = daoManager.getXXPortalUser().getById(mObj.getUpdatedByUserId());
            if (xXPortalUser != null) {
                ret.setUpdatedBy(xXPortalUser.getLoginId());
            }
        }
    }
    return ret;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXAuditMap(org.apache.ranger.view.VXAuditMap)

Example 94 with XXPortalUser

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

the class RangerRoleService method getTransactionLog.

public List<XXTrxLog> getTransactionLog(RangerRole current, RangerRole former, String action) {
    if (current == null || action == null || ("update".equalsIgnoreCase(action) && former == null)) {
        return null;
    }
    List<XXTrxLog> trxLogList = new ArrayList<>();
    Field[] fields = current.getClass().getDeclaredFields();
    String users = RangerConstants.MODULE_USER_GROUPS.split("/")[0];
    String groups = RangerConstants.MODULE_USER_GROUPS.split("/")[1];
    try {
        Field nameField = current.getClass().getDeclaredField("name");
        nameField.setAccessible(true);
        String objectName = "" + nameField.get(current);
        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(current.getId());
            xTrxLog.setObjectClassType(AppConstants.CLASS_TYPE_RANGER_ROLE);
            xTrxLog.setObjectName(objectName);
            if (!StringUtils.isNotBlank(current.getCreatedByUser())) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Created User = " + current.getCreatedByUser());
                }
                XXPortalUser xXPortalUser = daoMgr.getXXPortalUser().findByLoginId(current.getCreatedByUser());
                if (xXPortalUser != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("User Id for " + current.getCreatedByUser() + " = " + xXPortalUser.getId());
                    }
                    xTrxLog.setAddedByUserId(xXPortalUser.getId());
                    xTrxLog.setUpdatedByUserId(xXPortalUser.getId());
                }
            }
            String value;
            if (vTrxLogAttr.isEnum()) {
                String enumName = XXUser.getEnumName(fieldName);
                int enumValue = field.get(current) == null ? 0 : Integer.parseInt("" + field.get(current));
                value = xaEnumUtil.getLabel(enumName, enumValue);
            } else {
                value = "" + field.get(current);
                if (fieldName.equalsIgnoreCase(users) || fieldName.equalsIgnoreCase(groups) || fieldName.equalsIgnoreCase(RangerConstants.ROLE_FIELD)) {
                    if (fieldName.equalsIgnoreCase(users)) {
                        value = JsonUtils.listToJson(current.getUsers());
                    } else if (fieldName.equalsIgnoreCase(groups)) {
                        value = JsonUtils.listToJson(current.getGroups());
                    } else if (fieldName.equalsIgnoreCase(RangerConstants.ROLE_FIELD)) {
                        value = JsonUtils.listToJson(current.getRoles());
                    }
                }
                if ((value == null || "null".equalsIgnoreCase(value)) && !"update".equalsIgnoreCase(action)) {
                    continue;
                }
            }
            if ("options".equalsIgnoreCase(fieldName)) {
                value = JsonUtils.mapToJson(current.getOptions());
            }
            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 formerValue = null;
                Field[] mFields = current.getClass().getDeclaredFields();
                for (Field mField : mFields) {
                    mField.setAccessible(true);
                    String mFieldName = mField.getName();
                    if (fieldName.equalsIgnoreCase(mFieldName)) {
                        if ("options".equalsIgnoreCase(mFieldName)) {
                            formerValue = JsonUtils.mapToJson(former.getOptions());
                        } else {
                            formerValue = mField.get(former) + "";
                            if (fieldName.equalsIgnoreCase(users) || fieldName.equalsIgnoreCase(groups) || fieldName.equalsIgnoreCase(RangerConstants.ROLE_FIELD)) {
                                if (fieldName.equalsIgnoreCase(users)) {
                                    formerValue = JsonUtils.listToJson(former.getUsers());
                                } else if (fieldName.equalsIgnoreCase(groups)) {
                                    formerValue = JsonUtils.listToJson(former.getGroups());
                                } else if (fieldName.equalsIgnoreCase(RangerConstants.ROLE_FIELD)) {
                                    formerValue = JsonUtils.listToJson(former.getRoles());
                                }
                            }
                        }
                        break;
                    }
                }
                value = ((value == null) ? "" : value);
                formerValue = ((formerValue == null) ? "" : formerValue);
                if (formerValue.equalsIgnoreCase(value)) {
                    continue;
                }
                xTrxLog.setPreviousValue(formerValue);
                xTrxLog.setNewValue(value);
                trxLogList.add(xTrxLog);
            }
            if (logger.isDebugEnabled()) {
                logger.debug("AddedByUserId for " + xTrxLog.getObjectName() + " = " + xTrxLog.getAddedByUserId());
            }
        }
        if (trxLogList.isEmpty()) {
            if (logger.isDebugEnabled()) {
                logger.debug("trxLogList is empty!!");
            }
            trxLogList = null;
        }
    } catch (IllegalAccessException e) {
        logger.error("Transaction log failure.", e);
    } catch (NoSuchFieldException e) {
        logger.error("Transaction log failure.", e);
    }
    return trxLogList;
}
Also used : VTrxLogAttr(org.apache.ranger.common.view.VTrxLogAttr) Field(java.lang.reflect.Field) XXPortalUser(org.apache.ranger.entity.XXPortalUser) ArrayList(java.util.ArrayList) XXTrxLog(org.apache.ranger.entity.XXTrxLog)

Example 95 with XXPortalUser

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

the class XPermMapService method mapViewToEntityBean.

@Override
protected XXPermMap mapViewToEntityBean(VXPermMap vObj, XXPermMap mObj, int OPERATION_CONTEXT) {
    XXPermMap ret = null;
    if (vObj != null && mObj != null) {
        ret = super.mapViewToEntityBean(vObj, mObj, OPERATION_CONTEXT);
        XXPortalUser xXPortalUser = null;
        if (ret.getAddedByUserId() == null || ret.getAddedByUserId() == 0) {
            if (!stringUtil.isEmpty(vObj.getOwner())) {
                xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getOwner());
                if (xXPortalUser != null) {
                    ret.setAddedByUserId(xXPortalUser.getId());
                }
            }
        }
        if (ret.getUpdatedByUserId() == null || ret.getUpdatedByUserId() == 0) {
            if (!stringUtil.isEmpty(vObj.getUpdatedBy())) {
                xXPortalUser = daoManager.getXXPortalUser().findByLoginId(vObj.getUpdatedBy());
                if (xXPortalUser != null) {
                    ret.setUpdatedByUserId(xXPortalUser.getId());
                }
            }
        }
    }
    return ret;
}
Also used : XXPortalUser(org.apache.ranger.entity.XXPortalUser) XXPermMap(org.apache.ranger.entity.XXPermMap)

Aggregations

XXPortalUser (org.apache.ranger.entity.XXPortalUser)192 Test (org.junit.Test)113 ArrayList (java.util.ArrayList)93 VXPortalUser (org.apache.ranger.view.VXPortalUser)86 VXString (org.apache.ranger.view.VXString)82 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)74 XXPortalUserRole (org.apache.ranger.entity.XXPortalUserRole)46 XXPortalUserRoleDao (org.apache.ranger.db.XXPortalUserRoleDao)44 XXUserPermission (org.apache.ranger.entity.XXUserPermission)36 UserSessionBase (org.apache.ranger.common.UserSessionBase)34 VXUser (org.apache.ranger.view.VXUser)34 WebApplicationException (javax.ws.rs.WebApplicationException)33 Date (java.util.Date)30 RangerSecurityContext (org.apache.ranger.security.context.RangerSecurityContext)29 XXUser (org.apache.ranger.entity.XXUser)27 XXUserPermissionDao (org.apache.ranger.db.XXUserPermissionDao)25 XXModuleDef (org.apache.ranger.entity.XXModuleDef)25 XXModuleDefDao (org.apache.ranger.db.XXModuleDefDao)20 XXGroupPermission (org.apache.ranger.entity.XXGroupPermission)19 VXUserPermission (org.apache.ranger.view.VXUserPermission)19