kumaab commented on code in PR #554:
URL: https://github.com/apache/ranger/pull/554#discussion_r2029172587


##########
security-admin/src/main/java/org/apache/ranger/biz/PolicyRefUpdater.java:
##########
@@ -516,42 +516,50 @@ private Long createPrincipal(String user) {
             return ret;
         }
 
+        private boolean doesPolicyExist(XXPolicy xPolicy) {
+            return daoMgr.getXXPolicy().getById(xPolicy.getId()) != null;
+        }
+
         private void createPolicyAssociation(Long id, String name) {
             LOG.debug("===> 
PolicyPrincipalAssociator.createPolicyAssociation(policyId={}, type={}, 
name={}, id={})", xPolicy.getId(), type.name(), name, id);
 
-            switch (type) {
-                case USER: {
-                    XXPolicyRefUser xPolUser = 
rangerAuditFields.populateAuditFields(new XXPolicyRefUser(), xPolicy);
+            if (doesPolicyExist(xPolicy)) {

Review Comment:
   Check for principal is done as a pre-check from the caller of this function 
in the same thread, for reference:
   `Long id = createOrGetPrincipal(isAdmin);` in `boolean doAssociate(boolean 
isAdmin) {`



-- 
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-unsubscr...@ranger.apache.org

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

Reply via email to