You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ranger.apache.org by "Sanket-Shelar (via GitHub)" <gi...@apache.org> on 2025/11/03 09:18:25 UTC

[PR] RANGER-5392: Policies created by grant command have empty 'created by… [ranger]

Sanket-Shelar opened a new pull request, #726:
URL: https://github.com/apache/ranger/pull/726

   …' and 'updated by' fields
   
   ## What changes were proposed in this pull request?
   
   When grant policy is created **created by** and **updated by** is empty as it is trying to get the details from `ContextUtil.getCurrentUserId()` method which in case of non kerbores environment is giving null.
   Update the condition to fetch user from database.
   
   
   ## How was this patch tested?
   
   Local build.
   Ran grant command for a table and policy is created with **created by** and **updated by** field populated.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] RANGER-5392: Policies created by grant command have empty 'created by… [ranger]

Posted by "mneethiraj (via GitHub)" <gi...@apache.org>.
mneethiraj commented on code in PR #726:
URL: https://github.com/apache/ranger/pull/726#discussion_r2487677632


##########
security-admin/src/main/java/org/apache/ranger/service/RangerBaseModelService.java:
##########
@@ -313,15 +313,15 @@ protected V populateViewBean(T entityObj) {
     }
 
     protected T populateEntityBeanForCreate(T entityObj, V vObj) {
+        XXPortalUser createdByUser = daoMgr.getXXPortalUser().findByLoginId(vObj.getCreatedBy());

Review Comment:
   `ContextUtil.getCurrentUserId()` would not be null in Kerberos environments; in this case, avoid unnecessary calls to DB to retrieve `XPortalUser`. Consider the following:
   
   ```
     if (!populateExistingBaseFields) {
       Long addedByUserId = ContextUtil.getCurrentUserId();
   
       if (addedByUserId == null) {
         XXPortalUser createdByUser = daoMgr.getXXPortalUser().findByLoginId(vObj.getCreatedBy());
   
         if (createdByUser != null) {
           addedByUserId = createdByUser.getId();
         }
       }
   
       entityObj.setCreateTime(DateUtil.getUTCDate());
       entityObj.setUpdateTime(entityObj.getCreateTime());
       entityObj.setAddedByUserId(addedByUserId);
       entityObj.setUpdatedByUserId(entityObj.getAddedByUserId());
     } else {
       ...
     }
   ``` 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] RANGER-5392: Policies created by grant command have empty 'created by… [ranger]

Posted by "mneethiraj (via GitHub)" <gi...@apache.org>.
mneethiraj commented on code in PR #726:
URL: https://github.com/apache/ranger/pull/726#discussion_r2566284034


##########
security-admin/src/main/java/org/apache/ranger/service/RangerBaseModelService.java:
##########
@@ -348,8 +357,9 @@ protected T populateEntityBeanForUpdate(T entityObj, V vObj) {
         }
 
         if (!populateExistingBaseFields) {
+            Long currentUserId = ContextUtil.getCurrentUserId();
             ret.setUpdateTime(DateUtil.getUTCDate());
-            ret.setUpdatedByUserId(ContextUtil.getCurrentUserId());
+            ret.setUpdatedByUserId(currentUserId != null ? currentUserId : ret.getAddedByUserId());

Review Comment:
   I suggest to update field `updatedByUserId` only when `currentUserId` is not null. 
   
   ```
   if (currentUserId != null) {
     ret.setUpdatedByUserId(currentUserId);
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] RANGER-5392: Policies created by grant command have empty 'created by… [ranger]

Posted by "mneethiraj (via GitHub)" <gi...@apache.org>.
mneethiraj merged PR #726:
URL: https://github.com/apache/ranger/pull/726


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@ranger.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org