This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch ranger-2.7
in repository https://gitbox.apache.org/repos/asf/ranger.git
The following commit(s) were added to refs/heads/ranger-2.7 by this push:
new ba96e1a94 RANGER-5185: fix potential NPE in references to
RangerBasePlugin.policyEngine (#555)
ba96e1a94 is described below
commit ba96e1a940952fdf11b367c7cd365415028112ae
Author: Madhan Neethiraj <[email protected]>
AuthorDate: Tue Apr 29 07:49:47 2025 -0700
RANGER-5185: fix potential NPE in references to
RangerBasePlugin.policyEngine (#555)
(cherry picked from commit c583641a1e64a05fef6641e858a777385827c6d6)
---
.../ranger/plugin/service/RangerBasePlugin.java | 27 ++++++++++------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git
a/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBasePlugin.java
b/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBasePlugin.java
index 58b0bcc2b..606062bd9 100644
---
a/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBasePlugin.java
+++
b/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBasePlugin.java
@@ -514,7 +514,7 @@ public void setPolicies(ServicePolicies policies) {
} else {
LOG.warn("Leaving current policy engine as-is");
LOG.warn("Policies are not saved to cache.
policyVersion in the policy-cache may be different than in Ranger-admin, even
though the policies are the same!");
- LOG.warn("Ranger-PolicyVersion:[" + (policies
!= null ? policies.getPolicyVersion() : -1L) + "], Cached-PolicyVersion:[" +
(this.policyEngine != null ? this.policyEngine.getPolicyVersion() : -1L) + "]");
+ LOG.warn("Ranger-PolicyVersion:[" + (policies
!= null ? policies.getPolicyVersion() : -1L) + "], Cached-PolicyVersion:[" +
getPoliciesVersion() + "]");
}
} catch (Exception e) {
@@ -794,13 +794,11 @@ public RangerRoles getRangerRoles() {
}
public Set<RangerRole> getRangerRoleForPrincipal(String principal,
String type) {
- Set<RangerRole> ret = new
HashSet<>();
- Set<RangerRole> rangerRoles = null;
- Map<String, Set<String>> roleMapping = null;
- RangerRoles roles
= getRangerRoles();
- if (roles != null) {
- rangerRoles = roles.getRangerRoles();
- }
+ Set<RangerRole> ret = new HashSet<>();
+ RangerPolicyEngine policyEngine = this.policyEngine;
+ RangerRoles roles = policyEngine != null ?
policyEngine.getRangerRoles() : null;
+ Set<RangerRole> rangerRoles = roles != null ?
roles.getRangerRoles() : null;
+ Map<String, Set<String>> roleMapping = null;
if (rangerRoles != null) {
RangerPluginContext rangerPluginContext =
policyEngine.getPluginContext();
@@ -836,6 +834,7 @@ public Set<RangerRole> getRangerRoleForPrincipal(String
principal, String type)
}
}
}
+
return ret;
}
@@ -1042,18 +1041,14 @@ public void refreshPoliciesAndTags() {
}
try {
- RangerPolicyEngine policyEngine = this.policyEngine;
+ long oldPolicyVersion = getPoliciesVersion();
// Synch-up policies
- long oldPolicyVersion = policyEngine.getPolicyVersion();
-
if (refresher != null) {
refresher.syncPoliciesWithAdmin(accessTrigger);
}
- policyEngine = this.policyEngine; // might be updated
in syncPoliciesWithAdmin()
-
- long newPolicyVersion = policyEngine.getPolicyVersion();
+ long newPolicyVersion = getPoliciesVersion();
if (oldPolicyVersion == newPolicyVersion) {
// Synch-up tags
@@ -1415,6 +1410,8 @@ private static AuditProviderFactory
getAuditProviderFactory(String serviceName)
}
public Long getPolicyVersion() {
- return this.policyEngine == null ? -1L :
this.policyEngine.getPolicyVersion();
+ RangerPolicyEngine policyEngine = this.policyEngine;
+
+ return policyEngine == null ? -1L :
policyEngine.getPolicyVersion();
}
}