/** * A utility used to get user's global permissions based on the specified user name. * @param controller RpcController * @param protocol the AccessControlService protocol proxy * @param userName User name, if empty then all user permissions will be retrieved. * @throws ServiceException */ public static List<UserPermission> getUserPermissions(RpcController controller, AccessControlService.BlockingInterface protocol, String userName) throws ServiceException { AccessControlProtos.GetUserPermissionsRequest.Builder builder = AccessControlProtos.GetUserPermissionsRequest.newBuilder(); builder.setType(AccessControlProtos.Permission.Type.Global); if (!StringUtils.isEmpty(userName)) { builder.setUserName(ByteString.copyFromUtf8(userName)); } AccessControlProtos.GetUserPermissionsRequest request = builder.build(); AccessControlProtos.GetUserPermissionsResponse response = protocol.getUserPermissions(controller, request); List<UserPermission> perms = new ArrayList<>(response.getUserPermissionCount()); for (AccessControlProtos.UserPermission perm : response.getUserPermissionList()) { perms.add(toUserPermission(perm)); } return perms; }
/** * A utility used to get permissions for selected namespace based on the specified user name. * @param controller RpcController * @param protocol the AccessControlService protocol proxy * @param namespace name of the namespace * @param userName User name, if empty then all user permissions will be retrieved. * @throws ServiceException */ public static List<UserPermission> getUserPermissions(RpcController controller, AccessControlService.BlockingInterface protocol, byte[] namespace, String userName) throws ServiceException { AccessControlProtos.GetUserPermissionsRequest.Builder builder = AccessControlProtos.GetUserPermissionsRequest.newBuilder(); if (namespace != null) { builder.setNamespaceName(ByteStringer.wrap(namespace)); } if (!StringUtils.isEmpty(userName)) { builder.setUserName(ByteString.copyFromUtf8(userName)); } builder.setType(AccessControlProtos.Permission.Type.Namespace); AccessControlProtos.GetUserPermissionsRequest request = builder.build(); AccessControlProtos.GetUserPermissionsResponse response = protocol.getUserPermissions(controller, request); List<UserPermission> perms = new ArrayList<>(response.getUserPermissionCount()); for (AccessControlProtos.UserPermission perm : response.getUserPermissionList()) { perms.add(toUserPermission(perm)); } return perms; }
builder.setUserName(ByteString.copyFromUtf8(userName));
public Builder mergeFrom(org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.GetUserPermissionsRequest other) { if (other == org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.GetUserPermissionsRequest.getDefaultInstance()) return this; if (other.hasType()) { setType(other.getType()); } if (other.hasTableName()) { mergeTableName(other.getTableName()); } if (other.hasNamespaceName()) { setNamespaceName(other.getNamespaceName()); } if (other.hasColumnFamily()) { setColumnFamily(other.getColumnFamily()); } if (other.hasColumnQualifier()) { setColumnQualifier(other.getColumnQualifier()); } if (other.hasUserName()) { setUserName(other.getUserName()); } this.mergeUnknownFields(other.getUnknownFields()); return this; }