This is an automated email from the ASF dual-hosted git repository.
madhan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ranger.git
The following commit(s) were added to refs/heads/master by this push:
new c583641a1 RANGER-5185: fix potential NPE in references to
RangerBasePlugin.policyEngine (#555)
c583641a1 is described below
commit c583641a1e64a05fef6641e858a777385827c6d6
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)
---
.../ranger/plugin/service/RangerBasePlugin.java | 26 +++++++++-------------
1 file changed, 11 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 495ce3b83..54fcaa09d 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
@@ -611,7 +611,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:[{}],
Cached-PolicyVersion:[{}]", policies != null ? policies.getPolicyVersion() :
-1L, this.policyEngine != null ? this.policyEngine.getPolicyVersion() : -1L);
+ LOG.warn("Ranger-PolicyVersion:[{}],
Cached-PolicyVersion:[{}]", policies != null ? policies.getPolicyVersion() :
-1L, getPoliciesVersion());
}
} catch (Exception e) {
LOG.error("setPolicies: policy engine initialization failed!
Leaving current policy engine as-is. Exception : ", e);
@@ -883,14 +883,11 @@ public RangerRoles getRangerRoles() {
}
public Set<RangerRole> getRangerRoleForPrincipal(String principal, String
type) {
- Set<RangerRole> ret = new HashSet<>();
- Set<RangerRole> rangerRoles = null;
+ 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;
- RangerRoles roles = getRangerRoles();
-
- if (roles != null) {
- rangerRoles = roles.getRangerRoles();
- }
if (rangerRoles != null) {
RangerPluginContext rangerPluginContext =
policyEngine.getPluginContext();
@@ -930,6 +927,7 @@ public Set<RangerRole> getRangerRoleForPrincipal(String
principal, String type)
}
}
}
+
return ret;
}
@@ -1063,18 +1061,14 @@ public void refreshPoliciesAndTags() {
LOG.debug("==> 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
@@ -1196,7 +1190,9 @@ public Map<String, String> getServiceConfigs() {
}
public Long getPolicyVersion() {
- return this.policyEngine == null ? -1L :
this.policyEngine.getPolicyVersion();
+ RangerPolicyEngine policyEngine = this.policyEngine;
+
+ return policyEngine == null ? -1L : policyEngine.getPolicyVersion();
}
protected RangerPolicyEngine getPolicyEngine() {