Skip to content

Commit

Permalink
HBASE-19678 HBase Admin security capabilities should be represented a…
Browse files Browse the repository at this point in the history
…s a Set - revert due to wrong issue
  • Loading branch information
tedyu committed Jan 1, 2018
1 parent cafd4e4 commit 73ab51e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Expand Up @@ -20,9 +20,8 @@
package org.apache.hadoop.hbase.security; package org.apache.hadoop.hbase.security;


import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.ArrayList;
import java.util.HashSet; import java.util.List;
import java.util.Set;


import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.AuthUtil; import org.apache.hadoop.hbase.AuthUtil;
Expand All @@ -41,8 +40,8 @@ public final class Superusers {
/** Configuration key for superusers */ /** Configuration key for superusers */
public static final String SUPERUSER_CONF_KEY = "hbase.superuser"; // Not getting a name public static final String SUPERUSER_CONF_KEY = "hbase.superuser"; // Not getting a name


private static Set<String> superUsers; private static List<String> superUsers;
private static Set<String> superGroups; private static List<String> superGroups;
private static User systemUser; private static User systemUser;


private Superusers(){} private Superusers(){}
Expand All @@ -55,19 +54,19 @@ private Superusers(){}
* @throws IllegalStateException if current user is null * @throws IllegalStateException if current user is null
*/ */
public static void initialize(Configuration conf) throws IOException { public static void initialize(Configuration conf) throws IOException {
superUsers = new HashSet<>(); superUsers = new ArrayList<>();
superGroups = new HashSet<>(); superGroups = new ArrayList<>();
systemUser = User.getCurrent(); systemUser = User.getCurrent();


if (systemUser == null) { if (systemUser == null) {
throw new IllegalStateException("Unable to obtain the current user, " throw new IllegalStateException("Unable to obtain the current user, "
+ "authorization checks for internal operations will not work correctly!"); + "authorization checks for internal operations will not work correctly!");
} }


if (LOG.isTraceEnabled()) {
LOG.trace("Current user name is " + systemUser.getShortName());
}
String currentUser = systemUser.getShortName(); String currentUser = systemUser.getShortName();
LOG.trace("Current user name is {}", currentUser);
superUsers.add(currentUser);

String[] superUserList = conf.getStrings(SUPERUSER_CONF_KEY, new String[0]); String[] superUserList = conf.getStrings(SUPERUSER_CONF_KEY, new String[0]);
for (String name : superUserList) { for (String name : superUserList) {
if (AuthUtil.isGroupPrincipal(name)) { if (AuthUtil.isGroupPrincipal(name)) {
Expand All @@ -76,6 +75,7 @@ public static void initialize(Configuration conf) throws IOException {
superUsers.add(name); superUsers.add(name);
} }
} }
superUsers.add(currentUser);
} }


/** /**
Expand All @@ -88,11 +88,12 @@ public static void initialize(Configuration conf) throws IOException {
public static boolean isSuperUser(User user) { public static boolean isSuperUser(User user) {
if (superUsers == null) { if (superUsers == null) {
throw new IllegalStateException("Super users/super groups lists" throw new IllegalStateException("Super users/super groups lists"
+ " have not been initialized properly."); + " haven't been initialized properly.");
} }
if (superUsers.contains(user.getShortName())) { if (superUsers.contains(user.getShortName())) {
return true; return true;
} }

for (String group : user.getGroupNames()) { for (String group : user.getGroupNames()) {
if (superGroups.contains(group)) { if (superGroups.contains(group)) {
return true; return true;
Expand All @@ -101,7 +102,7 @@ public static boolean isSuperUser(User user) {
return false; return false;
} }


public static Collection<String> getSuperUsers() { public static List<String> getSuperUsers() {
return superUsers; return superUsers;
} }


Expand Down
Expand Up @@ -34,7 +34,6 @@
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;


Expand Down Expand Up @@ -1678,7 +1677,7 @@ public void testGlobalPermissionList() throws Exception {
acl.close(); acl.close();
} }


Collection<String> superUsers = Superusers.getSuperUsers(); List<String> superUsers = Superusers.getSuperUsers();
List<UserPermission> adminPerms = new ArrayList<>(superUsers.size() + 1); List<UserPermission> adminPerms = new ArrayList<>(superUsers.size() + 1);
adminPerms.add(new UserPermission(Bytes.toBytes(USER_ADMIN.getShortName()), adminPerms.add(new UserPermission(Bytes.toBytes(USER_ADMIN.getShortName()),
AccessControlLists.ACL_TABLE_NAME, null, null, Bytes.toBytes("ACRW"))); AccessControlLists.ACL_TABLE_NAME, null, null, Bytes.toBytes("ACRW")));
Expand Down

0 comments on commit 73ab51e

Please sign in to comment.