Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,7 @@ protected V populateViewBean(T entityObj) {

protected T populateEntityBeanForCreate(T entityObj, V vObj) {
if (!populateExistingBaseFields) {
Long addedByUserId = ContextUtil.getCurrentUserId();

if (addedByUserId == null) {
XXPortalUser createdByUser = daoMgr.getXXPortalUser().findByLoginId(vObj.getCreatedBy());

if (createdByUser != null) {
addedByUserId = createdByUser.getId();
}
}
Long addedByUserId = resolveUserId(vObj.getCreatedBy());
entityObj.setCreateTime(DateUtil.getUTCDate());
entityObj.setUpdateTime(entityObj.getCreateTime());
entityObj.setAddedByUserId(addedByUserId);
Expand Down Expand Up @@ -358,16 +350,33 @@ protected T populateEntityBeanForUpdate(T entityObj, V vObj) {
}

if (!populateExistingBaseFields) {
Long currentUserId = ContextUtil.getCurrentUserId();
Long updatedByUserId = resolveUserId(vObj.getUpdatedBy());
ret.setUpdateTime(DateUtil.getUTCDate());
if (Objects.nonNull(currentUserId)) {
ret.setUpdatedByUserId(currentUserId);
if (Objects.nonNull(updatedByUserId)) {
ret.setUpdatedByUserId(updatedByUserId);
}
}

return ret;
}

private Long resolveUserId(String userLoginId) {
Long userId = null;
if (Objects.equals(userLoginId, ContextUtil.getCurrentUserLoginId())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userLoginId paramter name is misleading. The value sent is the name provided in the view object - which can be specified by callers of REST API to create/update policy/role/sevice/service-def, etc. This name should not be trusted.

The challenge with grant/revoke scenario is that the authenticated user (ContextUtil.getCurrentUserId()) can be the service-account, while the policy changes should be recorded as the grantor user - the payload value in GrantRevokeRequest.grantor. One approach to consider is to update grant/revoke calls to reset RangerSecurityContext with the identity of the grantor.

userId = ContextUtil.getCurrentUserId();
}
else if (!stringUtil.isEmpty(userLoginId)) {
XXPortalUser createdByUser = daoMgr.getXXPortalUser().findByLoginId(userLoginId);
if (createdByUser != null) {
userId = createdByUser.getId();
}
}
if (userId == null) {
userId = ContextUtil.getCurrentUserId();
}
return userId;
}

protected abstract void validateForCreate(V vObj);

/*
Expand Down
Loading