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());
}
}
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations