diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityClient.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityClient.java index 2818c24b5b8..fef7d14d567 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityClient.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityClient.java @@ -21,6 +21,7 @@ import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LA import java.io.IOException; import java.util.Map; +import java.util.regex.Pattern; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HConstants; @@ -34,6 +35,8 @@ import org.apache.hadoop.hbase.ipc.BlockingRpcCallback; import org.apache.hadoop.hbase.ipc.ServerRpcController; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsRequest; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsResponse; +import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest; +import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.SetAuthsRequest; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabel; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsRequest; @@ -161,6 +164,57 @@ public class VisibilityClient { } } + /** + * Retrieve the list of visibility labels defined in the system. + * @param conf + * @param regex The regular expression to filter which labels are returned. + * @return labels The list of visibility labels defined in the system. + * @throws Throwable + */ + public static ListLabelsResponse listLabels(Configuration conf, final String regex) + throws Throwable { + Connection connection = null; + Table table = null; + try { + connection = ConnectionFactory.createConnection(conf); + table = connection.getTable(LABELS_TABLE_NAME); + Batch.Call callable = + new Batch.Call() { + ServerRpcController controller = new ServerRpcController(); + BlockingRpcCallback rpcCallback = + new BlockingRpcCallback(); + + public ListLabelsResponse call(VisibilityLabelsService service) throws IOException { + ListLabelsRequest.Builder listAuthLabelsReqBuilder = ListLabelsRequest.newBuilder(); + if (regex != null) { + // Compile the regex here to catch any regex exception earlier. + Pattern pattern = Pattern.compile(regex); + listAuthLabelsReqBuilder.setRegex(pattern.toString()); + } + service.listLabels(controller, listAuthLabelsReqBuilder.build(), rpcCallback); + ListLabelsResponse response = rpcCallback.get(); + if (controller.failedOnException()) { + throw controller.getFailedOn(); + } + return response; + } + }; + Map result = + table.coprocessorService(VisibilityLabelsService.class, HConstants.EMPTY_BYTE_ARRAY, + HConstants.EMPTY_BYTE_ARRAY, callable); + return result.values().iterator().next(); // There will be exactly one region for labels + // table and so one entry in result Map. + } + finally { + if (table != null) { + table.close(); + } + if (connection != null) { + connection.close(); + } + } + } + /** * Removes given labels from user's globally authorized list of labels. * @param conf diff --git a/hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/VisibilityLabelsProtos.java b/hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/VisibilityLabelsProtos.java index 38f83a11228..294772e9284 100644 --- a/hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/VisibilityLabelsProtos.java +++ b/hbase-protocol/src/main/java/org/apache/hadoop/hbase/protobuf/generated/VisibilityLabelsProtos.java @@ -4961,6 +4961,1012 @@ public final class VisibilityLabelsProtos { // @@protoc_insertion_point(class_scope:GetAuthsResponse) } + public interface ListLabelsRequestOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // optional string regex = 1; + /** + * optional string regex = 1; + */ + boolean hasRegex(); + /** + * optional string regex = 1; + */ + java.lang.String getRegex(); + /** + * optional string regex = 1; + */ + com.google.protobuf.ByteString + getRegexBytes(); + } + /** + * Protobuf type {@code ListLabelsRequest} + */ + public static final class ListLabelsRequest extends + com.google.protobuf.GeneratedMessage + implements ListLabelsRequestOrBuilder { + // Use ListLabelsRequest.newBuilder() to construct. + private ListLabelsRequest(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + this.unknownFields = builder.getUnknownFields(); + } + private ListLabelsRequest(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + + private static final ListLabelsRequest defaultInstance; + public static ListLabelsRequest getDefaultInstance() { + return defaultInstance; + } + + public ListLabelsRequest getDefaultInstanceForType() { + return defaultInstance; + } + + private final com.google.protobuf.UnknownFieldSet unknownFields; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private ListLabelsRequest( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + initFields(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + bitField0_ |= 0x00000001; + regex_ = input.readBytes(); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.internal_static_ListLabelsRequest_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.internal_static_ListLabelsRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest.class, org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest.Builder.class); + } + + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public ListLabelsRequest parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new ListLabelsRequest(input, extensionRegistry); + } + }; + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + private int bitField0_; + // optional string regex = 1; + public static final int REGEX_FIELD_NUMBER = 1; + private java.lang.Object regex_; + /** + * optional string regex = 1; + */ + public boolean hasRegex() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional string regex = 1; + */ + public java.lang.String getRegex() { + java.lang.Object ref = regex_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + regex_ = s; + } + return s; + } + } + /** + * optional string regex = 1; + */ + public com.google.protobuf.ByteString + getRegexBytes() { + java.lang.Object ref = regex_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + regex_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private void initFields() { + regex_ = ""; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeBytes(1, getRegexBytes()); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(1, getRegexBytes()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest)) { + return super.equals(obj); + } + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest other = (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest) obj; + + boolean result = true; + result = result && (hasRegex() == other.hasRegex()); + if (hasRegex()) { + result = result && getRegex() + .equals(other.getRegex()); + } + result = result && + getUnknownFields().equals(other.getUnknownFields()); + return result; + } + + private int memoizedHashCode = 0; + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptorForType().hashCode(); + if (hasRegex()) { + hash = (37 * hash) + REGEX_FIELD_NUMBER; + hash = (53 * hash) + getRegex().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code ListLabelsRequest} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequestOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.internal_static_ListLabelsRequest_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.internal_static_ListLabelsRequest_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest.class, org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest.Builder.class); + } + + // Construct using org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + regex_ = ""; + bitField0_ = (bitField0_ & ~0x00000001); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.internal_static_ListLabelsRequest_descriptor; + } + + public org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest getDefaultInstanceForType() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest.getDefaultInstance(); + } + + public org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest build() { + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest buildPartial() { + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest result = new org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.regex_ = regex_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest) { + return mergeFrom((org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest other) { + if (other == org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest.getDefaultInstance()) return this; + if (other.hasRegex()) { + bitField0_ |= 0x00000001; + regex_ = other.regex_; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + // optional string regex = 1; + private java.lang.Object regex_ = ""; + /** + * optional string regex = 1; + */ + public boolean hasRegex() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional string regex = 1; + */ + public java.lang.String getRegex() { + java.lang.Object ref = regex_; + if (!(ref instanceof java.lang.String)) { + java.lang.String s = ((com.google.protobuf.ByteString) ref) + .toStringUtf8(); + regex_ = s; + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string regex = 1; + */ + public com.google.protobuf.ByteString + getRegexBytes() { + java.lang.Object ref = regex_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + regex_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string regex = 1; + */ + public Builder setRegex( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + regex_ = value; + onChanged(); + return this; + } + /** + * optional string regex = 1; + */ + public Builder clearRegex() { + bitField0_ = (bitField0_ & ~0x00000001); + regex_ = getDefaultInstance().getRegex(); + onChanged(); + return this; + } + /** + * optional string regex = 1; + */ + public Builder setRegexBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + regex_ = value; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:ListLabelsRequest) + } + + static { + defaultInstance = new ListLabelsRequest(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:ListLabelsRequest) + } + + public interface ListLabelsResponseOrBuilder + extends com.google.protobuf.MessageOrBuilder { + + // repeated bytes label = 1; + /** + * repeated bytes label = 1; + */ + java.util.List getLabelList(); + /** + * repeated bytes label = 1; + */ + int getLabelCount(); + /** + * repeated bytes label = 1; + */ + com.google.protobuf.ByteString getLabel(int index); + } + /** + * Protobuf type {@code ListLabelsResponse} + */ + public static final class ListLabelsResponse extends + com.google.protobuf.GeneratedMessage + implements ListLabelsResponseOrBuilder { + // Use ListLabelsResponse.newBuilder() to construct. + private ListLabelsResponse(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + this.unknownFields = builder.getUnknownFields(); + } + private ListLabelsResponse(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + + private static final ListLabelsResponse defaultInstance; + public static ListLabelsResponse getDefaultInstance() { + return defaultInstance; + } + + public ListLabelsResponse getDefaultInstanceForType() { + return defaultInstance; + } + + private final com.google.protobuf.UnknownFieldSet unknownFields; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private ListLabelsResponse( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + initFields(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + if (!((mutable_bitField0_ & 0x00000001) == 0x00000001)) { + label_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000001; + } + label_.add(input.readBytes()); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this); + } finally { + if (((mutable_bitField0_ & 0x00000001) == 0x00000001)) { + label_ = java.util.Collections.unmodifiableList(label_); + } + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.internal_static_ListLabelsResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.internal_static_ListLabelsResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.class, org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.Builder.class); + } + + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public ListLabelsResponse parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new ListLabelsResponse(input, extensionRegistry); + } + }; + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + // repeated bytes label = 1; + public static final int LABEL_FIELD_NUMBER = 1; + private java.util.List label_; + /** + * repeated bytes label = 1; + */ + public java.util.List + getLabelList() { + return label_; + } + /** + * repeated bytes label = 1; + */ + public int getLabelCount() { + return label_.size(); + } + /** + * repeated bytes label = 1; + */ + public com.google.protobuf.ByteString getLabel(int index) { + return label_.get(index); + } + + private void initFields() { + label_ = java.util.Collections.emptyList(); + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized != -1) return isInitialized == 1; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + for (int i = 0; i < label_.size(); i++) { + output.writeBytes(1, label_.get(i)); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + { + int dataSize = 0; + for (int i = 0; i < label_.size(); i++) { + dataSize += com.google.protobuf.CodedOutputStream + .computeBytesSizeNoTag(label_.get(i)); + } + size += dataSize; + size += 1 * getLabelList().size(); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + @java.lang.Override + public boolean equals(final java.lang.Object obj) { + if (obj == this) { + return true; + } + if (!(obj instanceof org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse)) { + return super.equals(obj); + } + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse other = (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse) obj; + + boolean result = true; + result = result && getLabelList() + .equals(other.getLabelList()); + result = result && + getUnknownFields().equals(other.getUnknownFields()); + return result; + } + + private int memoizedHashCode = 0; + @java.lang.Override + public int hashCode() { + if (memoizedHashCode != 0) { + return memoizedHashCode; + } + int hash = 41; + hash = (19 * hash) + getDescriptorForType().hashCode(); + if (getLabelCount() > 0) { + hash = (37 * hash) + LABEL_FIELD_NUMBER; + hash = (53 * hash) + getLabelList().hashCode(); + } + hash = (29 * hash) + getUnknownFields().hashCode(); + memoizedHashCode = hash; + return hash; + } + + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code ListLabelsResponse} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder + implements org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponseOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.internal_static_ListLabelsResponse_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.internal_static_ListLabelsResponse_fieldAccessorTable + .ensureFieldAccessorsInitialized( + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.class, org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.Builder.class); + } + + // Construct using org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + label_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.internal_static_ListLabelsResponse_descriptor; + } + + public org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse getDefaultInstanceForType() { + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.getDefaultInstance(); + } + + public org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse build() { + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse buildPartial() { + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse result = new org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse(this); + int from_bitField0_ = bitField0_; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + label_ = java.util.Collections.unmodifiableList(label_); + bitField0_ = (bitField0_ & ~0x00000001); + } + result.label_ = label_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse) { + return mergeFrom((org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse other) { + if (other == org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.getDefaultInstance()) return this; + if (!other.label_.isEmpty()) { + if (label_.isEmpty()) { + label_ = other.label_; + bitField0_ = (bitField0_ & ~0x00000001); + } else { + ensureLabelIsMutable(); + label_.addAll(other.label_); + } + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + // repeated bytes label = 1; + private java.util.List label_ = java.util.Collections.emptyList(); + private void ensureLabelIsMutable() { + if (!((bitField0_ & 0x00000001) == 0x00000001)) { + label_ = new java.util.ArrayList(label_); + bitField0_ |= 0x00000001; + } + } + /** + * repeated bytes label = 1; + */ + public java.util.List + getLabelList() { + return java.util.Collections.unmodifiableList(label_); + } + /** + * repeated bytes label = 1; + */ + public int getLabelCount() { + return label_.size(); + } + /** + * repeated bytes label = 1; + */ + public com.google.protobuf.ByteString getLabel(int index) { + return label_.get(index); + } + /** + * repeated bytes label = 1; + */ + public Builder setLabel( + int index, com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + ensureLabelIsMutable(); + label_.set(index, value); + onChanged(); + return this; + } + /** + * repeated bytes label = 1; + */ + public Builder addLabel(com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + ensureLabelIsMutable(); + label_.add(value); + onChanged(); + return this; + } + /** + * repeated bytes label = 1; + */ + public Builder addAllLabel( + java.lang.Iterable values) { + ensureLabelIsMutable(); + super.addAll(values, label_); + onChanged(); + return this; + } + /** + * repeated bytes label = 1; + */ + public Builder clearLabel() { + label_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000001); + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:ListLabelsResponse) + } + + static { + defaultInstance = new ListLabelsResponse(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:ListLabelsResponse) + } + /** * Protobuf service {@code VisibilityLabelsService} */ @@ -5001,6 +6007,14 @@ public final class VisibilityLabelsProtos { org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsRequest request, com.google.protobuf.RpcCallback done); + /** + * rpc listLabels(.ListLabelsRequest) returns (.ListLabelsResponse); + */ + public abstract void listLabels( + com.google.protobuf.RpcController controller, + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest request, + com.google.protobuf.RpcCallback done); + } public static com.google.protobuf.Service newReflectiveService( @@ -5038,6 +6052,14 @@ public final class VisibilityLabelsProtos { impl.getAuths(controller, request, done); } + @java.lang.Override + public void listLabels( + com.google.protobuf.RpcController controller, + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest request, + com.google.protobuf.RpcCallback done) { + impl.listLabels(controller, request, done); + } + }; } @@ -5068,6 +6090,8 @@ public final class VisibilityLabelsProtos { return impl.clearAuths(controller, (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.SetAuthsRequest)request); case 3: return impl.getAuths(controller, (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsRequest)request); + case 4: + return impl.listLabels(controller, (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest)request); default: throw new java.lang.AssertionError("Can't get here."); } @@ -5090,6 +6114,8 @@ public final class VisibilityLabelsProtos { return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.SetAuthsRequest.getDefaultInstance(); case 3: return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsRequest.getDefaultInstance(); + case 4: + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest.getDefaultInstance(); default: throw new java.lang.AssertionError("Can't get here."); } @@ -5112,6 +6138,8 @@ public final class VisibilityLabelsProtos { return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse.getDefaultInstance(); case 3: return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsResponse.getDefaultInstance(); + case 4: + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.getDefaultInstance(); default: throw new java.lang.AssertionError("Can't get here."); } @@ -5152,6 +6180,14 @@ public final class VisibilityLabelsProtos { org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsRequest request, com.google.protobuf.RpcCallback done); + /** + * rpc listLabels(.ListLabelsRequest) returns (.ListLabelsResponse); + */ + public abstract void listLabels( + com.google.protobuf.RpcController controller, + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest request, + com.google.protobuf.RpcCallback done); + public static final com.google.protobuf.Descriptors.ServiceDescriptor getDescriptor() { @@ -5194,6 +6230,11 @@ public final class VisibilityLabelsProtos { com.google.protobuf.RpcUtil.specializeCallback( done)); return; + case 4: + this.listLabels(controller, (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest)request, + com.google.protobuf.RpcUtil.specializeCallback( + done)); + return; default: throw new java.lang.AssertionError("Can't get here."); } @@ -5216,6 +6257,8 @@ public final class VisibilityLabelsProtos { return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.SetAuthsRequest.getDefaultInstance(); case 3: return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsRequest.getDefaultInstance(); + case 4: + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest.getDefaultInstance(); default: throw new java.lang.AssertionError("Can't get here."); } @@ -5238,6 +6281,8 @@ public final class VisibilityLabelsProtos { return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse.getDefaultInstance(); case 3: return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsResponse.getDefaultInstance(); + case 4: + return org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.getDefaultInstance(); default: throw new java.lang.AssertionError("Can't get here."); } @@ -5318,6 +6363,21 @@ public final class VisibilityLabelsProtos { org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsResponse.class, org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsResponse.getDefaultInstance())); } + + public void listLabels( + com.google.protobuf.RpcController controller, + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest request, + com.google.protobuf.RpcCallback done) { + channel.callMethod( + getDescriptor().getMethods().get(4), + controller, + request, + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.getDefaultInstance(), + com.google.protobuf.RpcUtil.generalizeCallback( + done, + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.class, + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.getDefaultInstance())); + } } public static BlockingInterface newBlockingStub( @@ -5345,6 +6405,11 @@ public final class VisibilityLabelsProtos { com.google.protobuf.RpcController controller, org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsRequest request) throws com.google.protobuf.ServiceException; + + public org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse listLabels( + com.google.protobuf.RpcController controller, + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest request) + throws com.google.protobuf.ServiceException; } private static final class BlockingStub implements BlockingInterface { @@ -5401,6 +6466,18 @@ public final class VisibilityLabelsProtos { org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsResponse.getDefaultInstance()); } + + public org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse listLabels( + com.google.protobuf.RpcController controller, + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest request) + throws com.google.protobuf.ServiceException { + return (org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse) channel.callBlockingMethod( + getDescriptor().getMethods().get(4), + controller, + request, + org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse.getDefaultInstance()); + } + } // @@protoc_insertion_point(class_scope:VisibilityLabelsService) @@ -5446,6 +6523,16 @@ public final class VisibilityLabelsProtos { private static com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_GetAuthsResponse_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_ListLabelsRequest_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_ListLabelsRequest_fieldAccessorTable; + private static com.google.protobuf.Descriptors.Descriptor + internal_static_ListLabelsResponse_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_ListLabelsResponse_fieldAccessorTable; public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() { @@ -5466,15 +6553,19 @@ public final class VisibilityLabelsProtos { "ltiUserAuthorizations\022&\n\tuserAuths\030\001 \003(\013" + "2\023.UserAuthorizations\"\037\n\017GetAuthsRequest", "\022\014\n\004user\030\001 \002(\014\".\n\020GetAuthsResponse\022\014\n\004us" + - "er\030\001 \002(\014\022\014\n\004auth\030\002 \003(\0142\200\002\n\027VisibilityLab" + - "elsService\022@\n\taddLabels\022\030.VisibilityLabe" + - "lsRequest\032\031.VisibilityLabelsResponse\0227\n\010" + - "setAuths\022\020.SetAuthsRequest\032\031.VisibilityL" + - "abelsResponse\0229\n\nclearAuths\022\020.SetAuthsRe" + - "quest\032\031.VisibilityLabelsResponse\022/\n\010getA" + - "uths\022\020.GetAuthsRequest\032\021.GetAuthsRespons" + - "eBL\n*org.apache.hadoop.hbase.protobuf.ge" + - "neratedB\026VisibilityLabelsProtosH\001\210\001\001\240\001\001" + "er\030\001 \002(\014\022\014\n\004auth\030\002 \003(\014\"\"\n\021ListLabelsRequ" + + "est\022\r\n\005regex\030\001 \001(\t\"#\n\022ListLabelsResponse" + + "\022\r\n\005label\030\001 \003(\0142\267\002\n\027VisibilityLabelsServ" + + "ice\022@\n\taddLabels\022\030.VisibilityLabelsReque" + + "st\032\031.VisibilityLabelsResponse\0227\n\010setAuth" + + "s\022\020.SetAuthsRequest\032\031.VisibilityLabelsRe" + + "sponse\0229\n\nclearAuths\022\020.SetAuthsRequest\032\031" + + ".VisibilityLabelsResponse\022/\n\010getAuths\022\020." + + "GetAuthsRequest\032\021.GetAuthsResponse\0225\n\nli", + "stLabels\022\022.ListLabelsRequest\032\023.ListLabel" + + "sResponseBL\n*org.apache.hadoop.hbase.pro" + + "tobuf.generatedB\026VisibilityLabelsProtosH" + + "\001\210\001\001\240\001\001" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { @@ -5529,6 +6620,18 @@ public final class VisibilityLabelsProtos { com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_GetAuthsResponse_descriptor, new java.lang.String[] { "User", "Auth", }); + internal_static_ListLabelsRequest_descriptor = + getDescriptor().getMessageTypes().get(8); + internal_static_ListLabelsRequest_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_ListLabelsRequest_descriptor, + new java.lang.String[] { "Regex", }); + internal_static_ListLabelsResponse_descriptor = + getDescriptor().getMessageTypes().get(9); + internal_static_ListLabelsResponse_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_ListLabelsResponse_descriptor, + new java.lang.String[] { "Label", }); return null; } }; diff --git a/hbase-protocol/src/main/protobuf/VisibilityLabels.proto b/hbase-protocol/src/main/protobuf/VisibilityLabels.proto index f62dfa7524e..febc0136df0 100644 --- a/hbase-protocol/src/main/protobuf/VisibilityLabels.proto +++ b/hbase-protocol/src/main/protobuf/VisibilityLabels.proto @@ -60,6 +60,14 @@ message GetAuthsResponse { repeated bytes auth = 2; } +message ListLabelsRequest { + optional string regex = 1; +} + +message ListLabelsResponse { + repeated bytes label = 1; +} + service VisibilityLabelsService { rpc addLabels(VisibilityLabelsRequest) returns (VisibilityLabelsResponse); @@ -69,4 +77,6 @@ service VisibilityLabelsService { returns (VisibilityLabelsResponse); rpc getAuths(GetAuthsRequest) returns (GetAuthsResponse); + rpc listLabels(ListLabelsRequest) + returns (ListLabelsResponse); } \ No newline at end of file diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/DefaultVisibilityLabelServiceImpl.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/DefaultVisibilityLabelServiceImpl.java index 4de83b5a3e4..2747d512046 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/DefaultVisibilityLabelServiceImpl.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/DefaultVisibilityLabelServiceImpl.java @@ -36,6 +36,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; +import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -371,6 +372,26 @@ public class DefaultVisibilityLabelServiceImpl implements VisibilityLabelService return auths; } + @Override + public List listLabels(String regex) throws IOException { + assert (labelsRegion != null); + Pair, Map>> labelsAndUserAuths = + extractLabelsAndAuths(getExistingLabelsWithAuths()); + Map labels = labelsAndUserAuths.getFirst(); + labels.remove(SYSTEM_LABEL); + if (regex != null) { + Pattern pattern = Pattern.compile(regex); + ArrayList matchedLabels = new ArrayList(); + for (String label : labels.keySet()) { + if (pattern.matcher(label).matches()) { + matchedLabels.add(label); + } + } + return matchedLabels; + } + return new ArrayList(labels.keySet()); + } + @Override public List createVisibilityExpTags(String visExpression, boolean withSerializationFormat, boolean checkAuths) throws IOException { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java index eaea40ce202..82ea9ef24af 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityController.java @@ -78,6 +78,8 @@ import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionActionResul import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsRequest; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.GetAuthsResponse; +import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsRequest; +import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.SetAuthsRequest; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabel; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsRequest; @@ -881,6 +883,37 @@ public class VisibilityController extends BaseMasterAndRegionObserver implements done.run(response.build()); } + @Override + public synchronized void listLabels(RpcController controller, ListLabelsRequest request, + RpcCallback done) { + ListLabelsResponse.Builder response = ListLabelsResponse.newBuilder(); + if (!initialized) { + controller.setFailed("VisibilityController not yet initialized"); + } else { + List labels = null; + try { + // We do ACL check here as we create scanner directly on region. It will not make calls to + // AccessController CP methods. + if (this.acOn && !isSystemOrSuperUser()) { + User requestingUser = VisibilityUtils.getActiveUser(); + throw new AccessDeniedException("User '" + + (requestingUser != null ? requestingUser.getShortName() : "null") + + "' is not authorized to perform this action."); + } + String regex = request.hasRegex() ? request.getRegex() : null; + labels = this.visibilityLabelService.listLabels(regex); + } catch (IOException e) { + ResponseConverter.setControllerException(controller, e); + } + if (labels != null && !labels.isEmpty()) { + for (String label : labels) { + response.addLabel(ByteStringer.wrap(Bytes.toBytes(label))); + } + } + } + done.run(response.build()); + } + private void checkCallingUserAuth() throws IOException { if (!this.acOn) { User user = VisibilityUtils.getActiveUser(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelService.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelService.java index cc317d18a60..1f74a9a32d0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelService.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/visibility/VisibilityLabelService.java @@ -81,6 +81,13 @@ public interface VisibilityLabelService extends Configurable { */ List getAuths(byte[] user, boolean systemCall) throws IOException; + /** + * Retrieve the list of visibility labels defined in the system. + * @param regex The regular expression to filter which labels are returned. + * @return List of visibility labels + */ + List listLabels(String regex) throws IOException; + /** * Creates tags corresponding to given visibility expression. *
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/ExpAsStringVisibilityLabelServiceImpl.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/ExpAsStringVisibilityLabelServiceImpl.java index 285757a16c7..ae61dfd7c5e 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/ExpAsStringVisibilityLabelServiceImpl.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/ExpAsStringVisibilityLabelServiceImpl.java @@ -167,6 +167,12 @@ public class ExpAsStringVisibilityLabelServiceImpl implements VisibilityLabelSer return auths; } + @Override + public List listLabels(String regex) throws IOException { + // return an empty list for this implementation. + return new ArrayList(); + } + @Override public List createVisibilityExpTags(String visExpression, boolean withSerializationFormat, boolean checkAuths) throws IOException { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDefaultVisLabelService.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDefaultVisLabelService.java index cb5fff1b53c..dcfed5ffce5 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDefaultVisLabelService.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsWithDefaultVisLabelService.java @@ -18,8 +18,10 @@ package org.apache.hadoop.hbase.security.visibility; import static org.apache.hadoop.hbase.security.visibility.VisibilityConstants.LABELS_TABLE_NAME; +import static org.apache.hadoop.hbase.security.visibility.VisibilityUtils.SYSTEM_LABEL; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; import java.io.IOException; @@ -38,6 +40,7 @@ import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.RegionActionResult; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameBytesPair; +import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.ListLabelsResponse; import org.apache.hadoop.hbase.protobuf.generated.VisibilityLabelsProtos.VisibilityLabelsResponse; import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.testclassification.MediumTests; @@ -50,6 +53,8 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import com.google.protobuf.ByteString; + @Category({SecurityTests.class, MediumTests.class}) public class TestVisibilityLabelsWithDefaultVisLabelService extends TestVisibilityLabels { final Log LOG = LogFactory.getLog(getClass()); @@ -164,4 +169,56 @@ public class TestVisibilityLabelsWithDefaultVisLabelService extends TestVisibili // One label is the "system" label. Assert.assertEquals("The count should be 13", 13, i); } + + @Test + public void testListLabels() throws Throwable { + PrivilegedExceptionAction action = + new PrivilegedExceptionAction() { + public ListLabelsResponse run() throws Exception { + ListLabelsResponse response = null; + try { + response = VisibilityClient.listLabels(conf, null); + } catch (Throwable e) { + fail("Should not have thrown exception"); + } + // The addLabels() in setup added: + // { SECRET, TOPSECRET, CONFIDENTIAL, PUBLIC, PRIVATE, COPYRIGHT, ACCENT, + // UNICODE_VIS_TAG, UC1, UC2 }; + // The previous tests added 2 more labels: ABC, XYZ + // The 'system' label is excluded. + List labels = response.getLabelList(); + assertEquals(12, labels.size()); + assertTrue(labels.contains(ByteString.copyFrom(SECRET.getBytes()))); + assertTrue(labels.contains(ByteString.copyFrom(TOPSECRET.getBytes()))); + assertTrue(labels.contains(ByteString.copyFrom(CONFIDENTIAL.getBytes()))); + assertTrue(labels.contains(ByteString.copyFrom("ABC".getBytes()))); + assertTrue(labels.contains(ByteString.copyFrom("XYZ".getBytes()))); + assertFalse(labels.contains(ByteString.copyFrom(SYSTEM_LABEL.getBytes()))); + return null; + } + }; + SUPERUSER.runAs(action); + } + + @Test + public void testListLabelsWithRegEx() throws Throwable { + PrivilegedExceptionAction action = + new PrivilegedExceptionAction() { + public ListLabelsResponse run() throws Exception { + ListLabelsResponse response = null; + try { + response = VisibilityClient.listLabels(conf, ".*secret"); + } catch (Throwable e) { + fail("Should not have thrown exception"); + } + // Only return the labels that end with 'secret' + List labels = response.getLabelList(); + assertEquals(2, labels.size()); + assertTrue(labels.contains(ByteString.copyFrom(SECRET.getBytes()))); + assertTrue(labels.contains(ByteString.copyFrom(TOPSECRET.getBytes()))); + return null; + } + }; + SUPERUSER.runAs(action); + } } diff --git a/hbase-shell/src/main/ruby/hbase/visibility_labels.rb b/hbase-shell/src/main/ruby/hbase/visibility_labels.rb index ca33ada0e0b..61a49e81332 100644 --- a/hbase-shell/src/main/ruby/hbase/visibility_labels.rb +++ b/hbase-shell/src/main/ruby/hbase/visibility_labels.rb @@ -100,6 +100,20 @@ module Hbase end end + def list_labels(regex = ".*") + lables_table_available? + begin + response = VisibilityClient.listLabels(@config, regex) + if response.nil? + raise(ArgumentError, "DISABLED: Visibility labels feature is not available") + end + if response.getLabelList.empty? + raise(ArgumentError, "No auth label defined") + end + return response.getLabelList + end + end + def clear_auths(user, *args) lables_table_available? # Normalize args @@ -136,4 +150,4 @@ module Hbase @admin.tableExists(table_name) end end -end \ No newline at end of file +end diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb index 3222bee2f7c..5db2776357d 100644 --- a/hbase-shell/src/main/ruby/shell.rb +++ b/hbase-shell/src/main/ruby/shell.rb @@ -400,6 +400,7 @@ Shell.load_command_group( :comment => "NOTE: Above commands are only applicable if running with the VisibilityController coprocessor", :commands => %w[ add_labels + list_labels set_auths get_auths clear_auths diff --git a/hbase-shell/src/main/ruby/shell/commands/list_labels.rb b/hbase-shell/src/main/ruby/shell/commands/list_labels.rb new file mode 100644 index 00000000000..6c7f99137b7 --- /dev/null +++ b/hbase-shell/src/main/ruby/shell/commands/list_labels.rb @@ -0,0 +1,44 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +module Shell + module Commands + class ListLabels < Command + def help + return <<-EOF +List the visibility labels defined in the system. +Optional regular expression parameter could be used to filter the labels being returned. +Syntax : list_labels + +For example: + + hbase> list_labels 'secret.*' + hbase> list_labels +EOF + end + + def command(regex = ".*") + format_simple_command do + list = visibility_labels_admin.list_labels(regex) + list.each do |label| + formatter.row([org.apache.hadoop.hbase.util.Bytes::toStringBinary(label.toByteArray)]) + end + end + end + end + end +end