From 1eeff370c46d0db1e4852173187f315d1292fbb8 Mon Sep 17 00:00:00 2001 From: Reid Chan Date: Fri, 17 Apr 2020 13:55:47 +0800 Subject: [PATCH] HBASE-24174 Fix findbugs warning on ServiceAuthorizationManager (#1494) Signed-off-by: Viraj Jasani --- .../org/apache/hadoop/hbase/ipc/RpcServer.java | 18 ++++++++---------- .../hadoop/hbase/ipc/RpcServerInterface.java | 6 ++++-- .../token/TestTokenAuthentication.java | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java index 5daa42b7f6b..f62a218b741 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServer.java @@ -2202,7 +2202,6 @@ public class RpcServer implements RpcServerInterface, ConfigurationObserver { final InetSocketAddress bindAddress, Configuration conf, RpcScheduler scheduler) throws IOException { - if (conf.getBoolean("hbase.ipc.server.reservoir.enabled", true)) { this.reservoir = new BoundedByteBufferPool( conf.getInt("hbase.ipc.server.reservoir.max.buffer.size", 1024 * 1024), @@ -2265,14 +2264,9 @@ public class RpcServer implements RpcServerInterface, ConfigurationObserver { if (scheduler instanceof ConfigurationObserver) { ((ConfigurationObserver)scheduler).onConfigurationChange(newConf); } - // Make sure authManager will read hbase-policy file - System.setProperty("hadoop.policy.file", "hbase-policy.xml"); - synchronized (authManager) { - authManager.refresh(newConf, new HBasePolicyProvider()); + if (authorize) { + refreshAuthManager(newConf, new HBasePolicyProvider()); } - LOG.info("Refreshed hbase-policy.xml successfully"); - ProxyUsers.refreshSuperUserGroupsConfiguration(newConf); - LOG.info("Refreshed super and proxy users successfully"); } private void initReconfigurable(Configuration confToLoad) { @@ -2353,10 +2347,14 @@ public class RpcServer implements RpcServerInterface, ConfigurationObserver { } @Override - public synchronized void refreshAuthManager(PolicyProvider pp) { + public synchronized void refreshAuthManager(Configuration conf, PolicyProvider pp) { // Ignore warnings that this should be accessed in a static way instead of via an instance; // it'll break if you go via static route. - this.authManager.refresh(this.conf, pp); + System.setProperty("hadoop.policy.file", "hbase-policy.xml"); + this.authManager.refresh(conf, pp); + LOG.info("Refreshed hbase-policy.xml successfully"); + ProxyUsers.refreshSuperUserGroupsConfiguration(conf); + LOG.info("Refreshed super and proxy users successfully"); } private AuthenticationTokenSecretManager createSecretManager() { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerInterface.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerInterface.java index bae5a0a8e15..a6cb9ebc2f7 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerInterface.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/ipc/RpcServerInterface.java @@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.ipc; import java.io.IOException; import java.net.InetSocketAddress; +import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.classification.InterfaceStability; import org.apache.hadoop.hbase.CellScanner; @@ -78,11 +79,12 @@ public interface RpcServerInterface { /** * Refresh authentication manager policy. + * @param conf configuration for refresh * @param pp */ @VisibleForTesting - void refreshAuthManager(PolicyProvider pp); - + void refreshAuthManager(Configuration conf, PolicyProvider pp); + RpcScheduler getScheduler(); void setRsRpcServices(RSRpcServices rsRpcServices); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java index 6a659cb7dd4..4eac35033b4 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java @@ -368,7 +368,7 @@ public class TestTokenAuthentication { while (!server.isStarted() && !server.isStopped()) { Thread.sleep(10); } - server.rpcServer.refreshAuthManager(new PolicyProvider() { + server.rpcServer.refreshAuthManager(conf, new PolicyProvider() { @Override public Service[] getServices() { return new Service [] {