From e8f7f4660990a668150bfdcb8a18595442fcf3ad Mon Sep 17 00:00:00 2001 From: Zhihong Yu Date: Tue, 1 Apr 2014 16:09:35 +0000 Subject: [PATCH] HBASE-10879 user_permission shell command on namespace doesn't work git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1583725 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/protobuf/ProtobufUtil.java | 28 +++++++++++++++++++ hbase-shell/src/main/ruby/hbase/security.rb | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java index 97d3d27fff4..b45c109412b 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java @@ -2178,6 +2178,34 @@ public final class ProtobufUtil { return perms; } + /** + * A utility used to get permissions for selected namespace. + *

+ * It's also called by the shell, in case you want to find references. + * + * @param protocol the AccessControlService protocol proxy + * @param namespace name of the namespace + * @throws ServiceException + */ + public static List getUserPermissions( + AccessControlService.BlockingInterface protocol, + byte[] namespace) throws ServiceException { + AccessControlProtos.GetUserPermissionsRequest.Builder builder = + AccessControlProtos.GetUserPermissionsRequest.newBuilder(); + if (namespace != null) { + builder.setNamespaceName(HBaseZeroCopyByteString.wrap(namespace)); + } + builder.setType(AccessControlProtos.Permission.Type.Namespace); + AccessControlProtos.GetUserPermissionsRequest request = builder.build(); + AccessControlProtos.GetUserPermissionsResponse response = + protocol.getUserPermissions(null, request); + List perms = new ArrayList(); + for (AccessControlProtos.UserPermission perm: response.getUserPermissionList()) { + perms.add(ProtobufUtil.toUserPermission(perm)); + } + return perms; + } + /** * Convert a protobuf UserTablePermissions to a * ListMultimap where key is username. diff --git a/hbase-shell/src/main/ruby/hbase/security.rb b/hbase-shell/src/main/ruby/hbase/security.rb index fa9c3198a70..322fc987de4 100644 --- a/hbase-shell/src/main/ruby/hbase/security.rb +++ b/hbase-shell/src/main/ruby/hbase/security.rb @@ -168,7 +168,7 @@ module Hbase raise(ArgumentError, "Can't find a namespace: #{namespace_name}") unless namespace_exists?(namespace_name) # invoke cp endpoint to perform access controls perms = org.apache.hadoop.hbase.protobuf.ProtobufUtil.getUserPermissions( - protocol, table_name.to_java_bytes) + protocol, namespace_name.to_java_bytes) else raise(ArgumentError, "Can't find table: #{table_name}") unless exists?(table_name) perms = org.apache.hadoop.hbase.protobuf.ProtobufUtil.getUserPermissions(