diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RegionServerRpcQuotaManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RegionServerRpcQuotaManager.java index 69253d7306d..51b8cc950b2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RegionServerRpcQuotaManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RegionServerRpcQuotaManager.java @@ -20,6 +20,7 @@ package org.apache.hadoop.hbase.quotas; import java.io.IOException; import java.util.List; +import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -33,7 +34,6 @@ import org.apache.hadoop.hbase.regionserver.Region; import org.apache.hadoop.hbase.regionserver.RegionServerServices; import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.security.UserGroupInformation; - import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting; /** @@ -176,7 +176,13 @@ public class RegionServerRpcQuotaManager { private OperationQuota checkQuota(final Region region, final int numWrites, final int numReads, final int numScans) throws IOException, ThrottlingException { - UserGroupInformation ugi = RpcServer.getRequestUser().orElse(User.getCurrent()).getUGI(); + Optional user = RpcServer.getRequestUser(); + UserGroupInformation ugi; + if (user.isPresent()) { + ugi = user.get().getUGI(); + } else { + ugi = User.getCurrent().getUGI(); + } TableName table = region.getTableDescriptor().getTableName(); OperationQuota quota = getQuota(ugi, table); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java index b9219373804..f2b75417cd1 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java @@ -429,7 +429,12 @@ public class AccessController implements MasterCoprocessor, RegionCoprocessor, */ private User getActiveUser(ObserverContext ctx) throws IOException { // for non-rpc handling, fallback to system user - return ctx.getCaller().orElse(userProvider.getCurrent()); + Optional optionalUser = ctx.getCaller(); + User user; + if (optionalUser.isPresent()) { + return optionalUser.get(); + } + return userProvider.getCurrent(); } /** diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityUtils.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityUtils.java index 7d141e75061..3db8d0ebf14 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityUtils.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityUtils.java @@ -31,6 +31,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Optional; import java.util.Set; import org.apache.commons.lang3.StringUtils; @@ -282,7 +283,13 @@ public class VisibilityUtils { * @throws IOException When there is IOE in getting the system user (During non-RPC handling). */ public static User getActiveUser() throws IOException { - User user = RpcServer.getRequestUser().orElse(User.getCurrent()); + Optional optionalUser = RpcServer.getRequestUser(); + User user; + if (optionalUser.isPresent()) { + user = optionalUser.get(); + } else { + user = User.getCurrent(); + } if (LOG.isTraceEnabled()) { LOG.trace("Current active user name is " + user.getShortName()); }