001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.security.access; 019 020import java.util.Objects; 021import org.apache.hadoop.hbase.TableName; 022import org.apache.yetus.audience.InterfaceAudience; 023 024/** 025 * Used by 026 * {@link org.apache.hadoop.hbase.client.Admin#getUserPermissions(GetUserPermissionsRequest)}. 027 * Represents the params of user permissions needed to get from HBase. 028 */ 029@InterfaceAudience.Public 030public final class GetUserPermissionsRequest { 031 private String userName; 032 private String namespace; 033 private TableName tableName; 034 private byte[] family; 035 private byte[] qualifier; 036 037 private GetUserPermissionsRequest(String userName, String namespace, TableName tableName, 038 byte[] family, byte[] qualifier) { 039 this.userName = userName; 040 this.namespace = namespace; 041 this.tableName = tableName; 042 this.family = family; 043 this.qualifier = qualifier; 044 } 045 046 /** 047 * Build a get global permission request 048 * @return a get global permission request builder 049 */ 050 public static Builder newBuilder() { 051 return new Builder(); 052 } 053 054 /** 055 * Build a get namespace permission request 056 * @param namespace the specific namespace 057 * @return a get namespace permission request builder 058 */ 059 public static Builder newBuilder(String namespace) { 060 return new Builder(namespace); 061 } 062 063 /** 064 * Build a get table permission request 065 * @param tableName the specific table name 066 * @return a get table permission request builder 067 */ 068 public static Builder newBuilder(TableName tableName) { 069 return new Builder(tableName); 070 } 071 072 public String getUserName() { 073 return userName; 074 } 075 076 public String getNamespace() { 077 return namespace; 078 } 079 080 public TableName getTableName() { 081 return tableName; 082 } 083 084 public byte[] getFamily() { 085 return family; 086 } 087 088 public byte[] getQualifier() { 089 return qualifier; 090 } 091 092 public static final class Builder { 093 private String userName; 094 private String namespace; 095 private TableName tableName; 096 private byte[] family; 097 private byte[] qualifier; 098 099 private Builder() { 100 } 101 102 private Builder(String namespace) { 103 this.namespace = namespace; 104 } 105 106 private Builder(TableName tableName) { 107 this.tableName = tableName; 108 } 109 110 /** 111 * user name could be null if need all global/namespace/table permissions 112 */ 113 public Builder withUserName(String userName) { 114 this.userName = userName; 115 return this; 116 } 117 118 public Builder withFamily(byte[] family) { 119 Objects.requireNonNull(tableName, "The tableName can't be NULL"); 120 this.family = family; 121 return this; 122 } 123 124 public Builder withQualifier(byte[] qualifier) { 125 Objects.requireNonNull(tableName, "The tableName can't be NULL"); 126 // Objects.requireNonNull(family, "The family can't be NULL"); 127 this.qualifier = qualifier; 128 return this; 129 } 130 131 public GetUserPermissionsRequest build() { 132 return new GetUserPermissionsRequest(userName, namespace, tableName, family, qualifier); 133 } 134 } 135}