RANGER-2646: replace static references to static configuration instance, RangerConfiguration.getInstance() - #2 (fix PMD violations)
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPluginContext.java b/agents-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPluginContext.java
index 42f57f3..31a07c5 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPluginContext.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/policyengine/RangerPluginContext.java
@@ -29,19 +29,25 @@
public class RangerPluginContext {
private static final Log LOG = LogFactory.getLog(RangerBasePlugin.class);
- private final RangerPluginConfig config;
- private String clusterName;
- private String clusterType;
- private RangerAuthContext authContext;
+ private final RangerPluginConfig config;
+ private final String clusterName;
+ private final String clusterType;
+ private RangerAuthContext authContext;
public RangerPluginContext(String serviceType) {
- this(serviceType, new RangerPluginConfig(serviceType));
+ this(serviceType, new RangerPluginConfig(serviceType));
+ }
+
+ public RangerPluginContext(String serviceType, String clusterName, String clusterType) {
+ this.config = new RangerPluginConfig(serviceType);
+ this.clusterName = clusterName;
+ this.clusterType = clusterType;
}
public RangerPluginContext(String serviceType, RangerPluginConfig config) {
this.config = config;
- this.clusterName = findClusterName(serviceType);
- this.clusterType = findClusterType(serviceType);
+ this.clusterName = findClusterName(config, serviceType);
+ this.clusterType = findClusterType(config, serviceType);
}
public RangerPluginConfig getConfig() { return config; }
@@ -50,53 +56,47 @@
return clusterName;
}
- public void setClusterName(String clusterName) {
- this.clusterName = clusterName;
- }
-
public String getClusterType() {
return clusterType;
}
- public void setClusterType(String clusterType) {
- this.clusterType = clusterType;
- }
-
public RangerAuthContext getAuthContext() { return authContext; }
public void setAuthContext(RangerAuthContext authContext) { this.authContext = authContext; }
- private String findClusterName(String serviceType) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerPluginContext.findClusterName , serviceType = " + serviceType);
+ private static String findClusterName(RangerPluginConfig config, String serviceType) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginContext.findClusterName(serviceType=" + serviceType + ")");
}
- String propertyPrefix = "ranger.plugin." + serviceType;
- String clusterName = config.get(propertyPrefix + ".access.cluster.name", "");
- if(StringUtil.isEmpty(clusterName)){
+ String propertyPrefix = "ranger.plugin." + serviceType;
+ String clusterName = config.get(propertyPrefix + ".access.cluster.name", "");
+
+ if (StringUtil.isEmpty(clusterName)){
clusterName = config.get(propertyPrefix + ".ambari.cluster.name", "");
}
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerPluginContext.findClusterName ");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginContext.findClusterName(serviceType=" + serviceType + "): ret=" + clusterName);
}
return clusterName;
}
- private String findClusterType(String serviceType) {
- if(LOG.isDebugEnabled()) {
- LOG.debug("==> RangerPluginContext.findClusterType , serviceType = " + serviceType);
+ private static String findClusterType(RangerPluginConfig config, String serviceType) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("==> RangerPluginContext.findClusterType(serviceType=" + serviceType + ")");
}
- String propertyPrefix = "ranger.plugin." + serviceType;
- String clusterType = config.get(propertyPrefix + ".access.cluster.type", "");
- if(StringUtil.isEmpty(clusterType)){
+ String propertyPrefix = "ranger.plugin." + serviceType;
+ String clusterType = config.get(propertyPrefix + ".access.cluster.type", "");
+
+ if (StringUtil.isEmpty(clusterType)){
clusterType = config.get(propertyPrefix + ".ambari.cluster.type", "");
}
- if(LOG.isDebugEnabled()) {
- LOG.debug("<== RangerPluginContext.findClusterType ");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("<== RangerPluginContext.findClusterType(serviceType=" + serviceType + "): ret=" + clusterType);
}
return clusterType;
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBaseService.java b/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBaseService.java
index 1df3824..01a7c9f 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBaseService.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/service/RangerBaseService.java
@@ -37,7 +37,6 @@
import org.apache.hadoop.security.SecureClientLogin;
import org.apache.hadoop.security.authentication.util.KerberosName;
import org.apache.ranger.authorization.hadoop.config.RangerAdminConfig;
-import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
import org.apache.ranger.plugin.model.RangerPolicy;
import org.apache.ranger.plugin.model.RangerService;
import org.apache.ranger.plugin.model.RangerServiceDef;
diff --git a/agents-common/src/main/java/org/apache/ranger/plugin/util/ServiceDefUtil.java b/agents-common/src/main/java/org/apache/ranger/plugin/util/ServiceDefUtil.java
index c6cb22b..cd6c18b 100644
--- a/agents-common/src/main/java/org/apache/ranger/plugin/util/ServiceDefUtil.java
+++ b/agents-common/src/main/java/org/apache/ranger/plugin/util/ServiceDefUtil.java
@@ -45,7 +45,7 @@
if(serviceDef != null) {
Configuration config = pluginContext != null ? pluginContext.getConfig() : null;
- boolean enableDenyAndExceptionsInPoliciesHiddenOption = config != null ? config.getBoolean("ranger.servicedef.enableDenyAndExceptionsInPolicies", true) : true;
+ boolean enableDenyAndExceptionsInPoliciesHiddenOption = config == null || config.getBoolean("ranger.servicedef.enableDenyAndExceptionsInPolicies", true);
boolean defaultValue = enableDenyAndExceptionsInPoliciesHiddenOption || StringUtils.equalsIgnoreCase(serviceDef.getName(), EmbeddedServiceDefsUtil.EMBEDDED_SERVICEDEF_TAG_NAME);
ret = ServiceDefUtil.getBooleanValue(serviceDef.getOptions(), RangerServiceDef.OPTION_ENABLE_DENY_AND_EXCEPTIONS_IN_POLICIES, defaultValue);
diff --git a/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyACLs.java b/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyACLs.java
index 6af6948..8846ee8 100644
--- a/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyACLs.java
+++ b/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyACLs.java
@@ -91,9 +91,7 @@
for(PolicyACLsTests.TestCase testCase : testCases.testCases) {
RangerPolicyEngineOptions policyEngineOptions = new RangerPolicyEngineOptions();
- RangerPluginContext pluginContext = new RangerPluginContext("hive");
- pluginContext.setClusterName("cl1");
- pluginContext.setClusterType("on-prem");
+ RangerPluginContext pluginContext = new RangerPluginContext("hive", "cl1", "on-prem");
RangerPolicyEngine policyEngine = new RangerPolicyEngineImpl("test-policy-acls", testCase.servicePolicies, policyEngineOptions, pluginContext);
for(PolicyACLsTests.TestCase.OneTest oneTest : testCase.tests) {
diff --git a/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyDb.java b/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyDb.java
index 456d52c..67c02b2 100644
--- a/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyDb.java
+++ b/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyDb.java
@@ -115,9 +115,7 @@
policyEngineOptions.cacheAuditResults = false;
policyEngineOptions.disableContextEnrichers = true;
policyEngineOptions.disableCustomConditions = true;
- RangerPluginContext pluginContext = new RangerPluginContext("hive");
- pluginContext.setClusterName("cl1");
- pluginContext.setClusterType("on-prem");
+ RangerPluginContext pluginContext = new RangerPluginContext("hive", "cl1", "on-prem");
RangerPolicyEngine policyEngine = new RangerPolicyEngineImpl("test-policydb", testCase.servicePolicies, policyEngineOptions, pluginContext);
for(TestData test : testCase.tests) {
diff --git a/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyEngine.java b/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyEngine.java
index c7c59cec..6a160c9 100644
--- a/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyEngine.java
+++ b/agents-common/src/test/java/org/apache/ranger/plugin/policyengine/TestPolicyEngine.java
@@ -76,7 +76,7 @@
@BeforeClass
public static void setUpBeforeClass() throws Exception {
- pluginContext = new RangerPluginContext("hive");
+ pluginContext = new RangerPluginContext("hive", "cl1", "on-prem");
gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSSZ")
.setPrettyPrinting()
@@ -446,8 +446,6 @@
trustedProxyAddresses[i] = trustedProxyAddresses[i].trim();
}
}
- pluginContext.setClusterName("cl1");
- pluginContext.setClusterType("on-prem");
RangerRoles rangerRoles = new RangerRoles();
rangerRoles.setServiceName(testCase.serviceName);
diff --git a/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/TestPolicyEngine.java b/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/TestPolicyEngine.java
index 5eba4a8..cda80f8 100644
--- a/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/TestPolicyEngine.java
+++ b/hbase-agent/src/test/java/org/apache/ranger/authorization/hbase/TestPolicyEngine.java
@@ -103,9 +103,7 @@
servicePolicies.setPolicies(testCase.policies);
RangerPolicyEngineOptions policyEngineOptions = new RangerPolicyEngineOptions();
- RangerPluginContext pluginContext = new RangerPluginContext("hive");
- pluginContext.setClusterName("cl1");
- pluginContext.setClusterType("on-prem");
+ RangerPluginContext pluginContext = new RangerPluginContext("hive", "cl1", "on-prem");
RangerPolicyEngine policyEngine = new RangerPolicyEngineImpl(testName, servicePolicies, policyEngineOptions, pluginContext);
RangerAccessResultProcessor auditHandler = new RangerDefaultAuditHandler(pluginContext.getConfig());
diff --git a/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java b/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java
index 5998d46..b7ace87 100644
--- a/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java
+++ b/hdfs-agent/src/main/java/org/apache/ranger/authorization/hadoop/RangerHdfsAuthorizer.java
@@ -418,7 +418,7 @@
if (subDirAuthStatus != AuthzStatus.ALLOW) {
for(INode child : cList) {
if (child.isDirectory()) {
- directories.push(new SubAccessData(child.asDirectory(), resourcePath + org.apache.hadoop.fs.Path.SEPARATOR_CHAR + child.getLocalName()));
+ directories.push(new SubAccessData(child.asDirectory(), resourcePath + Path.SEPARATOR_CHAR + child.getLocalName()));
}
}
}
@@ -724,8 +724,8 @@
}
String subDirPath = path;
- if (subDirPath.charAt(subDirPath.length() - 1) != org.apache.hadoop.fs.Path.SEPARATOR_CHAR) {
- subDirPath = subDirPath + Character.toString(org.apache.hadoop.fs.Path.SEPARATOR_CHAR);
+ if (subDirPath.charAt(subDirPath.length() - 1) != Path.SEPARATOR_CHAR) {
+ subDirPath = subDirPath + Character.toString(Path.SEPARATOR_CHAR);
}
subDirPath = subDirPath + rangerPlugin.getRandomizedWildcardPathName();
diff --git a/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/RangerHdfsAuthorizerTest.java b/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/RangerHdfsAuthorizerTest.java
index 61afa47..cf9bad5 100644
--- a/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/RangerHdfsAuthorizerTest.java
+++ b/hdfs-agent/src/test/java/org/apache/ranger/services/hdfs/RangerHdfsAuthorizerTest.java
@@ -35,7 +35,6 @@
import org.apache.hadoop.security.AccessControlException;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ranger.authorization.hadoop.RangerHdfsAuthorizer;
-import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
diff --git a/knox-agent/src/main/java/org/apache/ranger/admin/client/RangerAdminJersey2RESTClient.java b/knox-agent/src/main/java/org/apache/ranger/admin/client/RangerAdminJersey2RESTClient.java
index cba2c8f..8ac62d3 100644
--- a/knox-agent/src/main/java/org/apache/ranger/admin/client/RangerAdminJersey2RESTClient.java
+++ b/knox-agent/src/main/java/org/apache/ranger/admin/client/RangerAdminJersey2RESTClient.java
@@ -46,7 +46,6 @@
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.ranger.plugin.util.*;
import org.apache.ranger.audit.provider.MiscUtil;
-import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
import org.apache.ranger.authorization.utils.StringUtil;
import org.glassfish.jersey.client.ClientProperties;
diff --git a/plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java b/plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java
index 9c419df..1e1593d 100644
--- a/plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java
+++ b/plugin-solr/src/main/java/org/apache/ranger/authorization/solr/authorizer/RangerSolrAuthorizer.java
@@ -33,7 +33,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ranger.audit.provider.MiscUtil;
-import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
import org.apache.ranger.plugin.policyengine.RangerAccessRequestImpl;
import org.apache.ranger.plugin.policyengine.RangerAccessResourceImpl;
import org.apache.ranger.plugin.policyengine.RangerAccessResult;
diff --git a/ranger-tools/src/test/java/org/apache/ranger/policyengine/RangerPolicyEnginePerformanceTest.java b/ranger-tools/src/test/java/org/apache/ranger/policyengine/RangerPolicyEnginePerformanceTest.java
index 97f474b..86909fd 100644
--- a/ranger-tools/src/test/java/org/apache/ranger/policyengine/RangerPolicyEnginePerformanceTest.java
+++ b/ranger-tools/src/test/java/org/apache/ranger/policyengine/RangerPolicyEnginePerformanceTest.java
@@ -145,8 +145,7 @@
public void policyEngineTest() throws InterruptedException {
List<RangerAccessRequest> requests = requestsCache.getUnchecked(concurrency);
ServicePolicies servicePolicies = servicePoliciesCache.getUnchecked(numberOfPolicies);
- RangerPluginContext pluginContext = new RangerPluginContext("hive");
- pluginContext.setClusterName("cl1");
+ RangerPluginContext pluginContext = new RangerPluginContext("hive", "cl1", "on-prem");
final RangerPolicyEngineImpl rangerPolicyEngine = new RangerPolicyEngineImpl("perf-test", servicePolicies, RangerPolicyFactory.createPolicyEngineOption(), pluginContext);
rangerPolicyEngine.preProcess(requests);
diff --git a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
index fc9f133..20849f6 100644
--- a/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
+++ b/security-admin/src/main/java/org/apache/ranger/rest/ServiceREST.java
@@ -60,7 +60,6 @@
import org.apache.commons.logging.LogFactory;
import org.apache.ranger.admin.client.datatype.RESTResponse;
import org.apache.ranger.authorization.hadoop.config.RangerAdminConfig;
-import org.apache.ranger.authorization.hadoop.config.RangerConfiguration;
import org.apache.ranger.authorization.utils.StringUtil;
import org.apache.ranger.biz.AssetMgr;
import org.apache.ranger.biz.RangerBizUtil;